public final class TransportImpl extends java.lang.Object implements Transport
Transport implementation.| Constructor and Description |
|---|
TransportImpl(Config config) |
TransportImpl(Config config,
SSHClient sshClient)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addHostKeyVerifier(HostKeyVerifier hkv)
Adds the specified verifier.
|
void |
die(java.lang.Exception ex)
Kill the transport in an exceptional way.
|
void |
disconnect()
Send a disconnection packet with reason as
DisconnectReason.BY_APPLICATION, and closes this transport. |
void |
disconnect(DisconnectReason reason)
Send a disconnect packet with the given
reason, and closes this transport. |
void |
disconnect(DisconnectReason reason,
java.lang.String message)
Send a disconnect packet with the given
reason and message, and closes this
transport. |
void |
doKex()
Do key exchange and algorithm negotiation.
|
java.lang.String |
getClientVersion() |
Config |
getConfig() |
DisconnectListener |
getDisconnectListener() |
int |
getHeartbeatInterval()
Deprecated.
|
java.lang.String |
getRemoteHost() |
int |
getRemotePort() |
java.lang.String |
getServerVersion()
Returns the version string as sent by the SSH server for identification purposes, e.g.
|
Service |
getService() |
byte[] |
getSessionID() |
int |
getTimeoutMs() |
void |
handle(Message msg,
SSHPacket buf)
This is where all incoming packets are handled.
|
void |
init(java.lang.String remoteHost,
int remotePort,
java.io.InputStream in,
java.io.OutputStream out)
Sets the host information and the streams to be used by this transport.
|
boolean |
isAuthenticated() |
boolean |
isKexDone() |
boolean |
isRunning() |
void |
join()
Joins the thread calling this method to the transport's death.
|
void |
join(int timeout,
java.util.concurrent.TimeUnit unit)
Joins the thread calling this method to the transport's death.
|
void |
reqService(Service service)
Request a SSH service represented by a
Service instance. |
long |
sendUnimplemented()
Sends SSH_MSG_UNIMPLEMENTED in response to the last packet received.
|
void |
setAuthenticated()
Informs this transport that authentication has been completed.
|
void |
setDisconnectListener(DisconnectListener listener)
Specify a
listener that will be notified upon disconnection. |
void |
setHeartbeatInterval(int interval)
Deprecated.
|
void |
setService(Service service)
Sets the currently active
Service. |
void |
setTimeoutMs(int timeoutMs)
Set a timeout for methods that may block.
|
long |
write(SSHPacket payload)
Write a packet over this transport.
|
public TransportImpl(Config config)
public void init(java.lang.String remoteHost,
int remotePort,
java.io.InputStream in,
java.io.OutputStream out)
throws TransportException
TransportTransportException is thrown in case of SSH protocol version incompatibility.init in interface TransportremoteHost - server's hostnameremotePort - server's portin - input stream for the connectionout - output stream for the connectionTransportException - if there is an error during exchange of identification informationpublic void addHostKeyVerifier(HostKeyVerifier hkv)
TransportaddHostKeyVerifier in interface Transporthkv - the host key verifierpublic void doKex()
throws TransportException
TransportdoKex in interface TransportTransportException - if there was an error during key exchangepublic boolean isKexDone()
public int getTimeoutMs()
getTimeoutMs in interface Transportpublic void setTimeoutMs(int timeoutMs)
TransportsetTimeoutMs in interface TransporttimeoutMs - the timeout in milliseconds@Deprecated public int getHeartbeatInterval()
getHeartbeatInterval in interface Transport@Deprecated public void setHeartbeatInterval(int interval)
setHeartbeatInterval in interface Transportinterval - the interval in seconds, 0 means no hearbeatpublic java.lang.String getRemoteHost()
getRemoteHost in interface Transportpublic int getRemotePort()
getRemotePort in interface Transportpublic java.lang.String getClientVersion()
getClientVersion in interface Transportpublic Config getConfig()
public java.lang.String getServerVersion()
TransportTransport.init(java.lang.String, int, java.io.InputStream, java.io.OutputStream), it will be null.getServerVersion in interface Transportnull)public byte[] getSessionID()
getSessionID in interface Transportpublic Service getService()
getService in interface TransportService instance.public void setService(Service service)
TransportService. Handling of non-transport-layer packets is delegated to that service.
For this method to be successful, at least one service request via Transport.reqService(net.schmizz.sshj.Service) must have been successful
(not necessarily for the service being set).setService in interface Transportservice - (null-ok) the Servicepublic void reqService(Service service) throws TransportException
TransportService instance. A separate call to Transport.setService(net.schmizz.sshj.Service) is not
needed.reqService in interface Transportservice - the SSH service to be requestedTransportException - if the request failed for any reasonpublic void setAuthenticated()
TransportsetAuthenticated in interface Transportpublic boolean isAuthenticated()
isAuthenticated in interface Transportpublic long sendUnimplemented()
throws TransportException
TransportsendUnimplemented in interface TransportTransportException - if an error occured sending the packetpublic void join()
throws TransportException
Transportjoin in interface TransportTransportException - if the transport dies of an exceptionpublic void join(int timeout,
java.util.concurrent.TimeUnit unit)
throws TransportException
Transportjoin in interface TransportTransportException - if the transport dies of an exceptionpublic boolean isRunning()
isRunning in interface TransportTransport.init(java.lang.String, int, java.io.InputStream, java.io.OutputStream) and
has not been disconnected.public void disconnect()
TransportDisconnectReason.BY_APPLICATION, and closes this transport.disconnect in interface Transportpublic void disconnect(DisconnectReason reason)
Transportreason, and closes this transport.disconnect in interface Transportreason - reason for disconnectingpublic void disconnect(DisconnectReason reason, java.lang.String message)
Transportreason and message, and closes this
transport.disconnect in interface Transportreason - the reason code for this disconnectmessage - the text messagepublic void setDisconnectListener(DisconnectListener listener)
Transportlistener that will be notified upon disconnection.setDisconnectListener in interface Transportpublic DisconnectListener getDisconnectListener()
getDisconnectListener in interface Transportpublic long write(SSHPacket payload) throws TransportException
Transportpayload SSHPacket should have 5 bytes free at the beginning to avoid a performance penalty
associated with making space for header bytes (packet length, padding length).write in interface Transportpayload - the SSHPacket containing data to sendTransportException - if an error occurred sending the packetpublic void handle(Message msg, SSHPacket buf) throws SSHException
SSHPacketHandler.handle(net.schmizz.sshj.common.Message, net.schmizz.sshj.common.SSHPacket).
Even among the transport layer specific packets, key exchange packets are delegated to KeyExchanger.handle(net.schmizz.sshj.common.Message, net.schmizz.sshj.common.SSHPacket).
This method is called in the context of the reader thread via Decoder.received(byte[], int) when a full
packet has been decoded.handle in interface SSHPacketHandlermsg - the message identiferbuf - buffer containg rest of the packetSSHException - if an error occurs during handling (unrecoverable)