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

Pro HTTP client updates #1033

Merged
merged 95 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
6b001ea
do not pass initialize flag when running Lantern
atavism Mar 18, 2024
39a1e39
do not pass initialize flag when running Lantern
atavism Mar 18, 2024
99ee35a
remove tray manager references in vpn switch widget
atavism Mar 18, 2024
1d0b91b
remove tray manager references in vpn switch widget
atavism Mar 18, 2024
e07e011
use windows webview
atavism Mar 18, 2024
c775cc9
update windows webview
atavism Mar 18, 2024
d808196
update windows webview
atavism Mar 18, 2024
289604c
windows webview updates
atavism Mar 18, 2024
368cc36
windows webview updates
atavism Mar 18, 2024
312c0cf
windows webview updates
atavism Mar 18, 2024
ca8e7b7
updates to use flutter_windows_webview
atavism Mar 18, 2024
1ba4262
update CI branch
atavism Mar 18, 2024
fbb4d98
merge latest
atavism Mar 19, 2024
a2335d1
use wgh136/flutter_windows_webview
atavism Mar 19, 2024
482b153
use subosito/flutter-action v2.12.0
atavism Mar 19, 2024
d6943f4
use subosito/flutter-action v2.12.0
atavism Mar 19, 2024
219991a
use subosito/flutter-action v2.12.0
atavism Mar 19, 2024
79a6b19
merge latest
atavism Mar 19, 2024
50f269d
Add expectedMonthlyPrice to plan json
atavism Mar 19, 2024
4d10af0
update branch name
atavism Mar 19, 2024
a56f3ed
update planfromJson
atavism Mar 19, 2024
7c6f2da
use cannot_sign_in instead of cannot_login
atavism Mar 19, 2024
6123581
fix issue with blank pro account screen
atavism Mar 19, 2024
084871d
Add devices and expiryDate
atavism Mar 19, 2024
117001e
update branch name
atavism Mar 19, 2024
8558285
Add report_description
atavism Mar 19, 2024
a1dba70
Add report_description
atavism Mar 19, 2024
2620791
save email address and pass currency to paymentRedirect
atavism Mar 20, 2024
322da45
dart format
atavism Mar 20, 2024
7babd06
merge latest
atavism Mar 20, 2024
ef82f53
use switch statement for desktop os opening webview
atavism Mar 20, 2024
302149d
initial commit - new go-resty based pro http client
atavism Mar 20, 2024
1b7b7e8
pro client updates
atavism Mar 20, 2024
92831b3
pro client updates
atavism Mar 20, 2024
6fddc63
pro client updates
atavism Mar 20, 2024
c0741b0
use PostFormReadingJSON in LinkCodeRequest
atavism Mar 20, 2024
e2c1cec
pro client updates
atavism Mar 20, 2024
52ceaaf
pro client updates
atavism Mar 20, 2024
7954d9c
update flashlight, remove unused
atavism Mar 20, 2024
6fc5340
update SendToURL
atavism Mar 20, 2024
ef0ad4c
move settings to separate package
atavism Mar 20, 2024
22b7fdc
reorder imports
atavism Mar 21, 2024
82909d8
update user is pro check
atavism Mar 21, 2024
d6b24f0
Merge branch 'atavism/pro-account-screen' into atavism/pro-client-upd…
atavism Mar 21, 2024
faf831e
use ubuntu-latest for now
atavism Mar 21, 2024
961b1ed
add websocket service
atavism Mar 21, 2024
d5d72fc
add websocket service
atavism Mar 21, 2024
c00ced4
clean-ups, add comments
atavism Mar 21, 2024
7d43b8f
apply formatting
atavism Mar 21, 2024
e7f1626
Merge branch 'atavism/pro-account-screen' into atavism/pro-client-upd…
atavism Mar 21, 2024
c901d47
Added socket to account menu and
jigar-f Mar 22, 2024
f02bf67
set Localization.locale when language is changed on desktop
atavism Mar 23, 2024
5f34ebc
updates to use didChangeAppLifecycleState
atavism Mar 24, 2024
81b5066
updates to init websocket when app starts
atavism Mar 24, 2024
39d67a9
clean-ups, add comments
atavism Mar 24, 2024
8fcdc92
updates to websocket service
atavism Mar 24, 2024
908f9d6
merge latest
atavism Mar 24, 2024
f0d03de
remove websocket changes to account menu
atavism Mar 24, 2024
a8d3a1a
apply formatting
atavism Mar 24, 2024
3cd60c5
refresh user data when home page is loaded
atavism Mar 24, 2024
3f10436
remove redundant methods
atavism Mar 25, 2024
3f012fa
update onTrayMenuItemClick
atavism Mar 25, 2024
5e74caf
Merge branch 'atavism/pro-account-screen' into atavism/pro-client-upd…
atavism Mar 25, 2024
b9b7b67
clean-ups, do not fetch user data when checking email address
atavism Mar 25, 2024
5448195
merge latest
atavism Mar 25, 2024
e303048
merge latest
atavism Mar 25, 2024
50afaa2
merge latest
atavism Apr 1, 2024
0418157
update flashlight
atavism Apr 1, 2024
dfc9728
clean-ups
atavism Apr 1, 2024
954c123
Add TestClient
atavism Apr 1, 2024
7c51aa6
export EmptySettings
atavism Apr 1, 2024
cc822bc
merge latest
atavism Apr 1, 2024
a50e4aa
pro client updates, merge latest
atavism Apr 8, 2024
e0256af
rename base api response
atavism Apr 8, 2024
041e933
Merge remote-tracking branch 'origin/main' into atavism/pro-client-up…
atavism Apr 9, 2024
4450aa2
Merge remote-tracking branch 'origin/main' into atavism/pro-client-up…
atavism Apr 10, 2024
31a337b
update errors package
atavism Apr 10, 2024
bba9bb3
Update how goveralls is installed
atavism Apr 10, 2024
85689b7
merge latest
atavism Apr 15, 2024
156b847
Add changes lost prior to merge
atavism Apr 15, 2024
29709c9
Fix issue with plans and payment redirect responses
atavism Apr 18, 2024
9a803a0
fix typo
atavism Apr 18, 2024
4587ade
Add GO111MODULE: off when installing goveralls
atavism Apr 18, 2024
9d415d7
Update import list
atavism Apr 18, 2024
fd5252a
GO111MODULE auto when installing goveralls
atavism Apr 18, 2024
9107e35
Fixed issue on incorrect endpoint on redeemResellerCode and fixed err…
jigar-f Apr 18, 2024
1c62818
make pro client more generic, remove desktop settings
atavism Apr 18, 2024
23f7623
make pro client more generic, remove desktop settings
atavism Apr 18, 2024
f16659d
Merge branch 'atavism/pro-client-updates' of github.com:getlantern/la…
atavism Apr 18, 2024
d8021df
remove duplicate line
atavism Apr 18, 2024
75a5ae8
update pro client test
atavism Apr 18, 2024
b87fded
Update PostJSONReadingJSON to allow specifying query parameters
atavism Apr 18, 2024
18f3955
update ios code to use new pro client
atavism Apr 18, 2024
51c78b9
update flashlight
atavism Apr 18, 2024
340c3d0
update flashlight to v7.6.73
atavism Apr 18, 2024
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
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
Loading