Skip to content

Commit

Permalink
merge latest
Browse files Browse the repository at this point in the history
  • Loading branch information
atavism committed Dec 19, 2024
2 parents 674fb36 + ddf6a65 commit 054f62c
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion internalsdk/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 8 additions & 6 deletions internalsdk/ios/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions internalsdk/ios/ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internalsdk/pro/pro.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internalsdk/session_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand Down
11 changes: 10 additions & 1 deletion ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import UIKit
private var lanternModel: LanternModel!
private var vpnModel: VpnModel!
private var messagingModel: MessagingModel!
private var vpnHelper: VpnHelper!

override func application(
_ application: UIApplication,
Expand Down Expand Up @@ -61,9 +62,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)
}

Expand Down
4 changes: 2 additions & 2 deletions ios/Runner/Lantern/Core/Vpn/VPNManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ class VPNManager: VPNBase {
_ completion: @escaping (Result<Void, VPNManagerError>) -> 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(()))
Expand Down
8 changes: 1 addition & 7 deletions ios/Runner/Lantern/Core/Vpn/VpnHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions ios/Runner/Lantern/Models/VpnModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import Sentry

class VpnModel: BaseModel<InternalsdkVPNModel>, 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?
Expand All @@ -23,6 +26,7 @@ class VpnModel: BaseModel<InternalsdkVPNModel>, InternalsdkVPNManagerProtocol {
throw error!
}
self.sessionModel = sessionModel
self.vpnHelper = vpnHelper
try super.init(flutterBinary, model)
model.setManager(self)

Expand Down
2 changes: 1 addition & 1 deletion ios/Runner/Lantern/Utils/RunningEnv.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 054f62c

Please sign in to comment.