Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS updates with new flashlight #1249

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions desktop/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
51 changes: 35 additions & 16 deletions internalsdk/ios/ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -218,20 +217,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)

Expand Down Expand Up @@ -274,13 +278,28 @@ 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, 0)
return
}

for quota := range bandwidth.Updates {
percent, remaining, allowed := getBandwidth(quota)
bt.BandwidthUpdate("", percent, remaining, allowed, int(quota.TTLSeconds))
}
}()
}

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
Expand Down
4 changes: 2 additions & 2 deletions ios/Tunnel/BandwidthTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading