|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.maverick.sshd.Channel
This abstract class provides the basic functions of an SSH2 channel. All terminal sessions, forwarded connections etc, are channels. Either side may open a channel and multiple channels are multiplexed into a single connection. Channels are flow-controlled so that no data may be sent to a channel until a message is received to indicate that a window space is available.
Channel implementations are identified by name and to support the
opening of a channel your server should add the channel's unique name to the
com.maverick.sshd.ConfigurationContext#supportedChannels(). This can
be completed in your com.maverick.sshd.SshDaemon#configure(ConfigurationContext) method.
protected void configure(ConfigurationContext context) {
context.supportedChannels().add(
"chat@sshtools.com",
Class.forName("com.sshtools.ChatChannel"));
}
Data sent by the channel is buffered and sent when window space is available
on the remote side. The incoming window space is decremented whenever data is
received with the abstract evaluateWindowSpace(int) method being called
to enable the channel implementation to add further window space should it
require.
| Nested Class Summary | |
protected class |
Channel.QueuedData
|
| Field Summary | |
protected ConnectionProtocol |
connection
The Connection Protocol instance managing this session, use this instance to disconnect the session or obtain the ip address of the remote client. |
protected int |
localwindow
|
protected java.lang.Object |
localWindowLock
|
| Constructor Summary | |
Channel(java.lang.String channelType,
int maximumPacketSize,
int initialWindowSize)
Construct a channel with the specified settings. |
|
| Method Summary | |
void |
addEventListener(ChannelEventListener listener)
Enable other objects to receive channel events |
void |
addInputListener(java.io.OutputStream out)
Add an OutputStream to receive all channel data input from the remote side of the connection. |
void |
addOutputListener(java.io.OutputStream out)
Add an OutputStream to receive all of the channels output. |
protected boolean |
canClose()
Can this channel close? |
void |
close()
This method closes the channel and free's its resources. |
protected abstract byte[] |
createChannel()
Called when the channel is being created. |
protected abstract void |
evaluateWindowSpace(int remaining)
Called to evaluate the window space available. |
java.lang.String |
getChannelType()
The name of this channel. |
ConnectionProtocol |
getConnection()
Returns the ConnectionProtocol associated with this channel. |
SshContext |
getContext()
Get the current configuration from the underlying connection. |
int |
getLocalId()
The local channel id |
int |
getLocalPacket()
The maximum size of a single packet that the local side will accept. |
int |
getLocalWindow()
The current size of the local data window. |
int |
getQueueSize()
|
int |
getRemoteId()
The remote sides channel id |
int |
getRemotePacket()
The maximum size of a single packet that the remote side will accept. |
int |
getRemoteWindow()
The current size of the remote data window. |
byte[] |
getSessionIdentifier()
Get the session id for the current connection. |
protected boolean |
hasQueuedData()
|
boolean |
isClosed()
Indicates the channel has been closed |
boolean |
isClosing()
Indicates whether the channel is currently performing a close operation |
boolean |
isEOF()
Indicates that the channel is EOF (it will not be receiving any more data from the remote side). |
protected boolean |
isOpen()
Get the open state of the channel. |
protected abstract void |
onChannelClosed()
Called when the channel has been closed to enable resources to be freed. |
protected abstract void |
onChannelClosing()
Called before the channel is closed |
protected abstract void |
onChannelData(byte[] data)
Called by the channel when data arrives from the remote side. |
protected abstract void |
onChannelFree()
This method is called when the channel has been closed and all its resources are no longer required. |
protected abstract void |
onChannelOpen()
Called when the channel has been opened - this method is only called when the remote side requests a channel open. |
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 |
onChannelOpenFailure()
Called when the remote side fails to open a channel in response to our request. |
protected abstract void |
onChannelRequest(java.lang.String type,
boolean wantreply,
byte[] requestdata)
Called when a channel request is received. |
protected abstract void |
onExtendedData(byte[] data,
int type)
Called by the channel when extended data arrives |
protected abstract void |
onLocalEOF()
Called when the local side is EOF. |
protected void |
onRemoteClose()
Called when the remote side closes the channel. |
protected abstract void |
onRemoteEOF()
Called when the remote side reports its OutputStream as EOF. |
protected void |
onWindowAdjust(int count)
|
protected abstract byte[] |
openChannel(byte[] requestdata)
Called when the channel is being opened. |
protected int |
queueSize()
|
protected void |
registerExtendedData(int type)
Call this method to register an extended data type. |
void |
resetIdleState(IdleStateListener listener)
Allows a channel to register and receive idle state events. |
void |
sendChannelData(byte[] data)
Send channel data to the remote side of the channel. |
void |
sendChannelData(byte[] data,
int off,
int len)
Send channel data to the remote side of the channel. |
void |
sendChannelData(byte[] data,
int off,
int len,
java.lang.Runnable r)
|
void |
sendChannelData(byte[] data,
java.lang.Runnable r)
|
void |
sendChannelDataWithBuffering(byte[] data)
Send channel data to the remote side of the channel and block until the data has been added to the local buffer. |
void |
sendChannelDataWithBuffering(byte[] data,
int off,
int len)
Send channel data to the remote side of the channel and block until the data has been sent. |
protected void |
sendChannelRequest(java.lang.String type,
boolean wantreply,
byte[] requestdata)
Send a channel request. |
protected void |
sendExtendedData(byte[] data,
int type)
Send extended channel data. |
protected void |
sendExtendedData(byte[] data,
int off,
int len,
int type)
Send extended channel data. |
protected void |
sendRequestResponse(boolean succeeded)
Send a channel request. |
protected void |
sendWindowAdjust(int count)
Adjust the local window by adding more bytes. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected ConnectionProtocol connection
protected int localwindow
protected java.lang.Object localWindowLock
| Constructor Detail |
public Channel(java.lang.String channelType,
int maximumPacketSize,
int initialWindowSize)
channelType - the name of the channel, for example "session" or "tcpip-forward"maximumPacketSize - the maximum size of an individual packet that the remote side can send through the channelinitialWindowSize - the initial size of the local window.| Method Detail |
public boolean isClosed()
public boolean isEOF()
public int getQueueSize()
public void resetIdleState(IdleStateListener listener)
IdleStateListener instance passed as a parameter will receive
notification once the channel reaches an idle state.
listener - IdleStateListenerpublic void addEventListener(ChannelEventListener listener)
listener - public void addInputListener(java.io.OutputStream out)
out - OutputStreampublic void addOutputListener(java.io.OutputStream out)
out - OutputStreampublic java.lang.String getChannelType()
public int getRemoteWindow()
public int getLocalWindow()
public int getLocalPacket()
public int getRemotePacket()
public int getLocalId()
public int getRemoteId()
protected int queueSize()
protected void registerExtendedData(int type)
throws java.io.IOException
type -
java.io.IOExceptionpublic byte[] getSessionIdentifier()
protected void onWindowAdjust(int count)
protected boolean hasQueuedData()
public ConnectionProtocol getConnection()
ConnectionProtocol associated with this channel.
public void sendChannelData(byte[] data)
data -
public void sendChannelData(byte[] data,
java.lang.Runnable r)
public void sendChannelData(byte[] data,
int off,
int len)
data - off - len -
public void sendChannelData(byte[] data,
int off,
int len,
java.lang.Runnable r)
public void sendChannelDataWithBuffering(byte[] data)
data - byte[]
public void sendChannelDataWithBuffering(byte[] data,
int off,
int len)
data - byte[]off - intlen - intpublic SshContext getContext()
protected void sendExtendedData(byte[] data,
int type)
data - type -
protected void sendExtendedData(byte[] data,
int off,
int len,
int type)
data - off - len - type - protected abstract void onChannelData(byte[] data)
data -
protected abstract void onExtendedData(byte[] data,
int type)
data -
protected void sendChannelRequest(java.lang.String type,
boolean wantreply,
byte[] requestdata)
Send a channel request. Many channel types have extensions that are specific to that particular channel type. An example is requresting a pty (pseudo terminal) for an interactive session. This method enables the sending of channel requests but does not support receiving responses. This should not present a problem as server implementations tend to send messages as one way information, for example the exit-status request of an interactive session.
To handle requests from a client implement
onChannelRequest(String,boolean,byte[]).
type - wantreply - requestdata - protected void onChannelOpenFailure()
protected void onRemoteClose()
public boolean isClosing()
public void close()
protected abstract void onChannelFree()
protected abstract byte[] createChannel()
throws java.io.IOException
java.io.IOException
protected abstract byte[] openChannel(byte[] requestdata)
throws WriteOperationRequest,
ChannelOpenException
requestdata -
WriteOperationRequest
ChannelOpenExceptionprotected abstract void onChannelOpenConfirmation()
protected abstract void onChannelClosed()
protected abstract void onChannelOpen()
protected abstract void onChannelClosing()
protected abstract void onChannelRequest(java.lang.String type,
boolean wantreply,
byte[] requestdata)
type - wantreply - requestdata - protected abstract void evaluateWindowSpace(int remaining)
remaining - protected abstract void onRemoteEOF()
protected boolean canClose()
protected abstract void onLocalEOF()
protected boolean isOpen()
protected void sendRequestResponse(boolean succeeded)
succeeded - protected void sendWindowAdjust(int count)
count -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||