Class SocketForwardingChannel<T extends SshContext>

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:
  • Field Details

  • Constructor Details

    • SocketForwardingChannel

      public SocketForwardingChannel(String channeltype, SshConnection con)
      Construct the forwarding channel.
      Parameters:
      channeltype - the type of channel i.e. "forwarded-tcpip"
  • Method Details

    • createCache

      protected CachingDataWindow createCache(int maximumWindowSpace)
      Overrides:
      createCache in class ChannelNG<T extends SshContext>
    • setSelectionKey

      public void setSelectionKey(SelectionKey key)
      Specified by:
      setSelectionKey in interface SelectionKeyAware
    • onChannelOpen

      protected void onChannelOpen()
      does nothing
      Specified by:
      onChannelOpen in class ChannelNG<T extends SshContext>
    • initialize

      public void initialize(ProtocolEngine engine, SshEngine daemon)
      No initialisation is necessary so this method does nothing.
    • createChannel

      protected abstract byte[] createChannel() throws IOException
      Description copied from class: ChannelNG
      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 ChannelNG<T extends SshContext>
      Returns:
      byte[]
      Throws:
      IOException
    • onExtendedData

      protected void onExtendedData(ByteBuffer data, int type)
      does nothing
      Overrides:
      onExtendedData in class ChannelNG<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: 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(ByteBuffer data)
      data has arrived from the end of the tunnel so add to the queue of data heading towards the start of the tunnel
      Overrides:
      onChannelData in class ChannelNG<T extends SshContext>
    • onChannelRequest

      protected void onChannelRequest(String parm1, boolean parm2, byte[] parm3)
      Description copied from class: ChannelNG
      Called when a channel request is received.
      Specified by:
      onChannelRequest in class ChannelNG<T extends SshContext>
    • onChannelFree

      protected void onChannelFree()
      does nothing
      Specified by:
      onChannelFree in class ChannelNG<T extends SshContext>
    • onChannelClosing

      protected void onChannelClosing()
      does nothing
      Specified by:
      onChannelClosing in class ChannelNG<T extends SshContext>
    • cleanupSocket

      protected void cleanupSocket()
    • canClose

      protected boolean canClose()
      Description copied from class: ChannelNG
      Can this channel close?
      Overrides:
      canClose in class ChannelNG<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: ChannelNG
      Called when the channel has been closed to enable resources to be freed.
      Specified by:
      onChannelClosed in class ChannelNG<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:
      onLocalEOF in class ChannelNG<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:
      onRemoteClose in class ChannelNG<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:
      onRemoteEOF in class ChannelNG<T extends SshContext>
    • onChannelOpenConfirmation

      protected abstract void onChannelOpenConfirmation()
      Description copied from class: ChannelNG
      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 ChannelNG<T extends SshContext>
    • evaluateWindowSpace

      protected void evaluateWindowSpace(int remaining)
    • openChannel

      protected abstract byte[] openChannel(byte[] parm1) throws WriteOperationRequest, ChannelOpenException
      Description copied from class: ChannelNG
      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 ChannelNG<T extends SshContext>
      Returns:
      byte[]
      Throws:
      WriteOperationRequest
      ChannelOpenException
    • 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
    • wantsWrite

      public boolean wantsWrite()
      Description copied from interface: SocketHandler
      Tell the selector that the handler wants to write.
      Specified by:
      wantsWrite in interface SocketHandler
      Returns:
    • wantsRead

      public boolean wantsRead()
      Description copied from interface: SocketHandler
      Tell the selector that the handler wants to read.
      Specified by:
      wantsRead in interface SocketHandler
      Returns:
    • getInitialOps

      public int getInitialOps()
      Description copied from interface: SocketHandler
      Returns the current operations the handler is interested in
      Specified by:
      getInitialOps 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
    • addTask

      public void addTask(ConnectionAwareTask task)
      Description copied from interface: SocketHandler
      Add a task to the executor
      Specified by:
      addTask in interface SocketHandler
    • getSelectorThread

      public SelectorThread getSelectorThread()
      Description copied from interface: SocketHandler
      Get the selector thread this handler is connected to.
      Specified by:
      getSelectorThread in interface SocketHandler
      Returns:
    • getName

      public String getName()
      Description copied from interface: SocketHandler
      A name for this Socket
      Specified by:
      getName in interface SocketHandler
      Returns: