com.maverick.ssh2
Class Ssh2Channel

java.lang.Object
  extended bycom.maverick.ssh.message.SshAbstractChannel
      extended bycom.maverick.ssh2.Ssh2Channel
All Implemented Interfaces:
SshChannel, SshIO
Direct Known Subclasses:
Ssh2Session

public class Ssh2Channel
extends com.maverick.ssh.message.SshAbstractChannel

All terminal sessions, forwarded connections, etc are channels and this class implements the base SSH2 channel. Either side may open a channel and multiple channels are multiplexed into a single SSH connection. SSH2 channels are flow controlled, no data may be sent to a channel until a message is received to indicate that window space is available.

To open a channel, first create an instance of the channel as follows:

 Ssh2Channel channel = new Ssh2Channel("session", 32768, 32768);
 
The second value passed into the contructor is the initial window space and also the maximum amount of window space that will be available to the other side. The channel manages the window space automatically by increasing the amount available once the data has been read from the channels InputStream and only when the current value falls below half of the maximum.

After the channel has been created the channel is opened through a call to openChannel(Ssh2Channel channel). Once the channel is open you can use the IO streams to send and receive data.

Author:
Lee David Painter

Field Summary
static java.lang.String SESSION_CHANNEL
           
 
Fields inherited from class com.maverick.ssh.message.SshAbstractChannel
CHANNEL_CLOSED, CHANNEL_OPEN, CHANNEL_UNINITIALIZED, channelid, manager, ms, state
 
Constructor Summary
Ssh2Channel(java.lang.String name, int windowsize, int packetsize)
          Construct an SSH2 channel
 
Method Summary
 void addChannelEventListener(ChannelEventListener listener)
          Provides an event listening mechanism.
protected  void channelEOF()
          Called when the remote side data stream is EOF, by default this method does nothing
protected  void channelRequest(java.lang.String requesttype, boolean wantreply, byte[] requestdata)
          Called when a channel request is received, by default this method sends a failure message if the remote side requests a reply.
 void close()
          Closes the channel.
protected  byte[] create()
          Called after the channel has been created by the
protected  com.maverick.ssh2.Ssh2Channel.ChannelInputStream createExtendedDataStream()
          Currently reserved.
 boolean equals(java.lang.Object obj)
          This channel is equal to another channel if the channel id's are equal.
 java.io.InputStream getInputStream()
          Get an InputStream to read incoming channel data.
protected  com.maverick.ssh.message.SshMessageStore getMessageStore()
           
 java.lang.String getName()
          Get the name of the channel.
 java.io.OutputStream getOutputStream()
          Get an OutputStream to write outgoing channel data.
protected  com.maverick.ssh.message.MessageObserver getStickyMessageIds()
           
protected  void open(int remoteid, int remotewindow, int remotepacket)
          Called once an SSH_MSG_CHANNEL_OPEN_CONFIRMATION has been sent.
protected  void open(int remoteid, int remotewindow, int remotepacket, byte[] responsedata)
          Once a SSH_MSG_CHANNEL_OPEN_CONFIRMATION message is received the framework calls this method to complete the channel open operation.
protected  boolean processChannelMessage(com.maverick.ssh.message.SshChannelMessage msg)
          Processes channel request messages by passing the request through to channelRequest().
protected  void processExtendedData(int typecode, byte[] buf, int offset, int len)
          Called when extended data arrives.
protected  void processStandardData(byte[] buf, int offset, int len)
          Called when channel data arrives, by default this method makes the data available in the channels InputStream.
 boolean sendRequest(java.lang.String requesttype, boolean wantreply, byte[] requestdata)
          Sends a channel request.
 void setAutoConsumeInput(boolean autoConsumeInput)
          Automatically consume input data
 
Methods inherited from class com.maverick.ssh.message.SshAbstractChannel
getChannelId, init, isClosed
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SESSION_CHANNEL

public static final java.lang.String SESSION_CHANNEL
See Also:
Constant Field Values
Constructor Detail

Ssh2Channel

public Ssh2Channel(java.lang.String name,
                   int windowsize,
                   int packetsize)

Construct an SSH2 channel

Parameters:
name - the name of the channel, for example "session"
windowsize - the initial window size
packetsize - the maximum packet size
Method Detail

getStickyMessageIds

protected com.maverick.ssh.message.MessageObserver getStickyMessageIds()

setAutoConsumeInput

