Class: Net::SSH::Multiplex::Client

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/net/ssh/multiplex/client.rb

Overview

Connects to an OpenSSH ControlMaster's UNIX socket and switches it to proxy mode (MUX_C_PROXY, OpenSSH 7.4 and later), after which the socket carries plain SSH connection-protocol packets. See PROTOCOL.mux and mux.c in OpenSSH.

Constant Summary collapse

MUX_MSG_HELLO =
0x00000001
MUX_C_PROXY =
0x1000000f
MUX_S_PERMISSION_DENIED =
0x80000002
MUX_S_FAILURE =
0x80000003
MUX_S_PROXY =
0x8000000f
PROTOCOL_VERSION =
4
MAX_MESSAGE_SIZE =

Mux control messages are small; this only guards against reading a bogus length from something that isn't a ControlMaster.

256 * 1024

Instance Attribute Summary collapse

Attributes included from Loggable

#logger

Instance Method Summary collapse

Methods included from Loggable

#debug, #error, #fatal, #info, #lwarn

Constructor Details

#initialize(path, timeout:, logger: nil) ⇒ Client

Returns a new instance of Client.



36
37
38
39
40
# File 'lib/net/ssh/multiplex/client.rb', line 36

def initialize(path, timeout:, logger: nil)
  self.logger = logger
  @path = path
  @timeout = timeout
end

Instance Attribute Details

#path ⇒ Object (readonly)

Returns the value of attribute path.



34
35
36
# File 'lib/net/ssh/multiplex/client.rb', line 34

def path
  @path
end

Instance Method Details

#connect_proxy ⇒ Object

Performs the HELLO and PROXY exchange and returns the connected socket, positioned at the first proxied packet. Raises Multiplex::Error, SystemCallError or IOError if the master can't be used; the socket is closed in that case.



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/net/ssh/multiplex/client.rb', line 46

def connect_proxy
  @deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + @timeout
  @socket = open_socket
  verify_peer
  hello
  request_proxy
  @socket
rescue StandardError
  @socket&.close
  raise
end