sshd: support the ConnectTimeout ssh config

Parse the value from the ssh config and if set use it when connecting.

Change-Id: I85b44c9468a5027602375706612c46ea7a99b2bd
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
This commit is contained in:
Thomas Wolf 2021-12-29 20:11:04 +01:00
parent f41929708e
commit 8e9a42b7c0
2 changed files with 15 additions and 1 deletions

View File

@ -51,6 +51,7 @@
import org.apache.sshd.sftp.common.SftpException;
import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.internal.transport.ssh.OpenSshConfigFile;
import org.eclipse.jgit.internal.transport.sshd.JGitSshClient;
import org.eclipse.jgit.internal.transport.sshd.SshdText;
import org.eclipse.jgit.transport.FtpChannel;
@ -138,7 +139,11 @@ private ClientSession connect(URIish target, List<URIish> jumps,
JGitSshClient.LOCAL_FORWARD_ADDRESS,
portForward.getBoundAddress());
}
resultSession = connect(hostConfig, context, timeout);
int timeoutInSec = OpenSshConfigFile.timeSpec(
hostConfig.getProperty(SshConstants.CONNECT_TIMEOUT));
resultSession = connect(hostConfig, context,
timeoutInSec > 0 ? Duration.ofSeconds(timeoutInSec)
: timeout);
if (proxySession != null) {
final PortForwardingTracker tracker = portForward;
final ClientSession pSession = proxySession;

View File

@ -70,6 +70,15 @@ private SshConstants() {
/** Key in an ssh config file. */
public static final String CONNECTION_ATTEMPTS = "ConnectionAttempts";
/**
* An OpenSSH time value for the connection timeout. In OpenSSH, this
* includes everything until the end of the initial key exchange; in JGit it
* covers only the underlying TCP connect.
*
* @since 6.1
*/
public static final String CONNECT_TIMEOUT = "ConnectTimeout";
/** Key in an ssh config file. */
public static final String CONTROL_PATH = "ControlPath";