Skip to content

Commit 210c88b

Browse files
Aperencefkuehne
authored andcommitted
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 include declaring a new sharedMPTCPSession property in NSURLSession, and replacing previous uses of [NSURLSession sharedSession] to [NSURLSession sharedMPTCPSession]
1 parent b68dbf0 commit 210c88b

File tree

10 files changed

+143
-4
lines changed

10 files changed

+143
-4
lines changed

Resources/iOS/VLC.entitlements

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
</array>
1919
<key>com.apple.developer.networking.multicast</key>
2020
<true/>
21+
<key>com.apple.developer.networking.multipath</key>
22+
<true/>
2123
<key>com.apple.developer.siri</key>
2224
<true/>
2325
<key>com.apple.developer.ubiquity-container-identifiers</key>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*****************************************************************************
2+
* NSURLSession+sharedMPTCPSession.h
3+
* VLC for iOS
4+
*****************************************************************************
5+
*
6+
* Author: Anthony Doeraene <[email protected]>
7+
*
8+
*****************************************************************************/
9+
10+
#ifndef NSURLSession_sharedMPTCPSession_h
11+
#define NSURLSession_sharedMPTCPSession_h
12+
13+
@interface NSURLSession (sharedMPTCPSession)
14+
+ (NSURLSession *) sharedMPTCPSession;
15+
@end
16+
17+
#endif /* NSURLSession_sharedMPTCPSession_h */
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*****************************************************************************
2+
* NSURLSession+sharedMPTCPSession.m
3+
* VLC for iOS
4+
*****************************************************************************
5+
*
6+
* Author: Anthony Doeraene <[email protected]>
7+
*
8+
*****************************************************************************/
9+
10+
#import <Foundation/Foundation.h>
11+
#include "NSURLSession+sharedMPTCPSession.h"
12+
#include "NSURLSessionConfiguration+default.h"
13+
14+
@implementation NSURLSession (sharedMPTCPSession)
15+
+ (NSURLSession *) sharedMPTCPSession {
16+
static NSURLSession *sharedMPTCPSession = nil;
17+
static dispatch_once_t onceToken;
18+
dispatch_once(&onceToken, ^{
19+
NSURLSessionConfiguration *conf = [NSURLSessionConfiguration defaultMPTCPConfiguration];
20+
// create a session with the MPTCP configuration if MPTCP is enabled, else fall back to TCP
21+
sharedMPTCPSession = [NSURLSession sessionWithConfiguration:conf];
22+
});
23+
return sharedMPTCPSession;
24+
}
25+
@end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*****************************************************************************
2+
* NSURLSessionConfiguration+default.h
3+
* VLC for iOS
4+
*****************************************************************************
5+
*
6+
* Author: Anthony Doeraene <[email protected]>
7+
*
8+
*****************************************************************************/
9+
10+
#ifndef NSURLSessionConfiguration_default_h
11+
#define NSURLSessionConfiguration_default_h
12+
// add a static var defaultMPTCPConfiguration to NSURLSessionConfiguration
13+
@interface NSURLSessionConfiguration (defaultMPTCPConfiguration)
14+
+ (NSURLSessionConfiguration *) defaultMPTCPConfiguration;
15+
@end
16+
#endif /* NSURLSessionConfiguration_default_h */
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*****************************************************************************
2+
* NSURLSessionConfiguration+default.m
3+
* VLC for iOS
4+
*****************************************************************************
5+
*
6+
* Author: Anthony Doeraene <[email protected]>
7+
*
8+
*****************************************************************************/
9+
10+
#import <Foundation/Foundation.h>
11+
#include "NSURLSessionConfiguration+default.h"
12+
13+
@implementation NSURLSessionConfiguration (defaultMPTCPConfiguration)
14+
+ (NSURLSessionConfiguration *) defaultMPTCPConfiguration {
15+
static NSURLSessionConfiguration *defaultMPTCPConfiguration = nil;
16+
static dispatch_once_t onceToken;
17+
dispatch_once(&onceToken, ^{
18+
NSURLSessionConfiguration *conf = [NSURLSessionConfiguration defaultSessionConfiguration];
19+
#if TARGET_OS_IOS
20+
// multipath is only supported on iOS 11.0+
21+
if (@available(iOS 11.0, *)) {
22+
conf.multipathServiceType = NSURLSessionMultipathServiceTypeHandover;
23+
}
24+
#endif
25+
// on other platforms, the defaultMPTCPConfiguration is simply [NSURLSessionConfiguration defaultSessionConfiguration], which is a standard TCP configuration
26+
27+
defaultMPTCPConfiguration = conf;
28+
});
29+
return defaultMPTCPConfiguration;
30+
}
31+
@end

