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

Add configuration of multipathServiceType in NIOTSConnectionBootstrap #205

Merged
merged 2 commits into from
Sep 18, 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
6 changes: 6 additions & 0 deletions Sources/NIOTransportServices/NIOTSConnectionBootstrap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ public final class NIOTSConnectionBootstrap {
return self
}

/// Specifies a type of Multipath service to use for this connection, instead of the default
/// service type for the event loop.
public func withMultipath(_ type: NWParameters.MultipathServiceType) -> Self {
Aperence marked this conversation as resolved.
Show resolved Hide resolved
self.channelOption(NIOTSChannelOptions.multipathServiceType, value: type)
}

/// Specify the `host` and `port` to connect to for the TCP `Channel` that will be established.
///
/// - parameters:
Expand Down
10 changes: 10 additions & 0 deletions Sources/NIOTransportServices/NIOTSListenerBootstrap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ public final class NIOTSListenerBootstrap {
return self
}

/// Specifies a type of Multipath service to use for this listener, instead of the default
/// service type for the event loop.
///
/// Warning: Multipath service doesn't seem supported on the listener side yet, as
/// described on https://www.mptcp.dev/macOS.html. Note that enabling Multipath
/// may then generate unexpected errors, use this function with caution.
public func withMultipath(_ type: NWParameters.MultipathServiceType) -> Self {
self.serverChannelOption(NIOTSChannelOptions.multipathServiceType, value: type)
}

/// Bind the `NIOTSListenerChannel` to `host` and `port`.
///
/// - parameters:
Expand Down
19 changes: 19 additions & 0 deletions Tests/NIOTransportServicesTests/NIOTSBootstrapTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,25 @@ final class NIOTSBootstrapTests: XCTestCase {
try? connectionChannel?.close().wait()
}
}

func testBootstrapsMultipath() throws {
let group = NIOTSEventLoopGroup()
defer {
try! group.syncShutdownGracefully()
}

let listenerBootstrap = NIOTSListenerBootstrap(group: group).withMultipath(.handover)
let connectionBootstrap = NIOTSConnectionBootstrap(group: group).withMultipath(.handover)

let listenerChannel: Channel = try listenerBootstrap.bind(host: "localhost", port: 0).wait()
let connectionChannel: Channel = try connectionBootstrap.connect(to: listenerChannel.localAddress!).wait()
defer{
try? listenerChannel.close().wait()
try? connectionChannel.close().wait()
}
Aperence marked this conversation as resolved.
Show resolved Hide resolved
XCTAssertEqual(try listenerChannel.getOption(NIOTSChannelOptions.multipathServiceType).wait(), .handover)
XCTAssertEqual(try connectionChannel.getOption(NIOTSChannelOptions.multipathServiceType).wait(), .handover)
}
}

extension Channel {
Expand Down