Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional Channel Prehandlers #72

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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