diff --git a/config/config.go b/config/config.go index 1d45e83e4..43d386c7c 100644 --- a/config/config.go +++ b/config/config.go @@ -16,7 +16,6 @@ import ( "github.com/getsentry/sentry-go" "gopkg.in/yaml.v3" - "github.com/getlantern/dhtup" "github.com/getlantern/golog" "github.com/getlantern/rot13" @@ -109,8 +108,6 @@ type options struct { // dictate whether the fetcher will use dual fetching (from fronted and // chained URLs) or not. rt http.RoundTripper - - dhtupContext *dhtup.Context } var globalConfigDhtTarget krpc.ID @@ -207,40 +204,6 @@ func pipeConfig(opts *options) (stop func()) { dispatch(cfg, Fetched) }, fetcher, opts.sleep, golog.LoggerFor(fmt.Sprintf("%v.%v.fetcher.http", packageLogPrefix, opts.name))) - - if opts.dhtupContext != nil { - dhtFetcher := dhtFetcher{ - dhtupResource: dhtup.NewResource(dhtup.ResourceInput{ - DhtTarget: globalConfigDhtTarget, - DhtContext: opts.dhtupContext, - FilePath: opts.name, - // Empty this to force data to be obtained through peers. - WebSeedUrls: []string{ - "https://globalconfig.flashlightproxy.com/dhtup/", - // For the same reason as with MetainfoUrls, if there's a config change, the - // wrong data is present if you go through globalconfig.flashlightproxy.com. - // This results in the webseeding code in anacrolix/torrent getting angry, - // and everyone piling onto the bootstrap seeders. - "https://s3.ap-northeast-1.amazonaws.com/globalconfig.flashlightproxy.com/dhtup/", - }, - Salt: []byte("globalconfig"), - // Empty this to force metainfo to be obtained via peers. - MetainfoUrls: []string{ - // This won't work for changes until the CloudFlare caches are flushed as part of updates. - "https://globalconfig.flashlightproxy.com/dhtup/globalconfig.torrent", - // Bypass CloudFlare cache. - "https://s3.ap-northeast-1.amazonaws.com/globalconfig.flashlightproxy.com/dhtup/globalconfig.torrent", - }, - }), - } - go conf.configFetcher( - stopCh, - func(cfg interface{}) { - dispatch(cfg, Dht) - }, - dhtFetcher, opts.sleep, - golog.LoggerFor(fmt.Sprintf("%v.%v.fetcher.dht", packageLogPrefix, opts.name))) - } } else { log.Debugf("Using sticky config") } diff --git a/config/dht.go b/config/dht.go deleted file mode 100644 index 7ca26197f..000000000 --- a/config/dht.go +++ /dev/null @@ -1,55 +0,0 @@ -package config - -import ( - "compress/gzip" - "context" - "fmt" - "io" - "time" - - "github.com/anacrolix/missinggo/v2" - "github.com/getlantern/dhtup" -) - -type dhtFetcher struct { - dhtupResource dhtup.Resource -} - -func (d dhtFetcher) fetch() (retB []byte, sleep time.Duration, err error) { - // There's some noise around default noSleep and default sleep times that I don't quite follow. - // We can override this value for specific cases below should they warrant better handling. A - // shorter timeout for transient network issues is a good default. - retB, temporary, err := d.fetchTemporary() - if temporary { - sleep = 2 * time.Minute - } else { - sleep = noSleep - } - return -} - -func (d dhtFetcher) fetchTemporary() (retB []byte, temporary bool, err error) { - // The only reason this is here is it might vary on how big the payload is. - ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Minute) - defer cancel() - r, temporary, err := d.dhtupResource.Open(ctx) - if err != nil { - err = fmt.Errorf("opening dht resource: %w", err) - return - } - defer r.Close() - gzipReader, err := gzip.NewReader( - missinggo.ContextedReader{R: r, Ctx: ctx}) - if err != nil { - temporary = false - err = fmt.Errorf("opening gzip: %w", err) - return - } - retB, err = io.ReadAll(gzipReader) - if err != nil { - err = fmt.Errorf("reading all: %w", err) - } - // What if we timed out while reading? - temporary = false - return -} diff --git a/config/initializer.go b/config/initializer.go index d102abfa0..6b620d526 100644 --- a/config/initializer.go +++ b/config/initializer.go @@ -7,7 +7,6 @@ import ( "time" commonconfig "github.com/getlantern/common/config" - "github.com/getlantern/dhtup" "github.com/getlantern/golog" "github.com/getlantern/yaml" @@ -38,7 +37,7 @@ func Init( configDir string, flags map[string]interface{}, userConfig common.UserConfig, proxiesDispatch func(interface{}, Source), onProxiesSaveError func(error), origGlobalDispatch func(interface{}, Source), onGlobalSaveError func(error), - rt http.RoundTripper, dhtupContext *dhtup.Context) (stop func()) { + rt http.RoundTripper) (stop func()) { staging := isStaging(flags) proxyConfigURL := checkOverrides(flags, getProxyURL(staging), "proxies.yaml.gz") @@ -46,8 +45,7 @@ func Init( return InitWithURLs( configDir, flags, userConfig, proxiesDispatch, onProxiesSaveError, - origGlobalDispatch, onGlobalSaveError, proxyConfigURL, globalConfigURL, rt, - dhtupContext) + origGlobalDispatch, onGlobalSaveError, proxyConfigURL, globalConfigURL, rt) } type cfgWithSource struct { @@ -63,8 +61,7 @@ func InitWithURLs( configDir string, flags map[string]interface{}, userConfig common.UserConfig, origProxiesDispatch func(interface{}, Source), onProxiesSaveError func(error), origGlobalDispatch func(interface{}, Source), onGlobalSaveError func(error), - proxyURL string, globalURL string, rt http.RoundTripper, - dhtupContext *dhtup.Context) (stop func()) { + proxyURL string, globalURL string, rt http.RoundTripper) (stop func()) { var mx sync.RWMutex globalConfigPollInterval := DefaultGlobalConfigPollInterval @@ -151,9 +148,8 @@ func InitWithURLs( defer mx.RUnlock() return globalConfigPollInterval }, - sticky: isSticky(flags), - rt: rt, - dhtupContext: dhtupContext, + sticky: isSticky(flags), + rt: rt, } stopGlobal := pipeConfig(globalOptions) diff --git a/config/initializer_test.go b/config/initializer_test.go index c5915e0b7..9e2c3fedd 100644 --- a/config/initializer_test.go +++ b/config/initializer_test.go @@ -43,7 +43,7 @@ func TestInit(t *testing.T) { req.Header.Add(common.CfgSvrAuthTokenHeader, "staging-token") return nil, nil }, - }, nil) + }) defer stop() _, valid := gotProxies.Get(time.Second * 12) @@ -86,7 +86,7 @@ func TestInitWithURLs(t *testing.T) { inTempDir("."), flags, newTestUserConfig(), proxiesDispatch, nil, globalDispatch, nil, - proxyConfigURL, globalConfigURL, &http.Transport{}, nil) + proxyConfigURL, globalConfigURL, &http.Transport{}) defer stop() // sleep some amount diff --git a/config_v7/config.go b/config_v7/config.go index d19abdc28..43d386c7c 100644 --- a/config_v7/config.go +++ b/config_v7/config.go @@ -16,7 +16,6 @@ import ( "github.com/getsentry/sentry-go" "gopkg.in/yaml.v3" - "github.com/getlantern/dhtup" "github.com/getlantern/golog" "github.com/getlantern/rot13" @@ -109,8 +108,6 @@ type options struct { // dictate whether the fetcher will use dual fetching (from fronted and // chained URLs) or not. rt http.RoundTripper - - dhtupContext *dhtup.Context } var globalConfigDhtTarget krpc.ID @@ -207,33 +204,6 @@ func pipeConfig(opts *options) (stop func()) { dispatch(cfg, Fetched) }, fetcher, opts.sleep, golog.LoggerFor(fmt.Sprintf("%v.%v.fetcher.http", packageLogPrefix, opts.name))) - - if opts.dhtupContext != nil { - dhtFetcher := dhtFetcher{ - dhtupResource: dhtup.NewResource(dhtup.ResourceInput{ - DhtTarget: globalConfigDhtTarget, - DhtContext: opts.dhtupContext, - FilePath: opts.name, - // Empty this to force data to be obtained through peers. - WebSeedUrls: []string{"https://globalconfig.flashlightproxy.com/dhtup/"}, - Salt: []byte("globalconfig"), - // Empty this to force metainfo to be obtained via peers. - MetainfoUrls: []string{ - // This won't work for changes until the CloudFlare caches are flushed as part of updates. - "https://globalconfig.flashlightproxy.com/dhtup/globalconfig.torrent", - // Bypass CloudFlare cache. - "https://s3.ap-northeast-1.amazonaws.com/globalconfig.flashlightproxy.com/dhtup/globalconfig.torrent", - }, - }), - } - go conf.configFetcher( - stopCh, - func(cfg interface{}) { - dispatch(cfg, Dht) - }, - dhtFetcher, opts.sleep, - golog.LoggerFor(fmt.Sprintf("%v.%v.fetcher.dht", packageLogPrefix, opts.name))) - } } else { log.Debugf("Using sticky config") } diff --git a/config_v7/dht.go b/config_v7/dht.go deleted file mode 100644 index 7ca26197f..000000000 --- a/config_v7/dht.go +++ /dev/null @@ -1,55 +0,0 @@ -package config - -import ( - "compress/gzip" - "context" - "fmt" - "io" - "time" - - "github.com/anacrolix/missinggo/v2" - "github.com/getlantern/dhtup" -) - -type dhtFetcher struct { - dhtupResource dhtup.Resource -} - -func (d dhtFetcher) fetch() (retB []byte, sleep time.Duration, err error) { - // There's some noise around default noSleep and default sleep times that I don't quite follow. - // We can override this value for specific cases below should they warrant better handling. A - // shorter timeout for transient network issues is a good default. - retB, temporary, err := d.fetchTemporary() - if temporary { - sleep = 2 * time.Minute - } else { - sleep = noSleep - } - return -} - -func (d dhtFetcher) fetchTemporary() (retB []byte, temporary bool, err error) { - // The only reason this is here is it might vary on how big the payload is. - ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Minute) - defer cancel() - r, temporary, err := d.dhtupResource.Open(ctx) - if err != nil { - err = fmt.Errorf("opening dht resource: %w", err) - return - } - defer r.Close() - gzipReader, err := gzip.NewReader( - missinggo.ContextedReader{R: r, Ctx: ctx}) - if err != nil { - temporary = false - err = fmt.Errorf("opening gzip: %w", err) - return - } - retB, err = io.ReadAll(gzipReader) - if err != nil { - err = fmt.Errorf("reading all: %w", err) - } - // What if we timed out while reading? - temporary = false - return -} diff --git a/config_v7/initializer.go b/config_v7/initializer.go index d102abfa0..6b620d526 100644 --- a/config_v7/initializer.go +++ b/config_v7/initializer.go @@ -7,7 +7,6 @@ import ( "time" commonconfig "github.com/getlantern/common/config" - "github.com/getlantern/dhtup" "github.com/getlantern/golog" "github.com/getlantern/yaml" @@ -38,7 +37,7 @@ func Init( configDir string, flags map[string]interface{}, userConfig common.UserConfig, proxiesDispatch func(interface{}, Source), onProxiesSaveError func(error), origGlobalDispatch func(interface{}, Source), onGlobalSaveError func(error), - rt http.RoundTripper, dhtupContext *dhtup.Context) (stop func()) { + rt http.RoundTripper) (stop func()) { staging := isStaging(flags) proxyConfigURL := checkOverrides(flags, getProxyURL(staging), "proxies.yaml.gz") @@ -46,8 +45,7 @@ func Init( return InitWithURLs( configDir, flags, userConfig, proxiesDispatch, onProxiesSaveError, - origGlobalDispatch, onGlobalSaveError, proxyConfigURL, globalConfigURL, rt, - dhtupContext) + origGlobalDispatch, onGlobalSaveError, proxyConfigURL, globalConfigURL, rt) } type cfgWithSource struct { @@ -63,8 +61,7 @@ func InitWithURLs( configDir string, flags map[string]interface{}, userConfig common.UserConfig, origProxiesDispatch func(interface{}, Source), onProxiesSaveError func(error), origGlobalDispatch func(interface{}, Source), onGlobalSaveError func(error), - proxyURL string, globalURL string, rt http.RoundTripper, - dhtupContext *dhtup.Context) (stop func()) { + proxyURL string, globalURL string, rt http.RoundTripper) (stop func()) { var mx sync.RWMutex globalConfigPollInterval := DefaultGlobalConfigPollInterval @@ -151,9 +148,8 @@ func InitWithURLs( defer mx.RUnlock() return globalConfigPollInterval }, - sticky: isSticky(flags), - rt: rt, - dhtupContext: dhtupContext, + sticky: isSticky(flags), + rt: rt, } stopGlobal := pipeConfig(globalOptions) diff --git a/config_v7/initializer_test.go b/config_v7/initializer_test.go index c5915e0b7..9e2c3fedd 100644 --- a/config_v7/initializer_test.go +++ b/config_v7/initializer_test.go @@ -43,7 +43,7 @@ func TestInit(t *testing.T) { req.Header.Add(common.CfgSvrAuthTokenHeader, "staging-token") return nil, nil }, - }, nil) + }) defer stop() _, valid := gotProxies.Get(time.Second * 12) @@ -86,7 +86,7 @@ func TestInitWithURLs(t *testing.T) { inTempDir("."), flags, newTestUserConfig(), proxiesDispatch, nil, globalDispatch, nil, - proxyConfigURL, globalConfigURL, &http.Transport{}, nil) + proxyConfigURL, globalConfigURL, &http.Transport{}) defer stop() // sleep some amount diff --git a/flashlight.go b/flashlight.go index 06cb2c048..94219fcde 100644 --- a/flashlight.go +++ b/flashlight.go @@ -9,7 +9,6 @@ import ( commonconfig "github.com/getlantern/common/config" "github.com/getlantern/detour" - "github.com/getlantern/dhtup" "github.com/getlantern/dnsgrab" "github.com/getlantern/errors" "github.com/getlantern/eventual" @@ -95,7 +94,6 @@ type Flashlight struct { client *client.Client op *fops.Op errorHandler func(HandledErrorType, error) - dhtupContext *dhtup.Context mxProxyListeners sync.RWMutex proxyListeners []func(map[string]*commonconfig.ProxyConfig, config.Source) } @@ -276,7 +274,7 @@ func (f *Flashlight) startConfigFetch() func() { stopConfig := config.Init( f.configDir, f.flagsAsMap, f.userConfig, proxiesDispatch, onProxiesSaveError, - globalDispatch, onConfigSaveError, rt, f.dhtupContext) + globalDispatch, onConfigSaveError, rt) return stopConfig } @@ -326,7 +324,6 @@ func New( reverseDNS func(host string) (string, error), adTrackUrl func() string, eventWithLabel func(category, action, label string), - dhtupContext *dhtup.Context, ) (*Flashlight, error) { log.Debugf("Running in app: %v", appName) log.Debugf("Using configdir: %v", configDir) @@ -357,7 +354,6 @@ func New( errorHandler: func(t HandledErrorType, err error) { log.Errorf("%v: %v", t, err) }, - dhtupContext: dhtupContext, proxyListeners: make([]func(map[string]*commonconfig.ProxyConfig, config.Source), 0), } diff --git a/go.mod b/go.mod index dd836faa8..9e9433f7a 100644 --- a/go.mod +++ b/go.mod @@ -35,7 +35,6 @@ require ( github.com/PuerkitoBio/goquery v1.8.1 github.com/anacrolix/dht/v2 v2.20.0 github.com/anacrolix/go-libutp v1.3.1 - github.com/anacrolix/missinggo/v2 v2.7.1 github.com/andybalholm/brotli v1.0.5 github.com/blang/semver v3.5.1+incompatible github.com/dustin/go-humanize v1.0.1 @@ -48,7 +47,6 @@ require ( github.com/getlantern/cmuxprivate v0.0.0-20211216020409-d29d0d38be54 github.com/getlantern/common v1.2.1-0.20230427204521-6ac18c21db39 github.com/getlantern/detour v0.0.0-20230503144615-d3106a68f79e - github.com/getlantern/dhtup v0.0.0-20230218071625-e78bcd432e4b github.com/getlantern/dnsgrab v0.0.0-20211216020425-5d5e155a01a8 github.com/getlantern/domains v0.0.0-20220311111720-94f59a903271 github.com/getlantern/ema v0.0.0-20190620044903-5943d28f40e4 @@ -147,6 +145,7 @@ require ( github.com/anacrolix/log v0.13.2-0.20221123232138-02e2764801c3 // indirect github.com/anacrolix/missinggo v1.3.0 // indirect github.com/anacrolix/missinggo/perf v1.0.0 // indirect + github.com/anacrolix/missinggo/v2 v2.7.1 // indirect github.com/anacrolix/mmsg v1.0.0 // indirect github.com/anacrolix/multiless v0.3.1-0.20221221005021-2d12701f83f7 // indirect github.com/anacrolix/squirrel v0.4.1-0.20220122230132-14b040773bac // indirect @@ -180,6 +179,7 @@ require ( github.com/getlantern/byteexec v0.0.0-20220903142956-e6ed20032cfd // indirect github.com/getlantern/cmux v0.0.0-20230301223233-dac79088a4c0 // indirect github.com/getlantern/context v0.0.0-20220418194847-3d5e7a086201 // indirect + github.com/getlantern/dhtup v0.0.0-20230218063409-258bc7570a27 // indirect github.com/getlantern/dns v0.0.0-20210120185712-8d005533efa0 // indirect github.com/getlantern/elevate v0.0.0-20220903142053-479ab992b264 // indirect github.com/getlantern/enproxy v0.0.0-20180913191734-002212d417a4 // indirect diff --git a/go.sum b/go.sum index 8806cd6c3..6e1f79cce 100644 --- a/go.sum +++ b/go.sum @@ -297,8 +297,8 @@ github.com/getlantern/context v0.0.0-20220418194847-3d5e7a086201 h1:oEZYEpZo28Wd github.com/getlantern/context v0.0.0-20220418194847-3d5e7a086201/go.mod h1:Y9WZUHEb+mpra02CbQ/QczLUe6f0Dezxaw5DCJlJQGo= github.com/getlantern/detour v0.0.0-20230503144615-d3106a68f79e h1:ah9RgyL8S76l/iUcNDAD7K9WDq4DWy71guQy7pDUtQk= github.com/getlantern/detour v0.0.0-20230503144615-d3106a68f79e/go.mod h1:BndJgV9V8+iLA35NIVqk7u0VTLUGgkc1jmVI+gWJAtI= -github.com/getlantern/dhtup v0.0.0-20230218071625-e78bcd432e4b h1:s6hIG0ssf0ixxDl2L/yl4pLr1hE3i+pkMPwJJzCKAB8= -github.com/getlantern/dhtup v0.0.0-20230218071625-e78bcd432e4b/go.mod h1:vHmyGO0tz9xO4rxi7rZCUjnI3GJ/26u6YHwdeamd3Bs= +github.com/getlantern/dhtup v0.0.0-20230218063409-258bc7570a27 h1:s0V8y7LIHcGUsSk8IO2datQWYCIUahqx0+9t2H5Op4s= +github.com/getlantern/dhtup v0.0.0-20230218063409-258bc7570a27/go.mod h1:vHmyGO0tz9xO4rxi7rZCUjnI3GJ/26u6YHwdeamd3Bs= github.com/getlantern/dns v0.0.0-20210120185712-8d005533efa0 h1:8DQSmWtwBy8Z0Zr/kiRJRhBPQO4LMN0mziCJd+8edhw= github.com/getlantern/dns v0.0.0-20210120185712-8d005533efa0/go.mod h1:nd1wZuSxVB7DZVqZT1hCFkdWcMqbuO5XQSd+1Duk/fs= github.com/getlantern/dnsgrab v0.0.0-20211216020425-5d5e155a01a8 h1:UKCd60g0A2N5t1EO45hNKR0fJ0QC9o33S476S3Aro9g=