apple / swift-nio-transport-services

Extensions for SwiftNIO to support Apple platforms as first-class citizens.
https://swiftpackageindex.com/apple/swift-nio-transport-services/main/documentation/niotransportservices
Apache License 2.0
282 stars 71 forks source link

Add configuration of multipathServiceType in NIOTSConnectionBootstrap #205

Open Aperence opened 3 weeks ago

Aperence commented 3 weeks ago

Motivation:

Allow different devices to leverage the capabilities of Mutipath TCP (MPTCP) to enhance the network reliability. Thanks to MPTCP, a connection can for example automatically migrate to another interface if it deteriorates on the first one. This can be especially interesting on MacOS X and iOS, where devices may frequently benefit from multiple interfaces (ethernet + Wi-Fi for Macs and Wi-fi + cellular for iOS). Allowing developers to enable MPTCP on their connections seems thus like a fine addition to this library.

Modifications:

Added a function "withMultipath" on NIOTSConnectionBootstrap, that allow to configure the type of service used for MPTCP (defaults to disabled). This value will be stored in a field, and then propagated to the underlying channel when the connect method will be called. Also updated the parameters field of NIOTSConnectionChannel to set the multipathServiceType accordingly.

Result:

Users will now be able to easily enable Multipath TCP, allowing them to benefit from seamless handover, interactive mode to automatically use the lowest delay interface or aggregate mode to send data in parallel on both interfaces.

Example:

let group = NIOTSEventLoopGroup()
defer {
     try! group.syncShutdownGracefully()
}
let bootstrap = NIOTSConnectionBootstrap(group: group)
    .withMultipath(.handover)   // set handover mode
    .channelInitializer { channel in
        channel.pipeline.addHandler(MyChannelHandler())
    }
try! bootstrap.connect(host: "example.org", port: 12345).wait()
/* the Channel is now connected */
Aperence commented 3 weeks ago

Thank you for your feedback, I'll try to simplify it to use the channel options !

Aperence commented 3 weeks ago

Hello,

I've simplified (a lot) the code thanks to your feedback, it now uses the NIOTSChannelOptions, limiting drastically the modifications needed