]> source.dussan.org Git - jgit.git/commitdiff
sshd: support the ConnectTimeout ssh config 78/189378/3
authorThomas Wolf <thomas.wolf@paranor.ch>
Wed, 29 Dec 2021 19:11:04 +0000 (20:11 +0100)
committerThomas Wolf <thomas.wolf@paranor.ch>
Sun, 30 Jan 2022 16:13:47 +0000 (17:13 +0100)
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>
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSession.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/SshConstants.java

index c270b44956fafdb59666af41c19731778ee38c8a..b742f5ea42cc67a88e8531f3e41a451d354913ed 100644 (file)
@@ -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;
index d6bdbd800daa2e6aed2b3be02902c0604603bf08..48cacf0964582737b9224067b3d2bf512e3a8bf8 100644 (file)
@@ -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";