From 8e9a42b7c0e67f9af0d7cf59a8a66bb243bb7c51 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Wed, 29 Dec 2021 20:11:04 +0100 Subject: [PATCH] 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 --- .../src/org/eclipse/jgit/transport/sshd/SshdSession.java | 7 ++++++- .../src/org/eclipse/jgit/transport/SshConstants.java | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSession.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSession.java index c270b44956..b742f5ea42 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSession.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSession.java @@ -51,6 +51,7 @@ import org.apache.sshd.sftp.client.SftpClientFactory; 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 @@ public class SshdSession implements RemoteSession2 { 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; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshConstants.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshConstants.java index d6bdbd800d..48cacf0964 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshConstants.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshConstants.java @@ -70,6 +70,15 @@ public final class 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"; -- 2.39.5