diff --git a/Sources/NIOTransportServices/NIOTSConnectionBootstrap.swift b/Sources/NIOTransportServices/NIOTSConnectionBootstrap.swift index 277ea02..4dd4889 100644 --- a/Sources/NIOTransportServices/NIOTSConnectionBootstrap.swift +++ b/Sources/NIOTransportServices/NIOTSConnectionBootstrap.swift @@ -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 { + self.channelOption(NIOTSChannelOptions.multipathServiceType, value: type) + } + /// Specify the `host` and `port` to connect to for the TCP `Channel` that will be established. /// /// - parameters: diff --git a/Sources/NIOTransportServices/NIOTSListenerBootstrap.swift b/Sources/NIOTransportServices/NIOTSListenerBootstrap.swift index ed5241a..f489b4a 100644 --- a/Sources/NIOTransportServices/NIOTSListenerBootstrap.swift +++ b/Sources/NIOTransportServices/NIOTSListenerBootstrap.swift @@ -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: diff --git a/Tests/NIOTransportServicesTests/NIOTSBootstrapTests.swift b/Tests/NIOTransportServicesTests/NIOTSBootstrapTests.swift index 27c43de..678577e 100644 --- a/Tests/NIOTransportServicesTests/NIOTSBootstrapTests.swift +++ b/Tests/NIOTransportServicesTests/NIOTSBootstrapTests.swift @@ -336,6 +336,29 @@ 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) + + do{ + 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() + } + XCTAssertEqual(try listenerChannel.getOption(NIOTSChannelOptions.multipathServiceType).wait(), .handover) + XCTAssertEqual(try connectionChannel.getOption(NIOTSChannelOptions.multipathServiceType).wait(), .handover) + }catch{ + XCTFail() + } + } } extension Channel {