Interface Session

    • Method Detail

      • createBuffer

        default Buffer createBuffer​(byte cmd)
        Create a new buffer for the specified SSH packet and reserve the needed space (5 bytes) for the packet header.
        Parameters:
        cmd - the SSH command
        Returns:
        a new buffer (of unknown size) ready for write
        See Also:
        createBuffer(byte, int)
      • createBuffer

        Buffer createBuffer​(byte cmd,
                            int estimatedSize)
        Create a new buffer for the specified SSH packet and reserve the needed space (5 bytes) for the packet header.
        Parameters:
        cmd - The SSH command to initialize the buffer with
        estimatedSize - Estimated number of bytes the buffer will hold, 0 if unknown.
        Returns:
        a new buffer ready for write
        See Also:
        prepareBuffer(byte, Buffer)
      • prepareBuffer

        Buffer prepareBuffer​(byte cmd,
                             Buffer buffer)
        Prepare a new "clean" buffer while reserving the needed space (5 bytes) for the packet header.
        Parameters:
        cmd - The SSH command to initialize the buffer with
        buffer - The Buffer instance to initialize
        Returns:
        The initialized buffer
      • sendDebugMessage

        IoWriteFuture sendDebugMessage​(boolean display,
                                       java.lang.Object msg,
                                       java.lang.String lang)
                                throws java.io.IOException
        Sends an SSH_MSG_DEBUG to the peer session
        Parameters:
        display - true if OK to display the message at the peer as-is
        msg - The message object whose toString() value to be used - if null then the "null" string is sent
        lang - The language - null/empty if some pre-agreed default is used
        Returns:
        An IoWriteFuture that can be used to check when the packet has actually been sent
        Throws:
        java.io.IOException - if an error occurred when encoding or sending the packet
        See Also:
        RFC 4253 - section 11.3
      • sendIgnoreMessage

        IoWriteFuture sendIgnoreMessage​(byte... data)
                                 throws java.io.IOException
        Sends an SSH_MSG_IGNORE to the peer session
        Parameters:
        data - The message data
        Returns:
        An IoWriteFuture that can be used to check when the packet has actually been sent
        Throws:
        java.io.IOException - if an error occurred when encoding or sending the packet
        See Also:
        RFC 4253 - section 11.2
      • writePacket

        IoWriteFuture writePacket​(Buffer buffer)
                           throws java.io.IOException
        Encode and send the given buffer. The buffer has to have 5 bytes free at the beginning to allow the encoding to take place. Also, the write position of the buffer has to be set to the position of the last byte to write.
        Parameters:
        buffer - the buffer to encode and send
        Returns:
        An IoWriteFuture that can be used to check when the packet has actually been sent
        Throws:
        java.io.IOException - if an error occurred when encoding sending the packet
      • writePacket

        default IoWriteFuture writePacket​(Buffer buffer,
                                          java.time.Duration timeout)
                                   throws java.io.IOException
        Encode and send the given buffer with the specified timeout. If the buffer could not be written before the timeout elapses, the returned IoWriteFuture will be set with a TimeoutException exception to indicate a timeout.
        Parameters:
        buffer - the buffer to encode and spend
        timeout - the (never null) timeout value - its milliseconds value will be used
        Returns:
        a future that can be used to check when the packet has actually been sent
        Throws:
        java.io.IOException - if an error occurred when encoding or sending the packet
        See Also:
        writePacket(Buffer, long)
      • writePacket

        default IoWriteFuture writePacket​(Buffer buffer,
                                          long maxWaitMillis)
                                   throws java.io.IOException
        Encode and send the given buffer with the specified timeout. If the buffer could not be written before the timeout elapses, the returned IoWriteFuture will be set with a TimeoutException exception to indicate a timeout.
        Parameters:
        buffer - the buffer to encode and spend
        maxWaitMillis - the timeout in milliseconds
        Returns:
        a future that can be used to check when the packet has actually been sent
        Throws:
        java.io.IOException - if an error occurred when encoding or sending the packet
      • writePacket

        IoWriteFuture writePacket​(Buffer buffer,
                                  long timeout,
                                  java.util.concurrent.TimeUnit unit)
                           throws java.io.IOException
        Encode and send the given buffer with the specified timeout. If the buffer could not be written before the timeout elapses, the returned IoWriteFuture will be set with a TimeoutException exception to indicate a timeout.
        Parameters:
        buffer - the buffer to encode and spend
        timeout - the timeout
        unit - the time unit of the timeout parameter
        Returns:
        a future that can be used to check when the packet has actually been sent
        Throws:
        java.io.IOException - if an error occurred when encoding or sending the packet
      • request

        default Buffer request​(java.lang.String request,
                               Buffer buffer,
                               long timeout,
                               java.util.concurrent.TimeUnit unit)
                        throws java.io.IOException
        Send a global request and wait for the response. This must only be used when sending a SSH_MSG_GLOBAL_REQUEST with a result expected, else it will time out
        Parameters:
        request - the request name - used mainly for logging and debugging
        buffer - the buffer containing the global request
        timeout - The number of time units to wait - must be positive
        unit - The TimeUnit to wait for the response
        Returns:
        the return buffer if the request was successful, null otherwise.
        Throws:
        java.io.IOException - if an error occurred when encoding or sending the packet
        java.net.SocketTimeoutException - If no response received within specified timeout
      • request

        default Buffer request​(java.lang.String request,
                               Buffer buffer,
                               java.time.Duration timeout)
                        throws java.io.IOException
        Send a global request and wait for the response. This must only be used when sending a SSH_MSG_GLOBAL_REQUEST with a result expected, else it will time out
        Parameters:
        request - the request name - used mainly for logging and debugging
        buffer - the buffer containing the global request
        timeout - The (never null) timeout to wait - its milliseconds value is used
        Returns:
        the return buffer if the request was successful, null otherwise.
        Throws:
        java.io.IOException - if an error occurred when encoding or sending the packet
        java.net.SocketTimeoutException - If no response received within specified timeout
      • request

        Buffer request​(java.lang.String request,
                       Buffer buffer,
                       long maxWaitMillis)
                throws java.io.IOException
        Send a global request and wait for the response. This must only be used when sending a SSH_MSG_GLOBAL_REQUEST with a result expected, else it will time out
        Parameters:
        request - the request name - used mainly for logging and debugging
        buffer - the buffer containing the global request
        maxWaitMillis - Max. time to wait for response (millis) - must be positive
        Returns:
        the return buffer if the request was successful, null otherwise.
        Throws:
        java.io.IOException - if an error occurred when encoding or sending the packet
        java.net.SocketTimeoutException - If no response received within specified timeout
      • exceptionCaught

        void exceptionCaught​(java.lang.Throwable t)
        Handle any exceptions that occurred on this session. The session will be closed and a disconnect packet will be sent before if the given exception is an SshException with a positive error code
        Parameters:
        t - the exception to process
      • reExchangeKeys

        KeyExchangeFuture reExchangeKeys()
                                  throws java.io.IOException
        Initiate a new key exchange.
        Returns:
        A KeyExchangeFuture for awaiting the completion of the exchange
        Throws:
        java.io.IOException - If failed to request keys re-negotiation
      • getService

        <T extends Service> T getService​(java.lang.Class<T> clazz)
        Get the service of the specified type. If the service is not of the specified class, an IllegalStateException will be thrown.
        Type Parameters:
        T - The generic Service type
        Parameters:
        clazz - The service class
        Returns:
        The service instance
        Throws:
        java.lang.IllegalStateException - If failed to find a matching service
      • getIoSession

        IoSession getIoSession()
        Returns:
        The IoSession associated to this session
      • getLocalAddress

        default java.net.SocketAddress getLocalAddress()
        Specified by:
        getLocalAddress in interface ConnectionEndpointsIndicator
        Returns:
        the socket address of local machine which is associated with this session.
      • getTimeoutStatus

        TimeoutIndicator getTimeoutStatus()
        Check if timeout has occurred.
        Returns:
        the timeout status - never null
      • getIdleTimeout

        java.time.Duration getIdleTimeout()
        Returns:
        Timeout value in milliseconds for communication
      • getIdleTimeoutStart

        java.time.Instant getIdleTimeoutStart()
        Returns:
        The timestamp value (milliseconds since EPOCH) when timer was started
      • resetIdleTimeout

        java.time.Instant resetIdleTimeout()
        Re-start idle timeout timer
        Returns:
        The timestamp value (milliseconds since EPOCH) when timer was started
        See Also:
        getIdleTimeoutStart()
      • getAuthTimeout

        java.time.Duration getAuthTimeout()
        Returns:
        Timeout value in milliseconds for authentication stage
      • getAuthTimeoutStart

        java.time.Instant getAuthTimeoutStart()
        Returns:
        The timestamp value (milliseconds since EPOCH) when timer was started
      • resetAuthTimeout

        java.time.Instant resetAuthTimeout()
        Re-start the authentication timeout timer
        Returns:
        The timestamp value (milliseconds since EPOCH) when timer was started
        See Also:
        getAuthTimeoutStart()
      • setAuthenticated

        void setAuthenticated()
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • getKex

        KeyExchange getKex()
        Returns:
        The current KeyExchange in progress - null if KEX not started or successfully completed
      • disconnect

        void disconnect​(int reason,
                        java.lang.String msg)
                 throws java.io.IOException
        Send a disconnect packet with the given reason and message. Once the packet has been sent, the session will be closed asynchronously.
        Parameters:
        reason - the reason code for this disconnect
        msg - the text message
        Throws:
        java.io.IOException - if an error occurred sending the packet
      • startService

        void startService​(java.lang.String name,
                          Buffer buffer)
                   throws java.lang.Exception
        Parameters:
        name - Service name
        buffer - Extra information provided when the service start request was received
        Throws:
        java.lang.Exception - If failed to start it
      • resolveAttribute

        default <T> T resolveAttribute​(AttributeRepository.AttributeKey<T> key)
        Description copied from interface: AttributeRepository
        Attempts to resolve the associated value by going up the store's hierarchy (if any)
        Specified by:
        resolveAttribute in interface AttributeRepository
        Type Parameters:
        T - The generic attribute type
        Parameters:
        key - The key of the attribute; must not be null.
        Returns:
        null if there is no value associated with the specified key either in this repository or any of its ancestors (if any available)