Class: Net::SSH::Transport::Session

Class | Net::SSH::Transport::Session
In: | lib/net/ssh/transport/session.rb
Parent: | Object

The transport layer represents the lowest level of the SSH protocol, and implements basic message exchanging and protocol initialization. It will never be instantiated directly (unless you really know what you‘re about), but will instead be created for you automatically when you create a new SSH session via Net::SSH.start.

### Methods

close closed? configure_client configure_server enqueue_message hint host_as_string new next_message peer poll_message push rekey! rekey_as_needed send_message service_request shutdown! wait

### Included Modules

Constants Loggable

### Constants

DEFAULT_PORT | = | 22 |  | The standard port for the SSH protocol.

### Attributes

algorithms | [R] | The Algorithms instance used to perform key exchanges.
host | [R] | The host to connect to, as given to the constructor.
host_key_verifier | [R] | The host-key verifier object used to verify host keys, to ensure that the connection is not being spoofed.
options | [R] | The hash of options that were given to the object at initialization.
port | [R] | The port number to connect to, as given in the options to the constructor. If no port number was given, this will default to DEFAULT_PORT.
server_version | [R] | The ServerVersion instance that encapsulates the negotiated protocol version.
socket | [R] | The underlying socket object being used to communicate with the remote host.

### Public Class methods

new(host, options={})

Instantiates a new transport layer abstraction. This will block until the initial key exchange completes, leaving you with a ready-to-use transport session.

### Public Instance methods

close()

Cleans up (see PacketStream#cleanup) and closes the underlying socket.

closed?()

Returns true if the underlying socket has been closed.

configure_client(options={})

Configure‘s the packet stream‘s client state with the given set of options. This is typically used to define the cipher, compression, and hmac algorithms to use when sending packets to the server.

configure_server(options={})

Configure‘s the packet stream‘s server state with the given set of options. This is typically used to define the cipher, compression, and hmac algorithms to use when reading packets from the server.

enqueue_message(message)

Enqueues the given message, such that it will be sent at the earliest opportunity. This does not block, but returns immediately.

hint(which, value=true)

Sets a new hint for the packet stream, which the packet stream may use to change its behavior. (See PacketStream#hints).

host_as_string()

Returns the host (and possibly IP address) in a format compatible with SSH known-host files.

next_message()

Blocks until a new packet is available to be read, and returns that packet. See poll_message.

peer()

Returns a hash of information about the peer (remote) side of the socket, including :ip, :port, :host, and :canonized (see host_as_string).

poll_message(mode=:nonblock, consume_queue=true)

Tries to read the next packet from the socket. If mode is :nonblock (the default), this will not block and will return nil if there are no packets waiting to be read. Otherwise, this will block until a packet is available. Note that some packet types (DISCONNECT, IGNORE, UNIMPLEMENTED, DEBUG, and KEXINIT) are handled silently by this method, and will never be returned.

If a key-exchange is in process and a disallowed packet type is received, it will be enqueued and otherwise ignored. When a key-exchange is not in process, and consume_queue is true, packets will be first read from the queue before the socket is queried.

push(packet)

Adds the given packet to the packet queue. If the queue is non-empty, poll_message will return packets from the queue in the order they were received.

rekey!()

Requests a rekey operation, and blocks until the operation completes. If a rekey is already pending, this returns immediately, having no effect.

rekey_as_needed()

Returns immediately if a rekey is already in process. Otherwise, if a rekey is needed (as indicated by the socket, see PacketStream#if_needs_rekey?) one is performed, causing this method to block until it completes.

send_message(message)

Sends the given message via the packet stream, blocking until the entire message has been sent.

service_request(service)

Returns a new service_request packet for the given service name, ready for sending to the server.

shutdown!()

Performs a "hard" shutdown of the connection. In general, this should never be done, but it might be necessary (in a rescue clause, for instance, when the connection needs to close but you don‘t know the status of the underlying protocol‘s state).

wait() {|| ...}

Waits (blocks) until the given block returns true. If no block is given, this just waits long enough to see if there are any pending packets. Any packets read are enqueued (see push).

[Validate]