SshConstants#SSH_MSG_KEXINIT message is received.
Apache MINA sshd queues up high-level messages that threads try to send while a key exchange is ongoing, and sends them once the key exchange is done. Sending queued messages may make the peer re-trigger a new key exchange, in which case sending queued messages stops and is resumed at the end of the new key exchange.
| Modifier and Type | Field and Description |
|---|---|
| protected static ExecutorService | flushRunner
An |
| protected final AtomicBoolean | kexFlushed
Indicates that all pending packets have been flushed. |
| protected final AtomicReference | kexFlushedFuture
Never |
| protected final ReentrantReadWriteLock | lock
We need the flushing thread to have priority over writing threads. |
| protected final Logger | |
| protected final Queue | pendingPackets
Queues up high-level packets written during an ongoing key exchange. |
| protected final AbstractSession | session
The |
| protected final AtomicBoolean | shutDown
Indicates that the handler has been shut down. |
| Access | Constructor and Description |
|---|---|
| public | KeyExchangeMessageHandler(AbstractSession
AbstractSession the new instance belongs toLogger to use for writing log messagesCreates a new |
| Modifier and Type | Method and Description |
|---|---|
| private void | drainQueueTo(List<AbstractMap.
|
| protected PendingWriteFuture | Returns: the enqueuedPendingWriteFuturethe SSH command from the buffer cmd, Buffer the buffer)Buffer containing the packet to be sentEnqueues a packet to be written once a running key exchange terminates. |
| protected void | flushQueue(DefaultKeyExchangeFuture
the future obtained from flushDone)getFlushedFuture; will be fulfilled once all pending packets
have been writtenFlushes all packets enqueued while a key exchange was ongoing. |
| public DefaultKeyExchangeFuture | Returns: the previousDefaultKeyExchangeFuture indicating whether all pending packets were flushed.Initializes the state for a new key exchange. |
| protected boolean | Returns: true if the thread may be blocked; false if the packet written must be
queued without blocking the threadSSH command of the buffer to be written cmd)Tells whether the calling thread may be blocked in |
| public void | |
| public AbstractMap. | Returns: the currentDefaultKeyExchangeFuture and the number of currently pending packetsTo be called when the key exchange is done. |
| public void | |
| public <V> V | |
| protected IoWriteFuture | Returns: anIoWriteFuture that will be fulfilled once the packet has indeed been written.SSH command from the buffer cmd, Buffer Buffer containing the packet to writenumber of timeout, TimeUnit TimeUnits to wait at most if the calling thread is blockedTimeUnit of timeoutWrites an SSH packet. |
| public IoWriteFuture | Returns: anIoWriteFuture that will be fulfilled once the packet has indeed been written.packet to write buffer, long number of timeout, TimeUnit TimeUnits to wait at most if the calling thread is blockedTimeUnit of timeoutWrites a packet. |
| flushRunner | back to summary |
|---|---|
| protected static ExecutorService flushRunner An
| |
| kexFlushed | back to summary |
|---|---|
| protected final AtomicBoolean kexFlushed Indicates that all pending packets have been flushed. Set to | |
| kexFlushedFuture | back to summary |
|---|---|
| protected final AtomicReference<DefaultKeyExchangeFuture> kexFlushedFuture Never | |
| lock | back to summary |
|---|---|
| protected final ReentrantReadWriteLock lock We need the flushing thread to have priority over writing threads. So we use a lock that favors writers over readers, and any state updates and the flushing thread are writers, while writePacket() is a reader. | |
| log | back to summary |
|---|---|
| protected final Logger log The | |
| pendingPackets | back to summary |
|---|---|
| protected final Queue<PendingWriteFuture> pendingPackets Queues up high-level packets written during an ongoing key exchange. | |
| session | back to summary |
|---|---|
| protected final AbstractSession session The | |
| shutDown | back to summary |
|---|---|
| protected final AtomicBoolean shutDown Indicates that the handler has been shut down. | |
| KeyExchangeMessageHandler | back to summary |
|---|---|
| public KeyExchangeMessageHandler(AbstractSession session, Logger log) Creates a new
| |
| drainQueueTo | back to summary |
|---|---|
| private void drainQueueTo(List<AbstractMap. | |
| enqueuePendingPacket | back to summary |
|---|---|
| protected PendingWriteFuture enqueuePendingPacket(int cmd, Buffer buffer) Enqueues a packet to be written once a running key exchange terminates.
| |
| flushQueue | back to summary |
|---|---|
| protected void flushQueue(DefaultKeyExchangeFuture flushDone) Flushes all packets enqueued while a key exchange was ongoing. If writing the pending packets triggers a new key exchange, flushing is stopped and is to be resumed by another call to this method when the new key exchange is done.
| |
| initNewKeyExchange | back to summary |
|---|---|
| public DefaultKeyExchangeFuture initNewKeyExchange() Initializes the state for a new key exchange.
| |
| isBlockAllowed | back to summary |
|---|---|
| protected boolean isBlockAllowed(int cmd) Tells whether the calling thread may be blocked in
Typically an internal thread is one of the reading threads of Apache MINA sshd handling an SSH protocol message:
it's holding the
| |
| shutdown | back to summary |
|---|---|
| public void shutdown() Pretends all pending packets had been written. To be called when the | |
| terminateKeyExchange | back to summary |
|---|---|
| public AbstractMap. To be called when the key exchange is done. If there are any pending packets, returns a future that will be
fulfilled when
| |
| updateState | back to summary |
|---|---|
| public void updateState(Runnable update) | |
| updateState | back to summary |
|---|---|
| public <V> V updateState(Supplier<V> update) | |
| writeOrEnqueue | back to summary |
|---|---|
| protected IoWriteFuture writeOrEnqueue(int cmd, Buffer buffer, long timeout, TimeUnit unit) throws IOException Writes an SSH packet. If no KEX is ongoing and there are no pending packets queued to be written after KEX, the
buffer is written directly. Otherwise, the write is enqueued or the calling thread is blocked until all pending
packets have been written, depending on the result of
If
| |
| writePacket | back to summary |
|---|---|
| public IoWriteFuture writePacket(Buffer buffer, long timeout, TimeUnit unit) throws IOException Writes a packet. If a key exchange is ongoing, only low-level messages are written directly; all other messages
are queued and will be written once
If a packet was written, a key exchange may be triggered via
If
| |