Package com.sshtools.synergy.ssh
Class SocketForwardingChannel<T extends SshContext>
java.lang.Object
com.sshtools.synergy.ssh.ChannelNG<T>
com.sshtools.synergy.ssh.ForwardingChannel<T>
com.sshtools.synergy.ssh.SocketForwardingChannel<T>
- All Implemented Interfaces:
Channel,SelectionKeyAware,SelectorRegistrationListener,SocketHandler
- Direct Known Subclasses:
LocalForwardingChannel,RemoteForwardingChannel
public abstract class SocketForwardingChannel<T extends SshContext>
extends ForwardingChannel<T>
implements SocketHandler
An abstract forwarding channel implementation for use with forwarding both
local and remote sockets.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.sshtools.synergy.ssh.ChannelNG
ChannelNG.ChannelInputStream -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected SelectionKeystatic final Stringstatic final Stringprotected SelectorThreadprotected SocketChannelstatic final StringFields inherited from class com.sshtools.synergy.ssh.ForwardingChannel
hostToConnect, originatingHost, originatingPort, portToConnectFields inherited from class com.sshtools.synergy.ssh.ChannelNG
cache, con, connection, localWindow, remoteWindow -
Constructor Summary
ConstructorsConstructorDescriptionSocketForwardingChannel(String channeltype, SshConnection con) Construct the forwarding channel. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTask(ConnectionAwareTask task) Add a task to the executorprotected booleancanClose()Can this channel close?protected voidprotected CachingDataWindowcreateCache(int maximumWindowSpace) protected abstract byte[]Called when the channel is being created.protected voidset the closePending flag to true and attempt to close the channelprotected voidevaluateWindowSpace(int remaining) intReturns the current operations the handler is interested ingetName()A name for this SocketGet the selector thread this handler is connected to.voidinitialize(ProtocolEngine engine, SshEngine daemon) No initialisation is necessary so this method does nothing.protected voidCalled when the channel has been closed to enable resources to be freed.protected voiddoes nothingprotected voidonChannelData(ByteBuffer data) data has arrived from the end of the tunnel so add to the queue of data heading towards the start of the tunnelprotected voiddoes nothingprotected voiddoes nothingprotected abstract voidCalled when the channel has been confirmed as open by the remote side - this method is only called when the channel has been requested by this side of the connectionprotected voidonChannelRequest(String parm1, boolean parm2, byte[] parm3) Called when a channel request is received.protected voidonExtendedData(ByteBuffer data, int type) does nothingprotected voidThe start of the tunnel has gone EOF , if the end of the tunnel has already gone EOF then close the tunnel.protected abstract voidCalled by the subsystem when the selector registration has been completed.protected voidWe override this to make sure that all data from the socket has been sent before we close our side of the channelprotected voidThe end of the tunnel has gone EOF , if the start of the tunnel has already gone EOF then close the tunnel.protected abstract byte[]openChannel(byte[] parm1) Called when the channel is being opened.booleanread data from the start/end of tunnel and write it into the ssh tunnel.booleanread data from the ssh tunnel and write it to the start/end point.voidregistrationCompleted(SelectableChannel channel, SelectionKey key, SelectorThread selectorThread) The registration completed and its selector added to an availableSelectorThreadvoidvoidsetThread(SelectorThread thread) Sets the selector thread for this connectionprotected voidbooleanTell the selector that the handler wants to read.booleanTell the selector that the handler wants to write.Methods inherited from class com.sshtools.synergy.ssh.ForwardingChannel
getHost, getOriginatingHost, getOriginatingPort, getPortMethods inherited from class com.sshtools.synergy.ssh.ChannelNG
addEventListener, checkWindowSpace, clearIdleState, close, close, close, disposeCache, evaluateWindowSpace, getChannelType, getCloseFuture, getConnection, getConnectionProtocol, getContext, getInputStream, getLastActivity, getLocalId, getLocalPacket, getLocalWindow, getMaxiumRemotePacketSize, getMaxiumRemoteWindowSize, getOpenFuture, getOutputStream, getRemoteId, getRemotePacket, getRemoteWindow, getSessionIdentifier, getTimeout, haltIncomingData, isAutoConsume, isClosed, isClosing, isConnected, isIncomingDataHalted, isLocalEOF, isOpen, isRemoteEOF, log, log, log, log, logMessage, logMessage, onChannelError, onChannelOpenFailure, onWindowAdjust, processChannelRequestResponse, registerExtendedDataType, resetIdleState, resumeIncomingData, sendChannelDataAndBlock, sendChannelDataAndBlock, sendChannelDataAndBlock, sendChannelDataAndBlock, sendChannelDataAndBlock, sendChannelDataAndBlock, sendChannelRequest, sendChannelRequest, sendData, sendEOF, sendExtendedData, sendExtendedData, sendRequestResponse, sendWindowAdjust, sendWindowAdjust, setTimeoutMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.sshtools.synergy.nio.SocketHandler
getConnection, getContext, initialize
-
Field Details
-
LOCAL_FORWARDING_CHANNEL_TYPE
- See Also:
-
REMOTE_FORWARDING_CHANNEL_TYPE
- See Also:
-
X11_FORWARDING_CHANNEL_TYPE
- See Also:
-
socketChannel
-
selectorThread
-
key
-
-
Constructor Details
-
SocketForwardingChannel
Construct the forwarding channel.- Parameters:
channeltype- the type of channel i.e. "forwarded-tcpip"
-
-
Method Details
-
createCache
- Overrides:
createCachein classChannelNG<T extends SshContext>
-
setSelectionKey
- Specified by:
setSelectionKeyin interfaceSelectionKeyAware
-
onChannelOpen
protected void onChannelOpen()does nothing- Specified by:
onChannelOpenin classChannelNG<T extends SshContext>
-
initialize
No initialisation is necessary so this method does nothing. -
createChannel
Description copied from class:ChannelNGCalled when the channel is being created. You can return data to be sent in the channel open request, or null for none.- Specified by:
createChannelin classChannelNG<T extends SshContext>- Returns:
- byte[]
- Throws:
IOException
-
onExtendedData
does nothing- Overrides:
onExtendedDatain classChannelNG<T extends SshContext>
-
onRegistrationComplete
protected abstract void onRegistrationComplete()Called by the subsystem when the selector registration has been completed. -
registrationCompleted
public void registrationCompleted(SelectableChannel channel, SelectionKey key, SelectorThread selectorThread) Description copied from interface:SelectorRegistrationListenerThe registration completed and its selector added to an availableSelectorThread- Specified by:
registrationCompletedin interfaceSelectorRegistrationListener- Parameters:
channel- SelectableChannelkey- SelectionKeyselectorThread- SelectorThread
-
onChannelData
data has arrived from the end of the tunnel so add to the queue of data heading towards the start of the tunnel- Overrides:
onChannelDatain classChannelNG<T extends SshContext>
-
onChannelRequest
Description copied from class:ChannelNGCalled when a channel request is received.- Specified by:
onChannelRequestin classChannelNG<T extends SshContext>
-
onChannelFree
protected void onChannelFree()does nothing- Specified by:
onChannelFreein classChannelNG<T extends SshContext>
-
onChannelClosing
protected void onChannelClosing()does nothing- Specified by:
onChannelClosingin classChannelNG<T extends SshContext>
-
cleanupSocket
protected void cleanupSocket() -
canClose
protected boolean canClose()Description copied from class:ChannelNGCan this channel close?- Overrides:
canClosein classChannelNG<T extends SshContext>- Returns:
- true if there is no queued data, else false
-
evaluateClosure
protected void evaluateClosure()set the closePending flag to true and attempt to close the channel -
shutdownSocket
protected void shutdownSocket() -
onChannelClosed
protected void onChannelClosed()Description copied from class:ChannelNGCalled when the channel has been closed to enable resources to be freed.- Specified by:
onChannelClosedin classChannelNG<T extends SshContext>
-
onLocalEOF
protected void onLocalEOF()The start of the tunnel has gone EOF , if the end of the tunnel has already gone EOF then close the tunnel.- Specified by:
onLocalEOFin classChannelNG<T extends SshContext>
-
onRemoteClose
protected void onRemoteClose()We override this to make sure that all data from the socket has been sent before we close our side of the channel- Overrides:
onRemoteClosein classChannelNG<T extends SshContext>
-
onRemoteEOF
protected void onRemoteEOF()The end of the tunnel has gone EOF , if the start of the tunnel has already gone EOF then close the tunnel.- Specified by:
onRemoteEOFin classChannelNG<T extends SshContext>
-
onChannelOpenConfirmation
protected abstract void onChannelOpenConfirmation()Description copied from class:ChannelNGCalled when the channel has been confirmed as open by the remote side - this method is only called when the channel has been requested by this side of the connection- Specified by:
onChannelOpenConfirmationin classChannelNG<T extends SshContext>
-
evaluateWindowSpace
protected void evaluateWindowSpace(int remaining) -
openChannel
protected abstract byte[] openChannel(byte[] parm1) throws WriteOperationRequest, ChannelOpenException Description copied from class:ChannelNGCalled when the channel is being opened. You can retrun data to be sent in the channel open confirmation message, or null for none.- Specified by:
openChannelin classChannelNG<T extends SshContext>- Returns:
- byte[]
- Throws:
WriteOperationRequestChannelOpenException
-
processReadEvent
public boolean processReadEvent()read data from the start/end of tunnel and write it into the ssh tunnel.- Specified by:
processReadEventin interfaceSocketHandler- Returns:
- boolean indicating ??
-
processWriteEvent
public boolean processWriteEvent()read data from the ssh tunnel and write it to the start/end point.- Specified by:
processWriteEventin interfaceSocketHandler- Returns:
- boolean
-
wantsWrite
public boolean wantsWrite()Description copied from interface:SocketHandlerTell the selector that the handler wants to write.- Specified by:
wantsWritein interfaceSocketHandler- Returns:
-
wantsRead
public boolean wantsRead()Description copied from interface:SocketHandlerTell the selector that the handler wants to read.- Specified by:
wantsReadin interfaceSocketHandler- Returns:
-
getInitialOps
public int getInitialOps()Description copied from interface:SocketHandlerReturns the current operations the handler is interested in- Specified by:
getInitialOpsin interfaceSocketHandler- Returns:
- int
-
setThread
Sets the selector thread for this connection- Specified by:
setThreadin interfaceSocketHandler- Parameters:
thread- SelectorThread
-
addTask
Description copied from interface:SocketHandlerAdd a task to the executor- Specified by:
addTaskin interfaceSocketHandler
-
getSelectorThread
Description copied from interface:SocketHandlerGet the selector thread this handler is connected to.- Specified by:
getSelectorThreadin interfaceSocketHandler- Returns:
-
getName
Description copied from interface:SocketHandlerA name for this Socket- Specified by:
getNamein interfaceSocketHandler- Returns:
-