From de360f6c9b94a98d3bec837fe97db2efde61f1e3 Mon Sep 17 00:00:00 2001 From: SimplyKyra Date: Wed, 4 Oct 2023 21:21:24 -0700 Subject: [PATCH] SSH Connection Timeout Added a parameter to alter the timeout duration. --- Sources/Citadel/Client.swift | 6 ++++-- Sources/Citadel/ClientSession.swift | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Sources/Citadel/Client.swift b/Sources/Citadel/Client.swift index c319a3c..9457f4f 100644 --- a/Sources/Citadel/Client.swift +++ b/Sources/Citadel/Client.swift @@ -151,7 +151,8 @@ public final class SSHClient { reconnect: SSHReconnectMode, algorithms: SSHAlgorithms = SSHAlgorithms(), protocolOptions: Set = [], - group: MultiThreadedEventLoopGroup = .init(numberOfThreads: 1) + group: MultiThreadedEventLoopGroup = .init(numberOfThreads: 1), + connectTimeout:TimeAmount = .seconds(30) ) async throws -> SSHClient { let session = try await SSHClientSession.connect( host: host, @@ -160,7 +161,8 @@ public final class SSHClient { hostKeyValidator: hostKeyValidator, algorithms: algorithms, protocolOptions: protocolOptions, - group: group + group: group, + connectTimeout: connectTimeout ) let client = SSHClient( diff --git a/Sources/Citadel/ClientSession.swift b/Sources/Citadel/ClientSession.swift index 97f9a09..0795a5f 100644 --- a/Sources/Citadel/ClientSession.swift +++ b/Sources/Citadel/ClientSession.swift @@ -99,7 +99,8 @@ final class SSHClientSession { hostKeyValidator: SSHHostKeyValidator, algorithms: SSHAlgorithms = SSHAlgorithms(), protocolOptions: Set = [], - group: EventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) + group: EventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1), + connectTimeout: TimeAmount = .seconds(30) ) async throws -> SSHClientSession { let handshakeHandler = ClientHandshakeHandler(eventLoop: group.next()) var clientConfiguration = SSHClientConfiguration( @@ -123,7 +124,7 @@ final class SSHClientSession { handshakeHandler ]) } - .connectTimeout(.seconds(30)) + .connectTimeout(connectTimeout) .channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1) .channelOption(ChannelOptions.socket(SocketOptionLevel(IPPROTO_TCP), TCP_NODELAY), value: 1)