Skip to content

Commit

Permalink
Cleanup unused code (#1056)
Browse files Browse the repository at this point in the history
  • Loading branch information
myleshorton authored Apr 25, 2024
1 parent 7163452 commit ca793a5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 523 deletions.
93 changes: 8 additions & 85 deletions desktop/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package app
import (
"context"
"fmt"
"io"
"io/fs"
"io/ioutil"
"math/rand"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -36,7 +35,6 @@ import (
"github.com/getlantern/memhelper"
notify "github.com/getlantern/notifier"
"github.com/getlantern/profiling"
"github.com/getlantern/trafficlog-flashlight/tlproc"

"github.com/getlantern/lantern-client/desktop/analytics"
"github.com/getlantern/lantern-client/desktop/autoupdate"
Expand All @@ -57,8 +55,6 @@ var (
func init() {
autoupdate.Version = ApplicationVersion
autoupdate.PublicKey = []byte(packagePublicKey)

rand.Seed(time.Now().UnixNano())
}

// App is the core of the Lantern desktop application, in the form of a library.
Expand All @@ -83,23 +79,6 @@ type App struct {

flashlight *flashlight.Flashlight

// If both the trafficLogLock and proxiesLock are needed, the trafficLogLock should be obtained
// first. Keeping the order consistent avoids deadlocking.

// Log of network traffic to and from the proxies. Used to attach packet capture files to
// reported issues. Nil if traffic logging is not enabled.
trafficLog *tlproc.TrafficLogProcess
trafficLogLock sync.RWMutex

// Also protected by trafficLogLock.
captureSaveDuration time.Duration

// proxies are tracked by the application solely for data collection purposes. This value should
// not be changed, except by Flashlight.onProxiesUpdate. State-changing methods on the dialers
// should not be called. In short, this slice and its elements should be treated as read-only.
proxies []bandit.Dialer
proxiesLock sync.RWMutex

issueReporter *issueReporter
proClient proclient.ProClient
referralCode string
Expand Down Expand Up @@ -280,7 +259,7 @@ func (app *App) Run(isMain bool) {
Title: i18n.T("BACKEND_CONFIG_SAVE_ERROR_TITLE"),
Message: i18n.T("BACKEND_CONFIG_SAVE_ERROR_MESSAGE", i18n.T(translationAppName)),
ClickLabel: i18n.T("BACKEND_CLICK_LABEL_GOT_IT"),
IconURL: app.AddToken("/img/lantern_logo.png"),
IconURL: "/img/lantern_logo.png",
}
_ = notifier.ShowNotification(note, "alert-prompt")
})
Expand Down Expand Up @@ -319,8 +298,6 @@ func (app *App) checkEnabledFeatures() {

log.Debugf("Starting enabled features: %v", enabledFeatures)
//go app.startReplicaIfNecessary(enabledFeatures)
enableTrafficLog := app.isFeatureEnabled(enabledFeatures, config.FeatureTrafficLog)
go app.toggleTrafficLog(enableTrafficLog)
}

// startFeaturesService starts a new features service that dispatches features to any relevant listeners.
Expand Down Expand Up @@ -366,16 +343,11 @@ func (app *App) beforeStart(listenAddr string) {
}
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")
return "/img/lantern_logo.png"
}))
app.AddExitFunc("stopping notifier", notifier.NotificationsLoop(app.analyticsSession))
}

func (app *App) isFeatureEnabled(features map[string]bool, feature string) bool {
val, ok := features[feature]
return ok && val
}

// Connect turns on proxying
func (app *App) Connect() {
app.analyticsSession.Event("systray-menu", "connect")
Expand Down Expand Up @@ -471,30 +443,6 @@ func (app *App) onProxiesUpdate(proxies []bandit.Dialer, src config.Source) {
if src == config.Fetched {
atomic.StoreInt32(&app.fetchedProxiesConfig, 1)
}
app.trafficLogLock.Lock()
app.proxiesLock.Lock()
app.proxies = proxies
if app.trafficLog != nil {
proxyAddresses := []string{}
for _, p := range proxies {
proxyAddresses = append(proxyAddresses, p.Addr())
}
if err := app.trafficLog.UpdateAddresses(proxyAddresses); err != nil {
log.Errorf("failed to update traffic log addresses: %v", err)
}
}
app.proxiesLock.Unlock()
app.trafficLogLock.Unlock()
}

// getProxies returns the currently configured proxies. State-changing methods on these dialers
// should not be called. In short, the elements of this slice should be treated as read-only.
func (app *App) getProxies() []bandit.Dialer {
app.proxiesLock.RLock()
copied := make([]bandit.Dialer, len(app.proxies))
copy(copied, app.proxies)
app.proxiesLock.RUnlock()
return copied
}

// AddExitFunc adds a function to be called before the application exits.
Expand Down Expand Up @@ -655,35 +603,6 @@ func ShouldReportToSentry() bool {
return !uicommon.IsDevEnvironment()
}

// OnTrayShow indicates the user has selected to show lantern from the tray.
func (app *App) OnTrayShow() {
app.analyticsSession.Event("systray-menu", "show")
}

// OnTrayUpgrade indicates the user has selected to upgrade lantern from the tray.
func (app *App) OnTrayUpgrade() {
app.analyticsSession.Event("systray-menu", "upgrade")
}

// PlansURL returns the URL for accessing the checkout/plans page directly.
func (app *App) PlansURL() string {
return "#/plans"
}

// AdTrackURL returns the URL for adding tracking on injected ads.
func (app *App) AdTrackURL() string {
return "/ad_track"
}

// AddToken adds our secure token to a given request path.
func (app *App) AddToken(path string) string {
return path
}

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

// GetTranslations accesses translations with the given filename
func (app *App) GetTranslations(filename string) ([]byte, error) {
log.Tracef("Accessing translations %v", filename)
Expand All @@ -695,5 +614,9 @@ func (app *App) GetTranslations(filename string) ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("could not get traslation for file name: %v, %w", filename, err)
}
return ioutil.ReadAll(f)
return io.ReadAll(f)
}

func (app *App) Settings() *settings.Settings {
return app.settings
}
55 changes: 0 additions & 55 deletions desktop/app/diagnostics.go

This file was deleted.

23 changes: 4 additions & 19 deletions desktop/app/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ 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/util"
Expand All @@ -25,10 +23,8 @@ var (
)

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

type issueMessage struct {
Expand All @@ -49,25 +45,14 @@ type issueMessage struct {
// to the Lantern team.
func newIssueReporter(app *App) *issueReporter {
return &issueReporter{
getCapturedPackets: app.getCapturedPackets,
getProxies: app.getProxies,
proClient: app.proClient,
settings: app.settings,
proClient: app.proClient,
settings: app.settings,
}
}

// sendIssueReport creates an issue report from the given UI message and submits it to
// lantern-cloud/issue service, which is then forwarded to the ticket system via API
func (reporter *issueReporter) sendIssueReport(msg *issueMessage) error {

if msg.RunDiagnostics {
var err error
msg.DiagnosticsYAML, msg.ProxyCapture, err = reporter.runDiagnostics()
if err != nil {
log.Errorf("error running diagnostics: %v", err)
}
}

settings := reporter.settings
uc := common.NewUserConfigData(
common.DefaultAppName,
Expand Down
Loading

0 comments on commit ca793a5

Please sign in to comment.