From c5c94f313aea01bd4729dea7c3884467716225ca Mon Sep 17 00:00:00 2001 From: Rod Hynes Date: Tue, 3 Nov 2020 15:13:53 -0500 Subject: [PATCH] Make notice handlers compatible with TunnelPoolSize > 1 --- MobileLibrary/Android/PsiphonTunnel/PsiphonTunnel.java | 10 ++++------ .../iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/MobileLibrary/Android/PsiphonTunnel/PsiphonTunnel.java b/MobileLibrary/Android/PsiphonTunnel/PsiphonTunnel.java index 84ee844b3..4aa30b5f1 100644 --- a/MobileLibrary/Android/PsiphonTunnel/PsiphonTunnel.java +++ b/MobileLibrary/Android/PsiphonTunnel/PsiphonTunnel.java @@ -845,9 +845,6 @@ private static String buildPsiphonConfig(Context context, HostLogger logger, Str File oslDownloadDir = new File(context.getFilesDir(), "osl"); json.put("MigrateObfuscatedServerListDownloadDirectory", oslDownloadDir.getAbsolutePath()); - // Note: onConnecting/onConnected logic assumes 1 tunnel connection - json.put("TunnelPoolSize", 1); - // Continue to run indefinitely until connected if (!json.has("EstablishTunnelTimeoutSeconds")) { json.put("EstablishTunnelTimeoutSeconds", 0); @@ -911,14 +908,15 @@ private void handlePsiphonNotice(String noticeJSON) { if (noticeType.equals("Tunnels")) { int count = notice.getJSONObject("data").getInt("count"); - if (count > 0) { + if (count == 0) { + mHostService.onConnecting(); + } else if (count == 1) { if (isVpnMode() && mShouldRouteThroughTunnelAutomatically) { routeThroughTunnel(); } mHostService.onConnected(); - } else { - mHostService.onConnecting(); } + // count > 1 is an additional multi-tunnel establishment, and not reported. } else if (noticeType.equals("AvailableEgressRegions")) { JSONArray egressRegions = notice.getJSONObject("data").getJSONArray("regions"); diff --git a/MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m b/MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m index 42abc4a2c..7eb4b10cf 100644 --- a/MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m +++ b/MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m @@ -831,9 +831,6 @@ + (NSString * _Nullable)buildPsiphonConfig:(id _Nonnull)configObject config[@"DeviceRegion"] = [PsiphonTunnel getDeviceRegion]; - // This library expects a pool size of 1 - config[@"TunnelPoolSize"] = [NSNumber numberWithInt:1]; - // We don't support upgrade downloading config[@"UpgradeDownloadURLs"] = nil; config[@"UpgradeDownloadUrl"] = nil; @@ -899,11 +896,12 @@ - (void)handlePsiphonNotice:(NSString * _Nonnull)noticeJSON { return; } - if ([count integerValue] > 0) { - [self changeConnectionStateTo:PsiphonConnectionStateConnected evenIfSameState:NO]; - } else { + if ([count integerValue] == 0) { [self changeConnectionStateTo:PsiphonConnectionStateConnecting evenIfSameState:NO]; + } else if ([count integerValue] == 1) { + [self changeConnectionStateTo:PsiphonConnectionStateConnected evenIfSameState:NO]; } + // count > 1 is an additional multi-tunnel establishment, and not reported. } else if ([noticeType isEqualToString:@"Exiting"]) { if ([self.tunneledAppDelegate respondsToSelector:@selector(onExiting)]) {