From 95642e9e0a557b323491632c9db52ca5dc429d48 Mon Sep 17 00:00:00 2001 From: Aperence Date: Thu, 8 Aug 2024 13:44:36 +0200 Subject: [PATCH] Add Multipath TCP (MPTCP) support MPTCP is a TCP extension allowing to improve network reliabilty by using mutiple network interface for the same TCP connection. Check https://www.mptcp.dev and https://developer.apple.com/documentation/foundation/urlsessionconfiguration/improving_network_reliability_using_multipath_tcp for details. Changes to this repository consists in setting the multipathServiceType of URLSessionConfiguration to Handover, allowing a seamless transition of interface in case of deterioration of the connection. --- SignalServiceKit/Network/ContentProxy.swift | 1 + SignalServiceKit/Network/OWSUrlSession.swift | 5 ++++- SignalServiceKit/Subscriptions/Stripe.swift | 8 +++++++- SignalUI/LinkPreview/LinkPreviewFetcher.swift | 1 + SignalUI/Payments/MobileCoinAPI+Configuration.swift | 1 + 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/SignalServiceKit/Network/ContentProxy.swift b/SignalServiceKit/Network/ContentProxy.swift index bd94b1cb2d8..d75dffc36d2 100644 --- a/SignalServiceKit/Network/ContentProxy.swift +++ b/SignalServiceKit/Network/ContentProxy.swift @@ -25,6 +25,7 @@ public class ContentProxy: NSObject { "HTTPSProxy": proxyHost, "HTTPSPort": proxyPort ] + configuration.multipathServiceType = .handover return configuration } diff --git a/SignalServiceKit/Network/OWSUrlSession.swift b/SignalServiceKit/Network/OWSUrlSession.swift index c94425ed44e..91802b44958 100644 --- a/SignalServiceKit/Network/OWSUrlSession.swift +++ b/SignalServiceKit/Network/OWSUrlSession.swift @@ -81,13 +81,16 @@ public class OWSURLSession: NSObject, OWSURLSessionProtocol { } public static var defaultConfigurationWithCaching: URLSessionConfiguration { - .ephemeral + let configuration = URLSessionConfiguration.ephemeral + configuration.multipathServiceType = .handover + return configuration } public static var defaultConfigurationWithoutCaching: URLSessionConfiguration { let configuration = URLSessionConfiguration.ephemeral configuration.urlCache = nil configuration.requestCachePolicy = .reloadIgnoringLocalCacheData + configuration.multipathServiceType = .handover return configuration } diff --git a/SignalServiceKit/Subscriptions/Stripe.swift b/SignalServiceKit/Subscriptions/Stripe.swift index 7d5ff2e02fd..fdaa3e5deaf 100644 --- a/SignalServiceKit/Subscriptions/Stripe.swift +++ b/SignalServiceKit/Subscriptions/Stripe.swift @@ -270,11 +270,17 @@ fileprivate extension Stripe { : "pk_test_sngOd8FnXNkpce9nPXawKrJD00kIDngZkD" static let authorizationHeader = "Basic \(Data("\(publishableKey):".utf8).base64EncodedString())" + + static let configuration: URLSessionConfiguration{ + let configuration = URLSessionConfiguration.ephemeral + configuration.multipathServiceType = .handover + return configuration + } static let urlSession = OWSURLSession( baseUrl: URL(string: "https://api.stripe.com/v1/")!, securityPolicy: OWSURLSession.defaultSecurityPolicy, - configuration: URLSessionConfiguration.ephemeral + configuration: configuration ) struct API { diff --git a/SignalUI/LinkPreview/LinkPreviewFetcher.swift b/SignalUI/LinkPreview/LinkPreviewFetcher.swift index 0b5219833cd..19669b90a5a 100644 --- a/SignalUI/LinkPreview/LinkPreviewFetcher.swift +++ b/SignalUI/LinkPreview/LinkPreviewFetcher.swift @@ -102,6 +102,7 @@ public class LinkPreviewFetcherImpl: LinkPreviewFetcher { let sessionConfig = URLSessionConfiguration.ephemeral sessionConfig.urlCache = nil sessionConfig.requestCachePolicy = .reloadIgnoringLocalCacheData + sessionConfig.multipathServiceType = .handover // Twitter doesn't return OpenGraph tags to Signal // `curl -A Signal "https://twitter.com/signalapp/status/1280166087577997312?s=20"` diff --git a/SignalUI/Payments/MobileCoinAPI+Configuration.swift b/SignalUI/Payments/MobileCoinAPI+Configuration.swift index 876dcc92000..6ce0dba5d88 100644 --- a/SignalUI/Payments/MobileCoinAPI+Configuration.swift +++ b/SignalUI/Payments/MobileCoinAPI+Configuration.swift @@ -723,6 +723,7 @@ final class MobileCoinHttpRequester: NSObject, HttpRequester { let config = URLSessionConfiguration.default config.timeoutIntervalForRequest = 30 config.timeoutIntervalForResource = 30 + config.multipathServiceType = .handover return config }()