com.maverick.sshd
Class SocketForwardingChannel

java.lang.Object
  extended bycom.maverick.sshd.Channel
      extended bycom.maverick.sshd.ForwardingChannel
          extended bycom.maverick.sshd.SocketForwardingChannel
All Implemented Interfaces:
SelectorRegistrationListener, SocketHandler
Direct Known Subclasses:
LocalForwardingChannel, RemoteForwardingChannel

public abstract class SocketForwardingChannel
extends ForwardingChannel
implements SocketHandler

An abstract forwarding channel implementation for use with forwarding both local and remote sockets.

Author:
Lee David Painter
See Also:
ForwardingChannel

Nested Class Summary
 
Nested classes inherited from class com.maverick.sshd.Channel
Channel.QueuedData
 
Field Summary
 
Fields inherited from class com.maverick.sshd.ForwardingChannel
hostToConnect, originatingHost, originatingPort, portToConnect
 
Fields inherited from class com.maverick.sshd.Channel
connection, localwindow, localWindowLock
 
Constructor Summary
SocketForwardingChannel(java.lang.String channeltype)
          Construct the forwarding channel.
 
Method Summary
protected  boolean canClose()
          Can this channel close?
protected abstract  byte[] createChannel()
          Called when the channel is being created.
protected  void evaluateClosure()
          set the closePending flag to true and attempt to close the channel
protected  void evaluateWindowSpace(int remaining)
          Called to evaluate the window space available.
 int getInterestedOps()
          Returns the current operations the handler is interested in
 void initialize(ProtocolEngine engine, Daemon daemon)
          No initialization is necessary so this method does nothing.
protected  void onChannelClosed()
          Called when the channel has been closed to enable resources to be freed.
protected  void onChannelClosing()
          does nothing
protected  void onChannelData(byte[] data)
          data has arrived from the end of the tunnel so add to the queue of data heading towards the start of the tunnel
protected  void onChannelFree()
          does nothing
protected  void onChannelOpen()
          does nothing
protected abstract  void onChannelOpenConfirmation()
          Called 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
protected  void onChannelRequest(java.lang.String parm1, boolean parm2, byte[] parm3)
          Called when a channel request is received.
protected  void onExtendedData(byte[] data, int type)
          does nothing
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.
protected abstract  void onRegistrationComplete()
          Called by the subsystem when the selector registration has been completed.
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
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.
protected abstract  byte[] openChannel(byte[] parm1)
          Called when the channel is being opened.
 boolean processReadEvent()
          read data from the start/end of tunnel and write it into the ssh tunnel.
 boolean processWriteEvent()
          read data from the ssh tunnel and write it to the start/end point.
 void registrationCompleted(java.nio.channels.SelectableChannel channel, java.nio.channels.SelectionKey key, SelectorThread selectorThread)
          The registration completed and its selector added to an available SelectorThread
 void setThread(SelectorThread thread)
          Sets the selector thread for this connection
protected  void shutdownSocket()
           
 
Methods inherited from class com.maverick.sshd.ForwardingChannel
getHost, getOriginatingHost, getOriginatingPort, getPort
 
Methods inherited from class com.maverick.sshd.Channel
addEventListener, addInputListener, addOutputListener, close, getChannelType, getConnection, getContext, getLocalId, getLocalPacket, getLocalWindow, getQueueSize, getRemoteId, getRemotePacket, getRemoteWindow, getSessionIdentifier, hasQueuedData, isClosed, isClosing, isEOF, isOpen, onChannelOpenFailure, onWindowAdjust, queueSize, registerExtendedData, resetIdleState, sendChannelData, sendChannelData, sendChannelData, sendChannelData, sendChannelDataWithBuffering, sendChannelDataWithBuffering, sendChannelRequest, sendExtendedData, sendExtendedData, sendRequestResponse, sendWindowAdjust
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketForwardingChannel

public SocketForwardingChannel(java.lang.String channeltype)
Construct the forwarding channel.

Parameters:
channeltype - the type of channel i.e. "forwarded-tcpip"
Method Detail

onChannelOpen

