Skip to content

Commit 806cff7

Browse files
authored
Merge pull request #47 from SimplyKyra/add-timeout-parameter
SSH Connection Timeout
2 parents 710c5ad + de360f6 commit 806cff7

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Sources/Citadel/Client.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ public final class SSHClient {
151151
reconnect: SSHReconnectMode,
152152
algorithms: SSHAlgorithms = SSHAlgorithms(),
153153
protocolOptions: Set<SSHProtocolOption> = [],
154-
group: MultiThreadedEventLoopGroup = .init(numberOfThreads: 1)
154+
group: MultiThreadedEventLoopGroup = .init(numberOfThreads: 1),
155+
connectTimeout:TimeAmount = .seconds(30)
155156
) async throws -> SSHClient {
156157
let session = try await SSHClientSession.connect(
157158
host: host,
@@ -160,7 +161,8 @@ public final class SSHClient {
160161
hostKeyValidator: hostKeyValidator,
161162
algorithms: algorithms,
162163
protocolOptions: protocolOptions,
163-
group: group
164+
group: group,
165+
connectTimeout: connectTimeout
164166
)
165167

166168
let client = SSHClient(

Sources/Citadel/ClientSession.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ final class SSHClientSession {
9999
hostKeyValidator: SSHHostKeyValidator,
100100
algorithms: SSHAlgorithms = SSHAlgorithms(),
101101
protocolOptions: Set<SSHProtocolOption> = [],
102-
group: EventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
102+
group: EventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1),
103+
connectTimeout: TimeAmount = .seconds(30)
103104
) async throws -> SSHClientSession {
104105
let handshakeHandler = ClientHandshakeHandler(eventLoop: group.next())
105106
var clientConfiguration = SSHClientConfiguration(
@@ -123,7 +124,7 @@ final class SSHClientSession {
123124
handshakeHandler
124125
])
125126
}
126-
.connectTimeout(.seconds(30))
127+
.connectTimeout(connectTimeout)
127128
.channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
128129
.channelOption(ChannelOptions.socket(SocketOptionLevel(IPPROTO_TCP), TCP_NODELAY), value: 1)
129130

0 commit comments

Comments
 (0)