Skip to content

Commit

Permalink
Merge pull request #72 from SimplyKyra/ChannelHandler
Browse files Browse the repository at this point in the history
Optional Channel Prehandlers
  • Loading branch information
Joannis authored Oct 1, 2024
2 parents 472e4f1 + 4d69090 commit 71f88f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Sources/Citadel/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ public final class SSHClient {
/// - algorithms: The algorithms to use. See `SSHAlgorithms` for more information.
/// - protocolOptions: The protocol options to use. See `SSHProtocolOption` for more information.
/// - group: The event loop group to use. Defaults to a single-threaded event loop group.
/// - channelHandlers: Pass in an array of channel prehandlers that execute first. Default empty array
/// - connectTimeout: Pass in the time before the connection times out. Default 30 seconds.
/// - Returns: An SSH client.
public static func connect(
host: String,
Expand All @@ -199,6 +201,7 @@ public final class SSHClient {
algorithms: SSHAlgorithms = SSHAlgorithms(),
protocolOptions: Set<SSHProtocolOption> = [],
group: MultiThreadedEventLoopGroup = .init(numberOfThreads: 1),
channelHandlers: [ChannelHandler] = [],
connectTimeout:TimeAmount = .seconds(30)
) async throws -> SSHClient {
let session = try await SSHClientSession.connect(
Expand All @@ -209,6 +212,7 @@ public final class SSHClient {
algorithms: algorithms,
protocolOptions: protocolOptions,
group: group,
channelHandlers: channelHandlers,
connectTimeout: connectTimeout
)

Expand Down
5 changes: 4 additions & 1 deletion Sources/Citadel/ClientSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ final class SSHClientSession {
/// - algorithms: The algorithms to use, will use the default algorithms if not specified.
/// - protocolOptions: The protocol options to use, will use the default options if not specified.
/// - group: The event loop group to use, will use a new group with one thread if not specified.
/// - channelHandlers: Pass in an array of channel prehandlers that execute first. Default empty array
/// - connectTimeout: Pass in the time before the connection times out. Default 30 seconds.
public static func connect(
host: String,
port: Int = 22,
Expand All @@ -104,6 +106,7 @@ final class SSHClientSession {
algorithms: SSHAlgorithms = SSHAlgorithms(),
protocolOptions: Set<SSHProtocolOption> = [],
group: EventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1),
channelHandlers: [ChannelHandler] = [],
connectTimeout: TimeAmount = .seconds(30)
) async throws -> SSHClientSession {
let handshakeHandler = ClientHandshakeHandler(
Expand All @@ -122,7 +125,7 @@ final class SSHClientSession {
}

let bootstrap = ClientBootstrap(group: group).channelInitializer { channel in
channel.pipeline.addHandlers([
channel.pipeline.addHandlers(channelHandlers + [
NIOSSHHandler(
role: .client(clientConfiguration),
allocator: channel.allocator,
Expand Down

0 comments on commit 71f88f5

Please sign in to comment.