protected void onChannelOpen()
does nothing

Specified by:
onChannelOpen in class Channel

initialize

public void initialize(ProtocolEngine engine,
                       Daemon daemon)
No initialization is necessary so this method does nothing.

Specified by:
initialize in interface SocketHandler
Parameters:
engine - ProtocolEngine
daemon - Daemon

createChannel

protected abstract byte[] createChannel()
                                 throws java.io.IOException
Description copied from class: Channel
Called when the channel is being created. You can return data to be sent in the channel open request, or null for none.

Specified by:
createChannel in class Channel
Returns:
byte[]
Throws:
java.io.IOException

onExtendedData

protected void onExtendedData(byte[] data,
                              int type)
does nothing

Specified by:
onExtendedData in class Channel
Parameters:
data -

onRegistrationComplete

protected abstract void onRegistrationComplete()
Called by the subsystem when the selector registration has been completed.


registrationCompleted

public void registrationCompleted(java.nio.channels.SelectableChannel channel,
                                  java.nio.channels.SelectionKey key,
                                  SelectorThread selectorThread)
Description copied from interface: SelectorRegistrationListener
The registration completed and its selector added to an available SelectorThread

Specified by:
registrationCompleted in interface SelectorRegistrationListener
Parameters:
channel - SelectableChannel
key - SelectionKey
selectorThread - SelectorThread

onChannelData

protected void onChannelData(byte[] data)
data has arrived from the end of the tunnel so add to the queue of data heading towards the start of the tunnel

Specified by:
onChannelData in class Channel
Parameters:
data -

onChannelRequest

protected void onChannelRequest(java.lang.String parm1,
                                boolean parm2,
                                byte[] parm3)
Description copied from class: Channel
Called when a channel request is received.

Specified by:
onChannelRequest in class Channel
Parameters:
parm1 -
parm2 -
parm3 -

onChannelFree

protected void onChannelFree()
does nothing

Specified by:
onChannelFree in class Channel

onChannelClosing

protected void onChannelClosing()
does nothing

Specified by:
onChannelClosing in class Channel

canClose

protected boolean canClose()
Description copied from class: Channel
Can this channel close?

Overrides:
canClose in class Channel
Returns:
true if there is no queued data, else false

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:
onRemoteClose in class Channel

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: Channel
Called when the channel has been closed to enable resources to be freed.

Specified by:
onChannelClosed in class Channel

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:
onLocalEOF in class Channel

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:
onRemoteEOF in class Channel

onChannelOpenConfirmation

protected abstract void onChannelOpenConfirmation()
Description copied from class: Channel
Called 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:
onChannelOpenConfirmation in class Channel

evaluateWindowSpace

protected void evaluateWindowSpace(int remaining)
Description copied from class: Channel
Called to evaluate the window space available. Send a window adjust message if there if the minimum amount of space is not available.

Specified by:
evaluateWindowSpace in class Channel
Parameters:
remaining -

openChannel

protected abstract byte[] openChannel(byte[] parm1)
                               throws WriteOperationRequest,
                                      ChannelOpenException
Description copied from class: Channel
Called 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:
openChannel in class Channel
Parameters:
parm1 -
Returns:
byte[]
Throws:
ChannelOpenException
WriteOperationRequest

processReadEvent

public boolean processReadEvent()
read data from the start/end of tunnel and write it into the ssh tunnel.

Specified by:
processReadEvent in interface SocketHandler
Returns:
boolean indicating ??

processWriteEvent

public boolean processWriteEvent()
read data from the ssh tunnel and write it to the start/end point.

Specified by:
processWriteEvent in interface SocketHandler
Returns:
boolean

getInterestedOps

public int getInterestedOps()
Description copied from interface: SocketHandler
Returns the current operations the handler is interested in

Specified by:
getInterestedOps in interface SocketHandler
Returns:
int

setThread

public void setThread(SelectorThread thread)
Sets the selector thread for this connection

Specified by:
setThread in interface SocketHandler
Parameters:
thread - SelectorThread


Copyright © 2003-2008 SSHTools LTD. All Rights Reserved.