Skip to content

Commit

Permalink
Merge pull request #47 from SimplyKyra/add-timeout-parameter
Browse files Browse the repository at this point in the history
SSH Connection Timeout
  • Loading branch information
Joannis authored Nov 19, 2023
2 parents 710c5ad + de360f6 commit 806cff7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Sources/Citadel/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ public final class SSHClient {
reconnect: SSHReconnectMode,
algorithms: SSHAlgorithms = SSHAlgorithms(),
protocolOptions: Set<SSHProtocolOption> = [],
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,
Expand All @@ -160,7 +161,8 @@ public final class SSHClient {
hostKeyValidator: hostKeyValidator,
algorithms: algorithms,
protocolOptions: protocolOptions,
group: group
group: group,
connectTimeout: connectTimeout
)

let client = SSHClient(
Expand Down
5 changes: 3 additions & 2 deletions Sources/Citadel/ClientSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ final class SSHClientSession {
hostKeyValidator: SSHHostKeyValidator,
algorithms: SSHAlgorithms = SSHAlgorithms(),
protocolOptions: Set<SSHProtocolOption> = [],
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(
Expand All @@ -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)

Expand Down

0 comments on commit 806cff7

Please sign in to comment.