From f485d9bd69b2a63555681d0f14fe9e53cf6a853e Mon Sep 17 00:00:00 2001 From: Jigar-f Date: Tue, 17 Dec 2024 17:10:20 +0530 Subject: [PATCH 1/2] Update to latest main. --- go.mod | 4 ++-- internalsdk/auth/auth.go | 2 +- internalsdk/ios/config.go | 14 ++++++++------ internalsdk/ios/ios.go | 2 -- internalsdk/pro/pro.go | 2 +- internalsdk/session_model.go | 2 +- ios/Runner/AppDelegate.swift | 14 +++++++++++++- ios/Runner/Lantern/Core/Vpn/VPNManager.swift | 4 ++-- ios/Runner/Lantern/Core/Vpn/VpnHelper.swift | 8 +------- ios/Runner/Lantern/Models/VpnModel.swift | 8 ++++++-- ios/Runner/Lantern/Utils/RunningEnv.swift | 2 +- 11 files changed, 36 insertions(+), 26 deletions(-) diff --git a/go.mod b/go.mod index 4ea2fae86..e7c6bed75 100644 --- a/go.mod +++ b/go.mod @@ -38,6 +38,8 @@ require ( github.com/getlantern/eventual/v2 v2.0.2 github.com/getlantern/filepersist v0.0.0-20210901195658-ed29a1cb0b7c github.com/getlantern/flashlight/v7 v7.6.165 + github.com/getlantern/fronted v0.0.0-20241212194832-a55b6db2616e + github.com/getlantern/geolookup v0.0.0-20230327091034-aebe73c6eef4 github.com/getlantern/golog v0.0.0-20230503153817-8e72de7e0a65 github.com/getlantern/hidden v0.0.0-20220104173330-f221c5a24770 github.com/getlantern/i18n v0.0.0-20181205222232-2afc4f49bb1c @@ -87,8 +89,6 @@ require ( github.com/cloudflare/circl v1.3.7 // indirect github.com/coder/websocket v1.8.12 // indirect github.com/containerd/console v1.0.3 // indirect - github.com/getlantern/fronted v0.0.0-20241212194832-a55b6db2616e // indirect - github.com/getlantern/geolookup v0.0.0-20230327091034-aebe73c6eef4 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/gookit/color v1.5.4 // indirect github.com/lithammer/fuzzysearch v1.1.8 // indirect diff --git a/internalsdk/auth/auth.go b/internalsdk/auth/auth.go index 1326f8615..56fdd9594 100644 --- a/internalsdk/auth/auth.go +++ b/internalsdk/auth/auth.go @@ -58,7 +58,7 @@ func NewClient(baseURL string, userConfig func() common.UserConfig) AuthClient { // iOS // There is no use of chnained proxy in iOS since all requests will fail httpClient = &http.Client{ - Transport: proxied.Fronted(""), + Transport: proxied.Fronted("authClient-ios"), Timeout: 30 * time.Second, } } else { diff --git a/internalsdk/ios/config.go b/internalsdk/ios/config.go index 05e385b42..bd286af43 100644 --- a/internalsdk/ios/config.go +++ b/internalsdk/ios/config.go @@ -106,7 +106,7 @@ type UserConfig struct { func (cf *configurer) Configure(userID int, proToken string, refreshProxies bool) (*ConfigResult, error) { // Log the full method run time. defer func(start time.Time) { - log.Debugf("Configured completed in %v", time.Since(start)) + log.Debugf("Configured completed in %v seconds", time.Since(start).Seconds()) }(time.Now()) result := &ConfigResult{} if err := cf.writeUserConfig(); err != nil { @@ -128,12 +128,13 @@ func (cf *configurer) Configure(userID int, proToken string, refreshProxies bool var globalUpdated, proxiesUpdated bool setupFronting := func() error { + start := time.Now() log.Debug("Setting up fronting") - defer log.Debug("Set up fronting") - if frontingErr := cf.configureFronting(global, shortFrontedAvailableTimeout); frontingErr != nil { + defer log.Debugf("Setting up fronting completed in %v", time.Since(start).Seconds()) + if frontingErr := cf.configureFronting(global); frontingErr != nil { log.Errorf("Unable to configure fronting on first try, update global config directly from GitHub and try again: %v", frontingErr) global, globalUpdated = cf.updateGlobal(http.DefaultTransport, global, globalEtag, "https://raw.githubusercontent.com/getlantern/lantern-binaries/main/cloud.yaml.gz") - return cf.configureFronting(global, longFrontedAvailableTimeout) + return cf.configureFronting(global) } return nil } @@ -158,10 +159,11 @@ func (cf *configurer) Configure(userID int, proToken string, refreshProxies bool log.Errorf("Unable to save updated UserConfig with country and allow probes: %v", err) } }() - + globalStart := time.Now() log.Debug("Updating global config") global, globalUpdated = cf.updateGlobal(cf.rt, global, globalEtag, "https://globalconfig.flashlightproxy.com/global.yaml.gz") log.Debug("Updated global config") + log.Debugf("Global config update completed in %v seconds", time.Since(globalStart).Seconds()) if refreshProxies { log.Debug("Refreshing proxies") proxies, proxiesUpdated = cf.updateProxies(proxies, proxiesEtag) @@ -409,7 +411,7 @@ func (cf *configurer) doUpdateFromWeb(rt http.RoundTripper, name string, etag st return bytes, newEtag, nil } -func (cf *configurer) configureFronting(global *config.Global, timeout time.Duration) error { +func (cf *configurer) configureFronting(global *config.Global) error { log.Debug("Configuring fronting") certs, err := global.TrustedCACerts() if err != nil { diff --git a/internalsdk/ios/ios.go b/internalsdk/ios/ios.go index fe7f81037..bb20c6acd 100644 --- a/internalsdk/ios/ios.go +++ b/internalsdk/ios/ios.go @@ -24,8 +24,6 @@ const ( maxDNSGrabAge = 1 * time.Hour // this doesn't need to be long because our fake DNS records have a TTL of only 1 second. We use a smaller value than on Android to be conservative with memory usag. quotaSaveInterval = 1 * time.Minute - shortFrontedAvailableTimeout = 30 * time.Second - longFrontedAvailableTimeout = 5 * time.Minute logMemoryInterval = 5 * time.Second forceGCInterval = 250 * time.Millisecond diff --git a/internalsdk/pro/pro.go b/internalsdk/pro/pro.go index 41b5d6dc6..161757554 100644 --- a/internalsdk/pro/pro.go +++ b/internalsdk/pro/pro.go @@ -73,7 +73,7 @@ func NewClient(baseURL string, userConfig func() common.UserConfig) ProClient { if common.Platform == "ios" { //For iOS use fronted proxy chined proxy does not work with iOS at the moment httpClient = &http.Client{ - Transport: proxied.Fronted(""), + Transport: proxied.Fronted("proclient-ios"), Timeout: 30 * time.Second, } } else { diff --git a/internalsdk/session_model.go b/internalsdk/session_model.go index 32953b16f..5dd29acaa 100644 --- a/internalsdk/session_model.go +++ b/internalsdk/session_model.go @@ -208,7 +208,7 @@ func (m *SessionModel) setupIosConfigure(configPath string, userId int, token st return } m.iosConfigurer = global - log.Debugf("Found global config IOS configure done %v", global) + log.Debug("Found global config IOS configure done") return // Exit the loop after success } log.Debugf("global config not available, retrying...") diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index 020ee8573..ce57be39f 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -21,11 +21,15 @@ import UIKit private var lanternModel: LanternModel! private var vpnModel: VpnModel! private var messagingModel: MessagingModel! + private var vpnHelper: VpnHelper! override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { + + // Init VPn helper as soon we can so it will start config methods on go + initializeFlutterComponents() try! setupModels() try! setupAppComponents() @@ -61,9 +65,17 @@ import UIKit } lanternModel = LanternModel(flutterBinary: self.flutterbinaryMessenger) sessionModel = try SessionModel(flutterBinary: self.flutterbinaryMessenger) + vpnHelper = VpnHelper( + constants: Constants(process: .app), + fileManager: .default, + userDefaults: Constants.appGroupDefaults, + notificationCenter: .default, + flashlightManager: FlashlightManager.appDefault, + vpnManager: (isSimulator() ? MockVPNManager() : VPNManager.appDefault)) + vpnModel = try VpnModel( flutterBinary: self.flutterbinaryMessenger, vpnBase: VPNManager.appDefault, - sessionModel: sessionModel) + sessionModel: sessionModel, vpnHelper: vpnHelper) messagingModel = try MessagingModel(flutterBinary: flutterbinaryMessenger) } diff --git a/ios/Runner/Lantern/Core/Vpn/VPNManager.swift b/ios/Runner/Lantern/Core/Vpn/VPNManager.swift index 7f4efdc6c..5d163b899 100644 --- a/ios/Runner/Lantern/Core/Vpn/VPNManager.swift +++ b/ios/Runner/Lantern/Core/Vpn/VPNManager.swift @@ -190,11 +190,11 @@ class VPNManager: VPNBase { _ completion: @escaping (Result) -> Void ) { provider.saveToPreferences { saveError in - if let _ = saveError { + if saveError != nil { completion(.failure(.savingProviderFailed)) } else { provider.loadFromPreferences { loadError in - if let _ = loadError { + if loadError != nil { completion(.failure(.loadingProviderFailed)) } else { completion(.success(())) diff --git a/ios/Runner/Lantern/Core/Vpn/VpnHelper.swift b/ios/Runner/Lantern/Core/Vpn/VpnHelper.swift index b1566a31d..b25bd49e1 100644 --- a/ios/Runner/Lantern/Core/Vpn/VpnHelper.swift +++ b/ios/Runner/Lantern/Core/Vpn/VpnHelper.swift @@ -10,13 +10,7 @@ import UIKit import UserNotifications class VpnHelper: NSObject { - static let shared = VpnHelper( - constants: Constants(process: .app), - fileManager: .default, - userDefaults: Constants.appGroupDefaults, - notificationCenter: .default, - flashlightManager: FlashlightManager.appDefault, - vpnManager: (isSimulator() ? MockVPNManager() : VPNManager.appDefault)) + // MARK: State static let didUpdateStateNotification = Notification.Name("Lantern.didUpdateState") enum VPNState: Equatable { diff --git a/ios/Runner/Lantern/Models/VpnModel.swift b/ios/Runner/Lantern/Models/VpnModel.swift index 5faf5ab97..1aefd7d9d 100644 --- a/ios/Runner/Lantern/Models/VpnModel.swift +++ b/ios/Runner/Lantern/Models/VpnModel.swift @@ -10,10 +10,13 @@ import Sentry class VpnModel: BaseModel, InternalsdkVPNManagerProtocol { let vpnManager: VPNBase - let vpnHelper = VpnHelper.shared + let vpnHelper: VpnHelper var sessionModel: SessionModel! - init(flutterBinary: FlutterBinaryMessenger, vpnBase: VPNBase, sessionModel: SessionModel) throws { + init( + flutterBinary: FlutterBinaryMessenger, vpnBase: VPNBase, sessionModel: SessionModel, + vpnHelper: VpnHelper + ) throws { logger.log("Initializing VPNModel") self.vpnManager = vpnBase var error: NSError? @@ -23,6 +26,7 @@ class VpnModel: BaseModel, InternalsdkVPNManagerProtocol { throw error! } self.sessionModel = sessionModel + self.vpnHelper = vpnHelper try super.init(flutterBinary, model) model.setManager(self) diff --git a/ios/Runner/Lantern/Utils/RunningEnv.swift b/ios/Runner/Lantern/Utils/RunningEnv.swift index e766bb258..2c9a7e382 100644 --- a/ios/Runner/Lantern/Utils/RunningEnv.swift +++ b/ios/Runner/Lantern/Utils/RunningEnv.swift @@ -30,7 +30,7 @@ func isRunningInTestFlightEnvironment() -> Bool { } private func hasEmbeddedMobileProvision() -> Bool { - if let _ = Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") { + if Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") != nil { return true } return false From ddf6a6504b2737a1e699aec067caa634b9c4089c Mon Sep 17 00:00:00 2001 From: Jigar-f Date: Tue, 17 Dec 2024 17:46:39 +0530 Subject: [PATCH 2/2] Update AppDelegate.swift --- ios/Runner/AppDelegate.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index ce57be39f..90027e713 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -27,9 +27,6 @@ import UIKit _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { - - // Init VPn helper as soon we can so it will start config methods on go - initializeFlutterComponents() try! setupModels() try! setupAppComponents()