Sources/Network/Download/VLCHTTPFileDownloader.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#import "VLCActivityManager.h"
1616
#import "VLCMediaFileDiscoverer.h"
1717
#import "VLC-Swift.h"
18+
#import "NSURLSessionConfiguration+default.h"
1819

1920
@interface VLCHTTPFileDownloader () <NSURLSessionDelegate>
2021
{
@@ -35,7 +36,7 @@ @implementation VLCHTTPFileDownloader
3536
- (instancetype)init
3637
{
3738
if (self = [super init]) {
38-
_urlSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]
39+
_urlSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultMPTCPConfiguration]
3940
delegate:self
4041
delegateQueue:nil];
4142
_downloadsAccessQueue = dispatch_queue_create("VLCHTTPFileDownloader.downloadsQueue", DISPATCH_QUEUE_SERIAL);

Sources/Network/Open Network Stream/VLCOpenNetworkSubtitlesFinder.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#import "VLCOpenNetworkSubtitlesFinder.h"
1414
#import "VLCPlaybackService.h"
15+
#import "NSURLSession+sharedMPTCPSession.h"
1516

1617
@implementation VLCOpenNetworkSubtitlesFinder
1718

@@ -61,7 +62,7 @@ + (NSData *)sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NS
6162
NSURLResponse __block *urlResponse;
6263
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
6364

