-
Notifications
You must be signed in to change notification settings - Fork 4
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
Invalid header field value for "X-Lantern-Device-Id" #1285
Open
atavism
wants to merge
20
commits into
main
Choose a base branch
from
atavism/updates-device-id
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0f17037
move settings to app package and other improvements
atavism 23f566c
move settings to app package and other improvements
atavism 6a83f26
trim space after reading device ID
atavism be998de
trim space after reading device ID
atavism bfb1aec
further clean-ups
atavism 4407353
further clean-ups
atavism 5dc702b
clean-ups
atavism 418d21d
move settings config files
atavism 8eba4d2
run go mod tidy
atavism bf18d7c
run go mod tidy
atavism 62cb0e2
clean-ups
atavism ece4e44
Fix tests
atavism a62b508
Clean-ups
atavism 527710d
Clean-ups
atavism 2381693
Merge remote-tracking branch 'origin/main' into atavism/updates-devic…
atavism 4e007cf
Fix tests
atavism 4e80e11
Update generated bindings
atavism ed7a472
Add applicationSupportsSecureRestorableState and update generated bin…
atavism 4df1080
Clean-ups
atavism 11571c2
Downgrade go-1.22.4.
jigar-f File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"net" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"sync" | ||
"sync/atomic" | ||
"time" | ||
|
@@ -34,7 +35,6 @@ import ( | |
|
||
"github.com/getlantern/lantern-client/desktop/autoupdate" | ||
"github.com/getlantern/lantern-client/desktop/datacap" | ||
"github.com/getlantern/lantern-client/desktop/settings" | ||
"github.com/getlantern/lantern-client/desktop/ws" | ||
"github.com/getlantern/lantern-client/internalsdk/auth" | ||
"github.com/getlantern/lantern-client/internalsdk/common" | ||
|
@@ -43,7 +43,7 @@ import ( | |
) | ||
|
||
var ( | ||
log = golog.LoggerFor("lantern-desktop.app") | ||
log = golog.LoggerFor("lantern-client.app") | ||
startTime = time.Now() | ||
) | ||
|
||
|
@@ -53,63 +53,75 @@ func init() { | |
|
||
} | ||
|
||
// App is the core of the Lantern desktop application, in the form of a library. | ||
// App is the core of the Lantern desktop application, managing components and configurations. | ||
type App struct { | ||
hasExited atomic.Bool | ||
fetchedGlobalConfig atomic.Bool | ||
fetchedProxiesConfig atomic.Bool | ||
hasSucceedingProxy atomic.Bool | ||
|
||
Flags flashlight.Flags | ||
configDir string | ||
exited eventual.Value | ||
settings *settings.Settings | ||
configService *configService | ||
statsTracker *statsTracker | ||
|
||
muExitFuncs sync.RWMutex | ||
exitFuncs []func() | ||
|
||
translations eventual.Value | ||
|
||
flashlight *flashlight.Flashlight | ||
|
||
authClient auth.AuthClient | ||
proClient proclient.ProClient | ||
|
||
selectedTab Tab | ||
|
||
connectionStatusCallbacks []func(isConnected bool) | ||
|
||
hasExited atomic.Bool // Tracks if the app has exited. | ||
fetchedGlobalConfig atomic.Bool // Indicates if the global configuration was fetched. | ||
fetchedProxiesConfig atomic.Bool // Tracks whether the proxy configuration was fetched. | ||
hasSucceedingProxy atomic.Bool // Tracks if a succeeding proxy is available. | ||
Flags flashlight.Flags // Command-line flags passed to the app. | ||
configDir string // Directory for storing configuration files. | ||
exited eventual.Value // Signals when the app has exited. | ||
settings *Settings // User settings for the application. | ||
configService *configService | ||
statsTracker *statsTracker | ||
muExitFuncs sync.RWMutex | ||
exitFuncs []func() | ||
translations eventual.Value // Translation files for localization. | ||
flashlight *flashlight.Flashlight // Flashlight library for networking and proxying. | ||
authClient auth.AuthClient // Client for managing authentication. | ||
proClient proclient.ProClient // Client for managing interaction with the Pro server. | ||
selectedTab Tab // Tracks the currently selected UI tab. | ||
connectionStatusCallbacks []func(isConnected bool) // Listeners for connection status changes. | ||
// Websocket-related settings | ||
websocketAddr string | ||
ws ws.UIChannel | ||
|
||
cachedUserData sync.Map | ||
|
||
onUserData []func(current *protos.User, new *protos.User) | ||
websocketAddr string // Address for WebSocket connections. | ||
ws ws.UIChannel // UI channel for WebSocket communication. | ||
cachedUserData sync.Map // Cached user data. | ||
onUserData []func(current *protos.User, new *protos.User) // Listeners for user data changes. | ||
|
||
mu sync.RWMutex | ||
} | ||
|
||
// NewApp creates a new desktop app that initializes the app and acts as a moderator between all desktop components. | ||
func NewApp() (*App, error) { | ||
// initialize app config and flags based on environment variables | ||
flags, err := initializeAppConfig() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to initialize app config: %w", err) | ||
flags := flashlight.ParseFlags() | ||
if flags.Pprof { | ||
go startPprof("localhost:6060") | ||
} | ||
|
||
// helper to resolve the configuration directory to an absolute path | ||
resolveConfigDir := func(dir string) string { | ||
if filepath.IsAbs(dir) { | ||
return dir | ||
} | ||
absPath, err := filepath.Abs(dir) | ||
if err != nil { | ||
return dir | ||
} | ||
return absPath | ||
} | ||
|
||
configDir := resolveConfigDir(flags.ConfigDir) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @atavism I think you missed this. We need this unless all files are created in the root of the repo folder.
|
||
|
||
if err := createDirIfNotExists(configDir, defaultConfigDirPerm); err != nil { | ||
return nil, fmt.Errorf("unable to create config directory %s: %v", configDir, err) | ||
} | ||
flags.ConfigDir = configDir | ||
|
||
log.Debugf("Config directory %s sticky %v readable %v", configDir, flags.StickyConfig, flags.ReadableConfig) | ||
return NewAppWithFlags(flags, flags.ConfigDir) | ||
} | ||
|
||
// NewAppWithFlags creates a new instance of App initialized with the given flags and configDir | ||
// NewAppWithFlags creates a new App instance with the given flags and configuration directory. | ||
func NewAppWithFlags(flags flashlight.Flags, configDir string) (*App, error) { | ||
if configDir == "" { | ||
log.Debug("Config directory is empty, using default location") | ||
configDir = appdir.General(common.DefaultAppName) | ||
} | ||
ss := settings.LoadSettings(configDir) | ||
// Load settings and initialize trackers and services. | ||
ss := LoadSettings(configDir) | ||
statsTracker := NewStatsTracker() | ||
|
||
app := &App{ | ||
Flags: flags, | ||
configDir: configDir, | ||
|
@@ -123,6 +135,7 @@ func NewAppWithFlags(flags flashlight.Flags, configDir string) (*App, error) { | |
ws: ws.NewUIChannel(), | ||
} | ||
|
||
// Start the WebSocket server for UI communication. | ||
if err := app.serveWebsocket(); err != nil { | ||
log.Error(err) | ||
} | ||
|
@@ -147,7 +160,7 @@ func NewAppWithFlags(flags flashlight.Flags, configDir string) (*App, error) { | |
return app, nil | ||
} | ||
|
||
// Run starts the app. | ||
// Run starts the application and initializes necessary components. | ||
func (app *App) Run(ctx context.Context) { | ||
golog.OnFatal(app.exitOnFatal) | ||
go func() { | ||
|
@@ -157,11 +170,8 @@ func (app *App) Run(ctx context.Context) { | |
}() | ||
|
||
log.Debug(app.Flags) | ||
userConfig := func() common.UserConfig { | ||
return settings.UserConfig(app.Settings()) | ||
} | ||
proClient := proclient.NewClient(fmt.Sprintf("https://%s", common.ProAPIHost), userConfig) | ||
authClient := auth.NewClient(fmt.Sprintf("https://%s", common.DFBaseUrl), userConfig) | ||
proClient := proclient.NewClient(fmt.Sprintf("https://%s", common.ProAPIHost), app.UserConfig) | ||
authClient := auth.NewClient(fmt.Sprintf("https://%s", common.DFBaseUrl), app.UserConfig) | ||
|
||
app.mu.Lock() | ||
app.proClient = proClient | ||
|
@@ -170,11 +180,12 @@ func (app *App) Run(ctx context.Context) { | |
|
||
settings := app.Settings() | ||
|
||
// Check and apply the ProxyAll flag. | ||
if app.Flags.ProxyAll { | ||
// If proxyall flag was supplied, force proxying of all | ||
settings.SetProxyAll(true) | ||
} | ||
|
||
// Determine the listen address for local HTTP and SOCKS proxies | ||
listenAddr := app.Flags.Addr | ||
if listenAddr == "" { | ||
listenAddr = settings.GetAddr() | ||
|
@@ -200,6 +211,7 @@ func (app *App) Run(ctx context.Context) { | |
}() | ||
} | ||
var err error | ||
// Initialize flashlight | ||
app.flashlight, err = flashlight.New( | ||
common.DefaultAppName, | ||
common.ApplicationVersion, | ||
|
@@ -216,8 +228,7 @@ func (app *App) Run(ctx context.Context) { | |
app.IsPro, | ||
settings.GetLanguage, | ||
func(addr string) (string, error) { return addr, nil }, // no dnsgrab reverse lookups on desktop | ||
// Dummy analytics function | ||
func(category, action, label string) {}, | ||
func(category, action, label string) {}, // Dummy analytics function | ||
flashlight.WithOnConfig(app.onConfigUpdate), | ||
flashlight.WithOnProxies(app.onProxiesUpdate), | ||
flashlight.WithOnSucceedingProxy(app.onSucceedingProxy), | ||
|
@@ -236,6 +247,20 @@ func (app *App) Run(ctx context.Context) { | |
) | ||
} | ||
|
||
// UserConfig returns the current user configuration after applying settings. | ||
func (app *App) UserConfig() common.UserConfig { | ||
settings := app.Settings() | ||
userID, deviceID, token := settings.GetUserID(), settings.GetDeviceID(), settings.GetToken() | ||
return common.NewUserConfig( | ||
common.DefaultAppName, | ||
deviceID, | ||
userID, | ||
token, | ||
nil, | ||
settings.GetLanguage(), | ||
) | ||
} | ||
|
||
// IsFeatureEnabled checks whether or not the given feature is enabled by flashlight | ||
func (app *App) IsFeatureEnabled(feature string) bool { | ||
if app.flashlight == nil { | ||
|
@@ -281,7 +306,7 @@ func (app *App) beforeStart(ctx context.Context, listenAddr string) { | |
} | ||
|
||
isProUser := func() (bool, bool) { | ||
return app.IsProUser(context.Background(), settings.UserConfig(app.Settings())) | ||
return app.IsProUser(context.Background(), app.UserConfig()) | ||
} | ||
|
||
if err := app.statsTracker.StartService(app.ws); err != nil { | ||
|
@@ -364,7 +389,7 @@ func (app *App) SendUpdateUserDataToUI() { | |
|
||
// 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 settings.SettingName, cb func(interface{})) { | ||
func (app *App) OnSettingChange(attr SettingName, cb func(interface{})) { | ||
app.settings.OnChange(attr, cb) | ||
} | ||
|
||
|
@@ -382,7 +407,7 @@ func (app *App) afterStart(cl *flashlightClient.Client) { | |
} | ||
go app.fetchDeviceLinkingCode(ctx) | ||
|
||
app.OnSettingChange(settings.SNSystemProxy, func(val interface{}) { | ||
app.OnSettingChange(SNSystemProxy, func(val interface{}) { | ||
enable := val.(bool) | ||
if enable { | ||
app.SysproxyOn() | ||
|
@@ -562,7 +587,7 @@ func (app *App) exitOnFatal(err error) { | |
|
||
// IsPro indicates whether or not the app is pro | ||
func (app *App) IsPro() bool { | ||
isPro, _ := app.IsProUserFast(settings.UserConfig(app.Settings())) | ||
isPro, _ := app.IsProUserFast(app.UserConfig()) | ||
return isPro | ||
} | ||
|
||
|
@@ -651,7 +676,7 @@ func (app *App) GetTranslations(filename string) ([]byte, error) { | |
return io.ReadAll(f) | ||
} | ||
|
||
func (app *App) Settings() *settings.Settings { | ||
func (app *App) Settings() *Settings { | ||
app.mu.RLock() | ||
defer app.mu.RUnlock() | ||
return app.settings | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we still using translations on the go end?