public void setAutoConsumeInput(boolean autoConsumeInput)
Description copied from interface: SshChannel
Automatically consume input data

Parameters:
autoConsumeInput - boolean

getMessageStore

protected com.maverick.ssh.message.SshMessageStore getMessageStore()
                                                            throws SshException
Throws:
SshException

getName

public java.lang.String getName()
Get the name of the channel.

Returns:
the name of the channel.

getInputStream

public java.io.InputStream getInputStream()
Description copied from interface: SshIO
Get an InputStream to read incoming channel data.

Returns:
the channels InputStream

getOutputStream

public java.io.OutputStream getOutputStream()
Description copied from interface: SshIO
Get an OutputStream to write outgoing channel data.

Returns:
the channels OutputStream

addChannelEventListener

public void addChannelEventListener(ChannelEventListener listener)
Description copied from interface: SshChannel
Provides an event listening mechanism.

Parameters:
listener -

create

protected byte[] create()
Called after the channel has been created by the

open

protected void open(int remoteid,
                    int remotewindow,
                    int remotepacket)
             throws java.io.IOException
Called once an SSH_MSG_CHANNEL_OPEN_CONFIRMATION has been sent.

Parameters:
remoteid -
remotewindow -
remotepacket -
Throws:
java.io.IOException

open

protected void open(int remoteid,
                    int remotewindow,
                    int remotepacket,
                    byte[] responsedata)
             throws java.io.IOException
Once a SSH_MSG_CHANNEL_OPEN_CONFIRMATION message is received the framework calls this method to complete the channel open operation.

Parameters:
remoteid - the senders id
remotewindow - the initial window space available for sending data
remotepacket - the maximum packet size available for sending data
responsedata - the data returned from the remote side in the SSH_MSG_CHANNEL_OPEN_CONFIRMATION message
Throws:
java.io.IOException

processChannelMessage

protected boolean processChannelMessage(com.maverick.ssh.message.SshChannelMessage msg)
                                 throws SshException
Processes channel request messages by passing the request through to channelRequest().

Throws:
SshException

processStandardData

protected void processStandardData(byte[] buf,
                                   int offset,
                                   int len)
                            throws SshException
Called when channel data arrives, by default this method makes the data available in the channels InputStream. Override this method to change this behaviour.

Parameters:
buf -
offset -
len -
Throws:
java.io.IOException
SshException

processExtendedData

protected void processExtendedData(int typecode,
                                   byte[] buf,
                                   int offset,
                                   int len)
                            throws SshException
Called when extended data arrives. This method fires the com.maverick.ssh.ChannelEventListener#extendedDataReceived(com.maverick.ssh.Channel, byte[], int, int, int) event so to maintain code compatibility always call the super method in any overidden method.

Parameters:
typecode - the type of extended data
buf - the data buffer
offset - the offset
len - the length
Throws:
java.io.IOException
SshException

createExtendedDataStream

protected com.maverick.ssh2.Ssh2Channel.ChannelInputStream createExtendedDataStream()
Currently reserved.

Returns:

sendRequest

public boolean sendRequest(java.lang.String requesttype,
                           boolean wantreply,
                           byte[] requestdata)
                    throws SshException
Sends a channel request. Many channels have extensions that are specific to that particular channel type, an example of which is requesting a pseudo terminal from an interactive session.

Parameters:
requesttype - the name of the request, for example "pty-req"
wantreply - specifies whether the remote side should send a success/failure message
requestdata - the request data
Returns:
true if the request succeeded and wantreply=true, otherwise false
Throws:
java.io.IOException
SshException

close

public void close()
Closes the channel. No data may be sent or receieved after this method completes.


equals

public boolean equals(java.lang.Object obj)
This channel is equal to another channel if the channel id's are equal. Please note that channel numbers may be reused so this method should only be called on open channels.


channelRequest

protected void channelRequest(java.lang.String requesttype,
                              boolean wantreply,
                              byte[] requestdata)
                       throws SshException
Called when a channel request is received, by default this method sends a failure message if the remote side requests a reply. Overidden methods should ALWAYS call this superclass method.

Parameters:
requesttype - the name of the request
wantreply - specifies whether the remote side requires a success/failure message
requestdata - the request data
Throws:
java.io.IOException
SshException

channelEOF

protected void channelEOF()
Called when the remote side data stream is EOF, by default this method does nothing

Throws:
java.io.IOException


Copyright © 2003 3SP LTD. All Rights Reserved.