Class SslHandler

    • Field Detail

      • MIN_ENCODER_BUFFER_PACKETS

        protected static final int MIN_ENCODER_BUFFER_PACKETS
        Minimum size of encoder buffer in packets
        See Also:
        Constant Field Values
      • MAX_ENCODER_BUFFER_PACKETS

        protected static final int MAX_ENCODER_BUFFER_PACKETS
        Maximum size of encoder buffer in packets
        See Also:
        Constant Field Values
      • ZERO

        protected static final IoBuffer ZERO
        Zero length buffer used to prime the ssl engine
      • LOGGER

        protected static final org.slf4j.Logger LOGGER
        Static logger
      • mEncodeQueue

        protected final java.util.Deque<WriteRequest> mEncodeQueue
        Write Requests which are enqueued prior to the completion of the handshaking
      • mAckQueue

        protected final java.util.Deque<WriteRequest> mAckQueue
        Requests which have been sent to the socket and waiting acknowledgment
      • mEngine

        protected final javax.net.ssl.SSLEngine mEngine
        SSL Engine
      • mExecutor

        protected final java.util.concurrent.Executor mExecutor
        Task executor
      • mSession

        protected final IoSession mSession
        Socket session
      • mDecodeBuffer

        protected IoBuffer mDecodeBuffer
        Progressive decoder buffer
    • Constructor Detail

      • SslHandler

        public SslHandler​(javax.net.ssl.SSLEngine p,
                          java.util.concurrent.Executor e,
                          IoSession s)
        Instantiates a new handler
        Parameters:
        p - engine
        e - executor
        s - session
    • Method Detail

      • isOpen

        public abstract boolean isOpen()
        Returns:
        true if the encryption session is open
      • isConnected

        public abstract boolean isConnected()
        Returns:
        true if the encryption session is connected and secure
      • open

        public abstract void open​(IoFilter.NextFilter next)
                           throws javax.net.ssl.SSLException
        Opens the encryption session, this may include sending the initial handshake message
        Parameters:
        next - The next filter
        Throws:
        javax.net.ssl.SSLException - The thrown exception
      • receive

        public abstract void receive​(IoFilter.NextFilter next,
                                     IoBuffer message)
                              throws javax.net.ssl.SSLException
        Decodes encrypted messages and passes the results to the next filter.
        Parameters:
        next - The next filter
        message - the received message
        Throws:
        javax.net.ssl.SSLException - The thrown exception
      • ack

        public abstract void ack​(IoFilter.NextFilter next,
                                 WriteRequest request)
                          throws javax.net.ssl.SSLException
        Acknowledge that a WriteRequest has been successfully written to the IoSession

        This functionality is used to enforce flow control by allowing only a specific number of pending write operations at any moment of time. When one WriteRequest is acknowledged, another can be encoded and written.

        Parameters:
        next - The next filter
        request - The request to ack
        Throws:
        javax.net.ssl.SSLException - The thrown exception
      • write

        public abstract void write​(IoFilter.NextFilter next,
                                   WriteRequest request)
                            throws javax.net.ssl.SSLException,
                                   WriteRejectedException
        Encrypts and writes the specified WriteRequest to the IoSession or enqueues it to be processed later.

        The encryption session may be currently handshaking preventing application messages from being written.

        Parameters:
        next - The next filter
        request - The request to write
        Throws:
        javax.net.ssl.SSLException - The thrown exception
        WriteRejectedException - when the session is closing
      • close

        public abstract void close​(IoFilter.NextFilter next,
                                   boolean linger)
                            throws javax.net.ssl.SSLException
        Closes the encryption session and writes any required messages
        Parameters:
        next - The next filter
        linger - if true, write any queued messages before closing
        Throws:
        javax.net.ssl.SSLException - The thrown exception
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • resume_decode_buffer

        protected IoBuffer resume_decode_buffer​(IoBuffer source)
        Combines the received data with any previously received data
        Parameters:
        source - received data
        Returns:
        buffer to decode
      • suspend_decode_buffer

        protected void suspend_decode_buffer​(IoBuffer source)
        Stores data for later use if any is remaining
        Parameters:
        source - the buffer previously returned by resume_decode_buffer(IoBuffer)
      • allocate_encode_buffer

        protected IoBuffer allocate_encode_buffer​(int estimate)
        Allocates the default encoder buffer for the given source size
        Parameters:
        estimate - The estimated remaining size
        Returns:
        buffer The allocated buffer
      • allocate_app_buffer

        protected IoBuffer allocate_app_buffer​(int estimate)
        Allocates the default decoder buffer for the given source size
        Parameters:
        estimate - The estimated remaining size
        Returns:
        buffer The allocated buffer