64-
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable _data, NSURLResponse * _Nullable _response, NSError * _Nullable _error) {
65+
[[[NSURLSession sharedMPTCPSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable _data, NSURLResponse * _Nullable _response, NSError * _Nullable _error) {
6566
urlResponse = _response;
6667
erreur = _error;
6768
data = _data;

Sources/Playback/Subtitles Downloading/VLCOpenSubtitlesDownloader.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//
99

1010
#import "VLCOpenSubtitlesDownloader.h"
11+
#import "NSURLSession+sharedMPTCPSession.h"
1112

1213
#define kVLCOpenSubtitlesDownloaderApiKey @""
1314

@@ -45,7 +46,7 @@ - (instancetype)initWithUserAgent:(nonnull NSString *)userAgent apiKey:(nonnull
4546
self = [super init];
4647
if (!self) return nil;
4748

48-
_session = [NSURLSession sharedSession];
49+
_session = [NSURLSession sharedMPTCPSession];
4950

5051
_userAgent = userAgent;
5152
_apiKey = apiKey;

Sources/UI Elements/VLCNetworkImageView.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313
#import "VLCNetworkImageView.h"
14+
#import "NSURLSession+sharedMPTCPSession.h"
1415

1516
@implementation VLCNetworkImageView
1617

@@ -51,7 +52,7 @@ - (void)setImageWithURL:(NSURL *)url {
5152
self.image = cachedImage;
5253
} else {
5354
__weak typeof(self) weakSelf = self;
54-
NSURLSession *sharedSession = [NSURLSession sharedSession];
55+
NSURLSession *sharedSession = [NSURLSession sharedMPTCPSession];
5556
self.downloadTask = [sharedSession dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
5657
if (!data) {
5758
return;

VLC.xcodeproj/project.pbxproj

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
0F007EB12C2B46440042A95F /* VLCMLMedia+isWatched.m in Sources */ = {isa = PBXBuildFile; fileRef = 0F007EB02C2B46440042A95F /* VLCMLMedia+isWatched.m */; };
1111
0F47AB962C1C42FF004B630F /* LongPressPlaybackSpeedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F47AB942C1C42FF004B630F /* LongPressPlaybackSpeedView.swift */; };
1212
13925DC647EC27EEB2818FD2 /* libPods-VLC-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B0E3BE184ED7B95399C04EB6 /* libPods-VLC-tvOS.a */; };
13+
1B39FA082C73BBA200F6F960 /* NSURLSessionConfiguration+default.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B2DEE8F2C63D57300E414B4 /* NSURLSessionConfiguration+default.m */; };
14+
1B39FA092C73BBA200F6F960 /* NSURLSessionConfiguration+default.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B2DEE8F2C63D57300E414B4 /* NSURLSessionConfiguration+default.m */; };
15+
1B39FA0A2C73BBA300F6F960 /* NSURLSessionConfiguration+default.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B2DEE8F2C63D57300E414B4 /* NSURLSessionConfiguration+default.m */; };
16+
1B39FA0B2C73BBA300F6F960 /* NSURLSessionConfiguration+default.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B2DEE8F2C63D57300E414B4 /* NSURLSessionConfiguration+default.m */; };
17+
1B39FA0D2C73BBA400F6F960 /* NSURLSessionConfiguration+default.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B2DEE8F2C63D57300E414B4 /* NSURLSessionConfiguration+default.m */; };
18+
1B39FA0E2C73BBA800F6F960 /* NSURLSession+sharedMPTCPSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B2DEE8C2C63D52000E414B4 /* NSURLSession+sharedMPTCPSession.m */; };
19+
1B39FA0F2C73BBA800F6F960 /* NSURLSession+sharedMPTCPSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B2DEE8C2C63D52000E414B4 /* NSURLSession+sharedMPTCPSession.m */; };
20+
1B39FA102C73BBA900F6F960 /* NSURLSession+sharedMPTCPSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B2DEE8C2C63D52000E414B4 /* NSURLSession+sharedMPTCPSession.m */; };
21+
1B39FA112C73BBA900F6F960 /* NSURLSession+sharedMPTCPSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B2DEE8C2C63D52000E414B4 /* NSURLSession+sharedMPTCPSession.m */; };
22+
1B39FA122C73BBA900F6F960 /* NSURLSession+sharedMPTCPSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B2DEE8C2C63D52000E414B4 /* NSURLSession+sharedMPTCPSession.m */; };
1323
226D57DD2B42C4710090AD88 /* VLCFavoriteService.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DA58D642B10E96800E5BA84 /* VLCFavoriteService.m */; };
1424
226D57E12B42FE060090AD88 /* FavoriteHeaderContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 226D57E02B42FE060090AD88 /* FavoriteHeaderContentView.swift */; };
1525
226D57E22B42FE060090AD88 /* FavoriteHeaderContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 226D57E02B42FE060090AD88 /* FavoriteHeaderContentView.swift */; };
@@ -520,6 +530,10 @@
520530
0F47AB942C1C42FF004B630F /* LongPressPlaybackSpeedView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LongPressPlaybackSpeedView.swift; sourceTree = "<group>"; };
521531
1ACB60BB25275E5700405250 /* VLCFirstStepsBaseViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCFirstStepsBaseViewController.h; sourceTree = "<group>"; };
522532
1ACB60BC25275E5700405250 /* VLCFirstStepsBaseViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCFirstStepsBaseViewController.m; sourceTree = "<group>"; };
533+
1B2DEE8B2C63D4FF00E414B4 /* NSURLSession+sharedMPTCPSession.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSURLSession+sharedMPTCPSession.h"; sourceTree = "<group>"; };
534+
1B2DEE8C2C63D52000E414B4 /* NSURLSession+sharedMPTCPSession.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSURLSession+sharedMPTCPSession.m"; sourceTree = "<group>"; };
535+
1B2DEE8E2C63D54900E414B4 /* NSURLSessionConfiguration+default.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSURLSessionConfiguration+default.h"; sourceTree = "<group>"; };
536+
1B2DEE8F2C63D57300E414B4 /* NSURLSessionConfiguration+default.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSURLSessionConfiguration+default.m"; sourceTree = "<group>"; };
523537
226D57E02B42FE060090AD88 /* FavoriteHeaderContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteHeaderContentView.swift; sourceTree = "<group>"; };
524538
226D57E82B4439080090AD88 /* FavoriteSectionHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteSectionHeader.swift; sourceTree = "<group>"; };
525539
226D57EB2B4439880090AD88 /* VLCFavoriteListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VLCFavoriteListViewController.swift; sourceTree = "<group>"; };
@@ -1364,6 +1378,24 @@
13641378
path = Pods;
13651379
sourceTree = "<group>";
13661380
};
1381+
1B2DEE8A2C63D4DE00E414B4 /* NSURLSession */ = {
1382+
isa = PBXGroup;
1383+
children = (
1384+
1B2DEE8B2C63D4FF00E414B4 /* NSURLSession+sharedMPTCPSession.h */,
1385+
1B2DEE8C2C63D52000E414B4 /* NSURLSession+sharedMPTCPSession.m */,
1386+
);
1387+
path = NSURLSession;
1388+
sourceTree = "<group>";
1389+
};
1390+
1B2DEE8D2C63D53100E414B4 /* NSURLSessionConfiguration */ = {
1391+
isa = PBXGroup;
1392+
children = (
1393+
1B2DEE8E2C63D54900E414B4 /* NSURLSessionConfiguration+default.h */,
1394+
1B2DEE8F2C63D57300E414B4 /* NSURLSessionConfiguration+default.m */,
1395+
);
1396+
path = NSURLSessionConfiguration;
1397+
sourceTree = "<group>";
1398+
};
13671399
226D57E62B44379E0090AD88 /* iOS */ = {
13681400
isa = PBXGroup;
13691401
children = (
@@ -2079,6 +2111,8 @@
20792111
7DC7BA7628C894DA00109F28 /* Extensions */ = {
20802112
isa = PBXGroup;
20812113
children = (
2114+
1B2DEE8D2C63D53100E414B4 /* NSURLSessionConfiguration */,
2115+
1B2DEE8A2C63D4DE00E414B4 /* NSURLSession */,
20822116
7DC7BAB928C8959300109F28 /* URLs */,
20832117
7DC7BAA628C8957A00109F28 /* UIKit */,
20842118
7DC7BA9828C8955700109F28 /* UI Elements */,
@@ -3494,17 +3528,21 @@
34943528
isa = PBXSourcesBuildPhase;
34953529
buildActionMask = 2147483647;
34963530
files = (
3531+
1B39FA122C73BBA900F6F960 /* NSURLSession+sharedMPTCPSession.m in Sources */,
34973532
4133CAE922CCB26C0047A4EC /* VLCAccessibilityIdentifier.swift in Sources */,
34983533
4133CAE722CCB0820047A4EC /* Screenshot.swift in Sources */,
34993534
4133CAE822CCB1250047A4EC /* TestHelper.swift in Sources */,
35003535
4133CAEA22CCB4E10047A4EC /* SnapshotHelper.swift in Sources */,
3536+
1B39FA0D2C73BBA400F6F960 /* NSURLSessionConfiguration+default.m in Sources */,
35013537
);
35023538
runOnlyForDeploymentPostprocessing = 0;
35033539
};
35043540
41533C8D211338D500EC3ABA /* Sources */ = {
35053541
isa = PBXSourcesBuildPhase;
35063542
buildActionMask = 2147483647;
35073543
files = (
3544+
1B39FA112C73BBA900F6F960 /* NSURLSession+sharedMPTCPSession.m in Sources */,
3545+
1B39FA0B2C73BBA300F6F960 /* NSURLSessionConfiguration+default.m in Sources */,
35083546
41533C9E2113392F00EC3ABA /* URLHandlerTests.swift in Sources */,
35093547
);
35103548
runOnlyForDeploymentPostprocessing = 0;
@@ -3513,10 +3551,12 @@
35133551
isa = PBXSourcesBuildPhase;
35143552
buildActionMask = 2147483647;
35153553
files = (
3554+
1B39FA102C73BBA900F6F960 /* NSURLSession+sharedMPTCPSession.m in Sources */,
35163555
CAA0B0F720726A0E00B9274E /* TestHelper.swift in Sources */,
35173556
8DD6516F208C89BC0052EE68 /* VLCAccessibilityIdentifier.swift in Sources */,
35183557
CAA0B0F02072651A00B9274E /* XCUIElement+Helpers.swift in Sources */,
35193558
CAA0B0ED2072651000B9274E /* VLCTestMenu.swift in Sources */,
3559+
1B39FA0A2C73BBA300F6F960 /* NSURLSessionConfiguration+default.m in Sources */,
35203560
);
35213561
runOnlyForDeploymentPostprocessing = 0;
35223562
};
@@ -3532,6 +3572,7 @@
35323572
DD8095E01BE3EFC20065D8E1 /* VLCPlaybackInfoTVViewController.m in Sources */,
35333573
DD9D8F651C01F96700B4060F /* VLCPlaybackInfoChaptersTVViewController.m in Sources */,
35343574
DDEAECFE1BDFFAEE00756C83 /* Reachability.m in Sources */,
3575+
1B39FA092C73BBA200F6F960 /* NSURLSessionConfiguration+default.m in Sources */,
35353576
DD3EFF561BDEBCE500B68579 /* VLCLocalNetworkServiceBrowserDSM.m in Sources */,
35363577
7D0C207128C896B800CCFFEF /* URL+isExcludedFromBackup.swift in Sources */,
35373578
DDA1B90A1CE902EE0076BC45 /* VLCNetworkServerLoginInformation+Keychain.m in Sources */,
@@ -3572,6 +3613,7 @@
35723613
226D57DD2B42C4710090AD88 /* VLCFavoriteService.m in Sources */,
35733614
7D1A2DB11BF66335002E0962 /* VLCMDFBrowsingArtworkProvider.m in Sources */,
35743615
DD3EFF501BDEBCE500B68579 /* VLCPlexParser.m in Sources */,
3616+
1B39FA0F2C73BBA800F6F960 /* NSURLSession+sharedMPTCPSession.m in Sources */,
35753617
7D405ED31BEA11CD006ED886 /* VLCHTTPUploaderController.m in Sources */,
35763618
7DC869C328CB7E5700EE99F8 /* VLCNetworkLoginTVViewController.swift in Sources */,
35773619
7DF90B4B1BE7A8110059C0E3 /* IASKSpecifier.m in Sources */,
@@ -3774,6 +3816,7 @@
37743816
DD3EFF3B1BDEBCE500B68579 /* VLCNetworkServerBrowserVLCMedia.m in Sources */,
37753817
8DB0D71924CED15C00915506 /* VideoPlayerControls.swift in Sources */,
37763818
41B93C051A53835300102E8B /* VLCCloudServiceCell.m in Sources */,
3819+
1B39FA082C73BBA200F6F960 /* NSURLSessionConfiguration+default.m in Sources */,
37773820
8DE1887421089B3A00A091D2 /* MediaLibraryBaseModel.swift in Sources */,
37783821
7D6D2CEF2A0A6056001604B3 /* VLCOneDriveController.m in Sources */,
37793822
7D745DD12B88CEBE004B4DCD /* VLCSEPA.m in Sources */,
@@ -3880,6 +3923,7 @@
38803923
444E5BFA24C6081B0003B69C /* PasscodeLockController.swift in Sources */,
38813924
7D6D2CEE2A0A6056001604B3 /* VLCOneDriveTableViewController.m in Sources */,
38823925
7D30F3DF183AB31E00FFC021 /* VLCWiFiUploadTableViewCell.m in Sources */,
3926+
1B39FA0E2C73BBA800F6F960 /* NSURLSession+sharedMPTCPSession.m in Sources */,
38833927
7D30F3EA183AB34200FFC021 /* VLCGoogleDriveController.m in Sources */,
38843928
7D37196428F1F0B800C5A9F2 /* VLCAppSceneDelegate.m in Sources */,
38853929
417D7F601F7BA26200DDF36A /* VLCRemoteControlService.m in Sources */,

0 commit comments

Comments
 (0)