From 9b8c790352e51fa659f1b376e16e4cec8fd30fb0 Mon Sep 17 00:00:00 2001 From: Jigar-f Date: Wed, 4 Dec 2024 14:51:59 +0530 Subject: [PATCH 1/3] Map stats tracker with ios. --- internalsdk/ios/ios.go | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/internalsdk/ios/ios.go b/internalsdk/ios/ios.go index 3faab417a..7739af84c 100644 --- a/internalsdk/ios/ios.go +++ b/internalsdk/ios/ios.go @@ -218,20 +218,25 @@ func (c *iosClient) start() (ClientWriter, error) { tracker := stats.NewTracker() dialer := dialer.New(&dialer.Options{ Dialers: dialers, + OnSuccess: func(pd dialer.ProxyDialer) { + tracker.SetHasSucceedingProxy(true) + countryCode, country, city := pd.Location() + previousStats := tracker.Latest() + if previousStats.CountryCode == "" || previousStats.CountryCode != countryCode { + tracker.SetActiveProxyLocation( + city, + country, + countryCode, + ) + } + }, }) if err != nil { return nil, err } - go func() { - tracker.AddListener(func(st stats.Stats) { - if st.City != "" && st.Country != "" && st.CountryCode != "" { - start := time.Now() - log.Debugf("Stats update at %v", start) - c.statsTracker.UpdateStats(st.City, st.Country, st.CountryCode, st.HTTPSUpgrades, st.AdsBlocked, st.HasSucceedingProxy) - } - }) - }() + // get stats updates + go c.statsTrackerUpdates(tracker) // get bandwidth updates go bandwidthUpdates(c.bandwidthTracker) @@ -280,7 +285,14 @@ func bandwidthUpdates(bt BandwidthTracker) { } }() } - +func (c *iosClient) statsTrackerUpdates(tracker stats.Tracker) { + tracker.AddListener(func(st stats.Stats) { + if st.City != "" && st.Country != "" && st.CountryCode != "" { + log.Debug("updating stats") + c.statsTracker.UpdateStats(st.City, st.Country, st.CountryCode, st.HTTPSUpgrades, st.AdsBlocked, st.HasSucceedingProxy) + } + }) +} func getBandwidth(quota *bandwidth.Quota) (int, int, int) { remaining := 0 percent := 100 From 787fb4e3d38c3b85f0c3f488d7c5231ba9f92c29 Mon Sep 17 00:00:00 2001 From: Jigar-f Date: Wed, 4 Dec 2024 15:11:25 +0530 Subject: [PATCH 2/3] fix bandwidth issue on ios. --- Makefile | 2 +- internalsdk/ios/ios.go | 19 +++++++++++++------ ios/Tunnel/BandwidthTracker.swift | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index e627dd0ea..f2b2ebed2 100644 --- a/Makefile +++ b/Makefile @@ -690,7 +690,7 @@ sourcedump: require-version find vendor/github.com/getlantern -name LICENSE -exec rm {} \; && \ tar -czf $$here/lantern-android-sources-$$VERSION.tar.gz . -build-framework: assert-go-version install-gomobile +ios: assert-go-version install-gomobile @echo "Nuking $(INTERNALSDK_FRAMEWORK_DIR) and $(MINISQL_FRAMEWORK_DIR)" rm -Rf $(INTERNALSDK_FRAMEWORK_DIR) $(MINISQL_FRAMEWORK_DIR) @echo "generating Ios.xcFramework" diff --git a/internalsdk/ios/ios.go b/internalsdk/ios/ios.go index 7739af84c..b08641f16 100644 --- a/internalsdk/ios/ios.go +++ b/internalsdk/ios/ios.go @@ -114,12 +114,11 @@ type BandwidthTracker interface { } type cw struct { - ipStack io.WriteCloser - client *iosClient - dialer dialer.Dialer - ipp ipproxy.Proxy - quotaTextPath string - lastSavedQuota time.Time + ipStack io.WriteCloser + client *iosClient + dialer dialer.Dialer + ipp ipproxy.Proxy + quotaTextPath string } func (c *cw) Write(b []byte) (int, error) { @@ -279,6 +278,14 @@ func (c *iosClient) start() (ClientWriter, error) { func bandwidthUpdates(bt BandwidthTracker) { go func() { + + quota, _ := bandwidth.GetQuota() + if quota == nil { + // quota is nil, so then we are uncapped + bt.BandwidthUpdate("", 0, 0, 0, int(quota.TTLSeconds)) + return + } + for quota := range bandwidth.Updates { percent, remaining, allowed := getBandwidth(quota) bt.BandwidthUpdate("", percent, remaining, allowed, int(quota.TTLSeconds)) diff --git a/ios/Tunnel/BandwidthTracker.swift b/ios/Tunnel/BandwidthTracker.swift index e6211e682..c0dbe33ee 100644 --- a/ios/Tunnel/BandwidthTracker.swift +++ b/ios/Tunnel/BandwidthTracker.swift @@ -17,8 +17,8 @@ class BandwidthTracker: NSObject, IosBandwidthTrackerProtocol { //Save data coming from server let dataDict: [String: Any] = [ "percent": p1, - "remaining": p2, - "allowed": p3, + "mibUsed": p2, + "mibAllowed": p3, "ttlSeconds": p4, ] do { From 448c595aed42be959dd0a97634be6ca41b4523fc Mon Sep 17 00:00:00 2001 From: Jigar-f Date: Wed, 4 Dec 2024 18:44:10 +0530 Subject: [PATCH 3/3] update ios.go --- desktop/app/app.go | 1 + internalsdk/ios/ios.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/desktop/app/app.go b/desktop/app/app.go index ee6d7c9f0..1a66672e0 100644 --- a/desktop/app/app.go +++ b/desktop/app/app.go @@ -169,6 +169,7 @@ func (app *App) Run(ctx context.Context) { } proClient := proclient.NewClient(fmt.Sprintf("https://%s", common.ProAPIHost), &webclient.Opts{ UserConfig: userConfig, + }) authClient := auth.NewClient(fmt.Sprintf("https://%s", common.DFBaseUrl), userConfig) diff --git a/internalsdk/ios/ios.go b/internalsdk/ios/ios.go index b08641f16..9dffbf9d9 100644 --- a/internalsdk/ios/ios.go +++ b/internalsdk/ios/ios.go @@ -282,7 +282,7 @@ func bandwidthUpdates(bt BandwidthTracker) { quota, _ := bandwidth.GetQuota() if quota == nil { // quota is nil, so then we are uncapped - bt.BandwidthUpdate("", 0, 0, 0, int(quota.TTLSeconds)) + bt.BandwidthUpdate("", 0, 0, 0, 0) return }