Skip to content

Commit

Permalink
Pro HTTP client updates (#1033)
Browse files Browse the repository at this point in the history
* do not pass initialize flag when running Lantern

* do not pass initialize flag when running Lantern

* remove tray manager references in vpn switch widget

* remove tray manager references in vpn switch widget

* use windows webview

* update windows webview

* update windows webview

* windows webview updates

* windows webview updates

* windows webview updates

* updates to use flutter_windows_webview

* update CI branch

* use wgh136/flutter_windows_webview

* use subosito/flutter-action v2.12.0

* use subosito/flutter-action v2.12.0

* use subosito/flutter-action v2.12.0

* Add expectedMonthlyPrice to plan json

* update branch name

* update planfromJson

* use cannot_sign_in instead of cannot_login

* fix issue with blank pro account screen

* Add devices and expiryDate

* update branch name

* Add report_description

* Add report_description

* save email address and pass currency to paymentRedirect

* dart format

* use switch statement for desktop os opening webview

* initial commit - new go-resty based pro http client

* pro client updates

* pro client updates

* pro client updates

* use PostFormReadingJSON in LinkCodeRequest

* pro client updates

* pro client updates

* update flashlight, remove unused

* update SendToURL

* move settings to separate package

* reorder imports

* update user is pro check

* use ubuntu-latest for now

* add websocket service

* add websocket service

* clean-ups, add comments

* apply formatting

* Added socket to account menu and

* set Localization.locale when language is changed on desktop

* updates to use didChangeAppLifecycleState

* updates to init websocket when app starts

* clean-ups, add comments

* updates to websocket service

* remove websocket changes to account menu

* apply formatting

* refresh user data when home page is loaded

* remove redundant methods

* update onTrayMenuItemClick

* clean-ups, do not fetch user data when checking email address

* merge latest

* update flashlight

* clean-ups

* Add TestClient

* export EmptySettings

* rename base api response

* update errors package

* Update how goveralls is installed

* Add changes lost prior to merge

* Fix issue with plans and payment redirect responses

* fix typo

* Add GO111MODULE: off when installing goveralls

* Update import list

* GO111MODULE auto when installing goveralls

* Fixed issue on incorrect endpoint on redeemResellerCode and fixed error handling.

* make pro client more generic, remove desktop settings

* make pro client more generic, remove desktop settings

* remove duplicate line

* update pro client test

* Update PostJSONReadingJSON to allow specifying query parameters

* update ios code to use new pro client

* update flashlight

* update flashlight to v7.6.73

---------

Co-authored-by: Jigar-f <[email protected]>
  • Loading branch information
atavism and jigar-f authored Apr 18, 2024
1 parent 22f0dc9 commit 9713030
Show file tree
Hide file tree
Showing 38 changed files with 2,445 additions and 675 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
go test -failfast -coverprofile=profile.cov ./...
- name: Install goveralls
env:
GO111MODULE: off
run: go get github.com/mattn/goveralls
GO111MODULE: auto
run: go install github.com/mattn/goveralls@latest
- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish releases

on:
push:
branches: [ main ]
branches: [ atavism/pro-client-updates ]
tags:
- '*'

Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ INTERNALSDK_FRAMEWORK_NAME = Internalsdk.xcframework
codegen: protos routes

# You can install the dart protoc support by running 'dart pub global activate protoc_plugin'
protos: lib/vpn/protos_shared/vpn.pb.dart
protos: lib/vpn/protos_shared/vpn.pb.dart internalsdk/protos/vpn.pb.go

lib/messaging/protos_flutteronly/messaging.pb.dart: protos_flutteronly/messaging.proto
@protoc --dart_out=./lib/messaging --plugin=protoc-gen-dart=$$HOME/.pub-cache/bin/protoc-gen-dart protos_flutteronly/messaging.proto

lib/vpn/protos_shared/vpn.pb.dart: protos_shared/vpn.proto
@protoc --dart_out=./lib/vpn --plugin=protoc-gen-dart=$$HOME/.pub-cache/bin/protoc-gen-dart protos_shared/vpn.proto

#internalsdk/protos/%.pb.go: protos_shared/%.proto
# @echo "Generating Go protobuf for $<"
# @protoc --plugin=protoc-gen-go=build/protoc-gen-go \
# --go_out=internalsdk \
# $<
internalsdk/protos/%.pb.go: protos_shared/%.proto
@echo "Generating Go protobuf for $<"
@protoc --plugin=protoc-gen-go=build/protoc-gen-go \
--go_out=internalsdk \
$<

internalsdk/protos/vpn.pb.go: protos_shared/vpn.proto
@protoc --go_out=internalsdk protos_shared/vpn.proto
Expand Down
58 changes: 30 additions & 28 deletions desktop/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import (
"github.com/getlantern/flashlight/v7/logging"
"github.com/getlantern/flashlight/v7/ops"
"github.com/getlantern/flashlight/v7/otel"
"github.com/getlantern/flashlight/v7/pro"
"github.com/getlantern/flashlight/v7/pro/client"
"github.com/getlantern/flashlight/v7/stats"
"github.com/getlantern/golog"
"github.com/getlantern/i18n"
Expand All @@ -45,7 +43,9 @@ import (
uicommon "github.com/getlantern/lantern-client/desktop/common"
"github.com/getlantern/lantern-client/desktop/features"
"github.com/getlantern/lantern-client/desktop/notifier"
"github.com/getlantern/lantern-client/desktop/settings"
"github.com/getlantern/lantern-client/desktop/ws"
proclient "github.com/getlantern/lantern-client/internalsdk/pro"
)

var (
Expand All @@ -71,7 +71,7 @@ type App struct {
configDir string
exited eventual.Value
analyticsSession analytics.Session
settings *Settings
settings *settings.Settings
statsTracker *statsTracker

muExitFuncs sync.RWMutex
Expand Down Expand Up @@ -101,7 +101,7 @@ type App struct {
proxiesLock sync.RWMutex

issueReporter *issueReporter
proClient *client.Client
proClient proclient.ProClient
referralCode string
selectedTab Tab
stats *stats.Stats
Expand All @@ -117,7 +117,7 @@ type App struct {
}

// NewApp creates a new desktop app that initializes the app and acts as a moderator between all desktop components.
func NewApp(flags flashlight.Flags, configDir string, proClient *client.Client, settings *Settings) *App {
func NewApp(flags flashlight.Flags, configDir string, proClient proclient.ProClient, settings *settings.Settings) *App {
analyticsSession := newAnalyticsSession(settings)
app := &App{
configDir: configDir,
Expand All @@ -135,19 +135,19 @@ func NewApp(flags flashlight.Flags, configDir string, proClient *client.Client,
golog.OnFatal(app.exitOnFatal)

app.AddExitFunc("stopping analytics", app.analyticsSession.End)
pro.OnProStatusChange(func(isPro bool, _ bool) {
onProStatusChange(func(isPro bool) {
app.statsTracker.SetIsPro(isPro)
})

log.Debugf("Using configdir: %v", configDir)

app.issueReporter = newIssueReporter(app.settings, app.getCapturedPackets, app.getProxies)
app.issueReporter = newIssueReporter(app)
app.translations.Set(os.DirFS("locale/translation"))

return app
}

func newAnalyticsSession(settings *Settings) analytics.Session {
func newAnalyticsSession(settings *settings.Settings) analytics.Session {
if settings.IsAutoReport() {
session := analytics.Start(settings.GetDeviceID(), ApplicationVersion)
go func() {
Expand Down Expand Up @@ -194,15 +194,15 @@ func (app *App) Run(isMain bool) {

listenAddr := app.Flags.Addr
if listenAddr == "" {
listenAddr = app.settings.getString(SNAddr)
listenAddr = app.settings.GetAddr()
}
if listenAddr == "" {
listenAddr = defaultHTTPProxyAddress
}

socksAddr := app.Flags.SocksAddr
if socksAddr == "" {
socksAddr = app.settings.getString(SNSOCKSAddr)
socksAddr = app.settings.GetSOCKSAddr()
}
if socksAddr == "" {
socksAddr = defaultSOCKSProxyAddress
Expand Down Expand Up @@ -239,7 +239,7 @@ func (app *App) Run(isMain bool) {
RevisionDate,
app.configDir,
app.Flags.VPN,
func() bool { return app.settings.getBool(SNDisconnected) }, // check whether we're disconnected
func() bool { return app.settings.GetDisconnected() }, // check whether we're disconnected
app.settings.GetProxyAll,
func() bool { return false }, // on desktop, we do not allow private hosts
app.settings.IsAutoReport,
Expand All @@ -260,11 +260,11 @@ func (app *App) Run(isMain bool) {
app.beforeStart(listenAddr)

chProStatusChanged := make(chan bool, 1)
pro.OnProStatusChange(func(isPro bool, _ bool) {
onProStatusChange(func(isPro bool) {
chProStatusChanged <- isPro
})
chUserChanged := make(chan bool, 1)
app.settings.OnChange(SNUserID, func(v interface{}) {
app.settings.OnChange(settings.SNUserID, func(v interface{}) {
chUserChanged <- true
})
app.startFeaturesService(geolookup.OnRefresh(), chUserChanged, chProStatusChanged, app.chGlobalConfigChanged)
Expand Down Expand Up @@ -364,9 +364,10 @@ func (app *App) beforeStart(listenAddr string) {
app.Exit(nil)
os.Exit(0)
}
app.AddExitFunc("stopping loconf scanner", LoconfScanner(app.settings, app.configDir, 4*time.Hour, app.IsProUser, func() string {
return app.AddToken("/img/lantern_logo.png")
}))
app.AddExitFunc("stopping loconf scanner", LoconfScanner(app.settings, app.configDir, 4*time.Hour,
func() (bool, bool) { return app.IsProUser(context.Background()) }, func() string {
return app.AddToken("/img/lantern_logo.png")
}))
app.AddExitFunc("stopping notifier", notifier.NotificationsLoop(app.analyticsSession))
}

Expand All @@ -379,14 +380,14 @@ func (app *App) isFeatureEnabled(features map[string]bool, feature string) bool
func (app *App) Connect() {
app.analyticsSession.Event("systray-menu", "connect")
ops.Begin("connect").End()
app.settings.setBool(SNDisconnected, false)
app.settings.SetDisconnected(false)
}

// Disconnect turns off proxying
func (app *App) Disconnect() {
app.analyticsSession.Event("systray-menu", "disconnect")
ops.Begin("disconnect").End()
app.settings.setBool(SNDisconnected, true)
app.settings.SetDisconnected(true)
}

// GetLanguage returns the user language
Expand All @@ -407,7 +408,7 @@ func (app *App) SetLanguage(lang string) {

// OnSettingChange sets a callback cb to get called when attr is changed from server.
// When calling multiple times for same attr, only the last one takes effect.
func (app *App) OnSettingChange(attr SettingName, cb func(interface{})) {
func (app *App) OnSettingChange(attr settings.SettingName, cb func(interface{})) {
app.settings.OnChange(attr, cb)
}

Expand All @@ -417,7 +418,7 @@ func (app *App) OnStatsChange(fn func(stats.Stats)) {
}

func (app *App) afterStart(cl *flashlightClient.Client) {
app.OnSettingChange(SNSystemProxy, func(val interface{}) {
app.OnSettingChange(settings.SNSystemProxy, func(val interface{}) {
enable := val.(bool)
if enable {
app.SysproxyOn()
Expand All @@ -431,12 +432,12 @@ func (app *App) afterStart(cl *flashlightClient.Client) {
})
app.AddExitFunc("flushing to opentelemetry", otel.Stop)
if addr, ok := flashlightClient.Addr(6 * time.Second); ok {
app.settings.setString(SNAddr, addr)
app.settings.SetAddr(addr.(string))
} else {
log.Errorf("Couldn't retrieve HTTP proxy addr in time")
}
if socksAddr, ok := flashlightClient.Socks5Addr(6 * time.Second); ok {
app.settings.setString(SNSOCKSAddr, socksAddr)
app.settings.SetSOCKSAddr(socksAddr.(string))
} else {
log.Errorf("Couldn't retrieve SOCKS proxy addr in time")
}
Expand Down Expand Up @@ -601,20 +602,21 @@ func (app *App) exitOnFatal(err error) {

// IsPro indicates whether or not the app is pro
func (app *App) IsPro() bool {
isPro, _ := app.isProUserFast()
isPro, _ := app.isProUserFast(context.Background())
return isPro
}

// ReferralCode returns a user's unique referral code
func (app *App) ReferralCode(uc common.UserConfig) (string, error) {
referralCode := app.referralCode
if referralCode == "" {
resp, err := app.proClient.UserData(uc)
resp, err := app.proClient.UserData(context.Background())
if err != nil {
return "", err
return "", errors.New("error fetching user data: %v", err)
}
app.SetReferralCode(resp.Code)
return resp.Code, nil

app.SetReferralCode(resp.User.Code)
return resp.User.Code, nil
}
return referralCode, nil
}
Expand Down Expand Up @@ -678,7 +680,7 @@ func (app *App) AddToken(path string) string {
return path
}

func (app *App) Settings() *Settings {
func (app *App) Settings() *settings.Settings {
return app.settings
}

Expand Down
6 changes: 4 additions & 2 deletions desktop/app/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package app
import (
"crypto/rand"
"encoding/hex"

"github.com/getlantern/lantern-client/desktop/settings"
)

const (
Expand All @@ -23,12 +25,12 @@ func randRead(size int) string {

// localHTTPToken fetches the local HTTP token from disk if it's there, and
// otherwise creates a new one and stores it.
func localHTTPToken(set *Settings) string {
func localHTTPToken(set *settings.Settings) string {
tok := set.GetLocalHTTPToken()
if tok == "" {
t := randRead(16)
set.SetLocalHTTPToken(t)
return t
}
return tok
}
}
22 changes: 13 additions & 9 deletions desktop/app/issue.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package app

import (
"context"
"io"
"math"
"strconv"

"github.com/getlantern/lantern-client/desktop/settings"
"github.com/getlantern/lantern-client/internalsdk/pro"

"github.com/getlantern/flashlight/v7/bandit"
"github.com/getlantern/flashlight/v7/common"
"github.com/getlantern/flashlight/v7/issue"
"github.com/getlantern/flashlight/v7/pro"

"github.com/getlantern/flashlight/v7/util"
"github.com/getlantern/osversion"
)
Expand All @@ -23,9 +25,10 @@ var (
)

type issueReporter struct {
settings *Settings
settings *settings.Settings
getCapturedPackets func(io.Writer) error
getProxies func() []bandit.Dialer
proClient pro.ProClient
}

type issueMessage struct {
Expand All @@ -44,12 +47,12 @@ type issueMessage struct {

// newIssueReporter creates a new issue reporter that can be used to send issue reports
// to the Lantern team.
func newIssueReporter(settings *Settings, getCapturedPackets func(io.Writer) error,
getProxies func() []bandit.Dialer) *issueReporter {
func newIssueReporter(app *App) *issueReporter {
return &issueReporter{
settings: settings,
getCapturedPackets: getCapturedPackets,
getProxies: getProxies,
getCapturedPackets: app.getCapturedPackets,
getProxies: app.getProxies,
proClient: app.proClient,
settings: app.settings,
}
}

Expand Down Expand Up @@ -80,7 +83,8 @@ func (reporter *issueReporter) sendIssueReport(msg *issueMessage) error {
return err
}
subscriptionLevel := "free"
if isPro, _ := pro.IsProUser(settings); isPro {
ctx := context.Background()
if isPro, _ := IsProUser(ctx, reporter.proClient, settings.GetUserID()); isPro {
subscriptionLevel = "pro"
}
var osVersion string
Expand Down
9 changes: 5 additions & 4 deletions desktop/app/loconfscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/getlantern/lantern-client/desktop/loconf"
"github.com/getlantern/lantern-client/desktop/notifier"
"github.com/getlantern/lantern-client/desktop/settings"
)

// LoconfScanner starts a goroutine to periodically check for new loconf files.
Expand All @@ -27,7 +28,7 @@ import (
// show the announcement or not).
//
// Returns a function to stop the loop.
func LoconfScanner(settings *Settings, configDir string, interval time.Duration, proChecker func() (bool, bool), iconURL func() string) (stop func()) {
func LoconfScanner(settings *settings.Settings, configDir string, interval time.Duration, proChecker func() (bool, bool), iconURL func() string) (stop func()) {
loc := &loconfer{
log: golog.LoggerFor("loconfer"),
configDir: configDir,
Expand Down Expand Up @@ -86,7 +87,7 @@ type loconfer struct {
configDir string
r *rand.Rand
iconURL func() string
settings *Settings
settings *settings.Settings
}

func (loc *loconfer) onLoconf(lc *loconf.LoConf, isPro bool) {
Expand Down Expand Up @@ -139,14 +140,14 @@ func (loc *loconfer) makeAnnouncements(lc *loconf.LoConf, isPro bool) {
}
return
}
past := loc.settings.getStringArray(SNPastAnnouncements)
past := loc.settings.GetPastAnnouncements()
if in(current.Campaign, past) {
loc.log.Debugf("Skip announcement %s", current.Campaign)
return
}
if loc.showAnnouncement(current) {
past = append(past, current.Campaign)
loc.settings.setStringArray(SNPastAnnouncements, past)
loc.settings.SetPastAnnouncements(past)
}
}

Expand Down
Loading

0 comments on commit 9713030

Please sign in to comment.