mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-08 08:10:55 +03:00
change transport layer to use millisecond timeouts
This commit is contained in:
@@ -63,7 +63,7 @@ public class ConnectionImpl
|
|||||||
*/
|
*/
|
||||||
public ConnectionImpl(Transport trans) {
|
public ConnectionImpl(Transport trans) {
|
||||||
super("ssh-connection", trans);
|
super("ssh-connection", trans);
|
||||||
timeoutMs = trans.getTimeout() * 1000;
|
timeoutMs = trans.getTimeoutMs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ final class KeyExchanger
|
|||||||
* @param waitForDone whether should block till key exchange completed
|
* @param waitForDone whether should block till key exchange completed
|
||||||
*
|
*
|
||||||
* @throws TransportException if there is an error during key exchange
|
* @throws TransportException if there is an error during key exchange
|
||||||
* @see {@link Transport#setTimeout} for setting timeout for kex
|
* @see {@link Transport#setTimeoutMs} for setting timeout for kex
|
||||||
*/
|
*/
|
||||||
void startKex(boolean waitForDone)
|
void startKex(boolean waitForDone)
|
||||||
throws TransportException {
|
throws TransportException {
|
||||||
@@ -169,7 +169,7 @@ final class KeyExchanger
|
|||||||
|
|
||||||
void waitForDone()
|
void waitForDone()
|
||||||
throws TransportException {
|
throws TransportException {
|
||||||
done.await(transport.getTimeout(), TimeUnit.SECONDS);
|
done.await(transport.getTimeoutMs(), TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void ensureKexOngoing()
|
private synchronized void ensureKexOngoing()
|
||||||
@@ -360,7 +360,7 @@ final class KeyExchanger
|
|||||||
* We block on this event to prevent a race condition where we may have received a SSH_MSG_KEXINIT before
|
* We block on this event to prevent a race condition where we may have received a SSH_MSG_KEXINIT before
|
||||||
* having sent the packet ourselves (would cause gotKexInit() to fail)
|
* having sent the packet ourselves (would cause gotKexInit() to fail)
|
||||||
*/
|
*/
|
||||||
kexInitSent.await(transport.getTimeout(), TimeUnit.SECONDS);
|
kexInitSent.await(transport.getTimeoutMs(), TimeUnit.MILLISECONDS);
|
||||||
gotKexInit(buf);
|
gotKexInit(buf);
|
||||||
expected = Expected.FOLLOWUP;
|
expected = Expected.FOLLOWUP;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -86,14 +86,14 @@ public interface Transport
|
|||||||
Config getConfig();
|
Config getConfig();
|
||||||
|
|
||||||
/** @return the timeout that is currently set for blocking operations. */
|
/** @return the timeout that is currently set for blocking operations. */
|
||||||
int getTimeout();
|
int getTimeoutMs();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a timeout for methods that may block.
|
* Set a timeout for methods that may block.
|
||||||
*
|
*
|
||||||
* @param timeout the timeout in seconds
|
* @param timeout the timeout in milliseconds
|
||||||
*/
|
*/
|
||||||
void setTimeout(int timeout);
|
void setTimeoutMs(int timeout);
|
||||||
|
|
||||||
/** @return the interval in seconds at which a heartbeat message is sent to the server */
|
/** @return the interval in seconds at which a heartbeat message is sent to the server */
|
||||||
int getHeartbeatInterval();
|
int getHeartbeatInterval();
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public final class TransportImpl
|
|||||||
/** Client version identification string */
|
/** Client version identification string */
|
||||||
private final String clientID;
|
private final String clientID;
|
||||||
|
|
||||||
private volatile int timeout = 30;
|
private volatile int timeoutMs = 30 * 1000; // Crazy long, but it was the original default
|
||||||
|
|
||||||
private volatile boolean authed = false;
|
private volatile boolean authed = false;
|
||||||
|
|
||||||
@@ -241,13 +241,13 @@ public final class TransportImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getTimeout() {
|
public int getTimeoutMs() {
|
||||||
return timeout;
|
return timeoutMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTimeout(int timeout) {
|
public void setTimeoutMs(int timeoutMs) {
|
||||||
this.timeout = timeout;
|
this.timeoutMs = timeoutMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -311,7 +311,7 @@ public final class TransportImpl
|
|||||||
try {
|
try {
|
||||||
serviceAccept.clear();
|
serviceAccept.clear();
|
||||||
sendServiceRequest(service.getName());
|
sendServiceRequest(service.getName());
|
||||||
serviceAccept.await(timeout, TimeUnit.SECONDS);
|
serviceAccept.await(timeoutMs, TimeUnit.MILLISECONDS);
|
||||||
setService(service);
|
setService(service);
|
||||||
} finally {
|
} finally {
|
||||||
serviceAccept.unlock();
|
serviceAccept.unlock();
|
||||||
|
|||||||
Reference in New Issue
Block a user