diff --git a/client.go b/client.go index 0c383caf..fadd8eea 100644 --- a/client.go +++ b/client.go @@ -526,9 +526,6 @@ func NewClient(cfg *Config) (cl *Client, err error) { } if !cfg.NoDHT { dhtCfg := cfg.DHTConfig - if dhtCfg == nil { - dhtCfg = &dht.ServerConfig{} - } if dhtCfg.IPBlocklist == nil { dhtCfg.IPBlocklist = cl.ipBlockList } @@ -538,7 +535,7 @@ func NewClient(cfg *Config) (cl *Client, err error) { if dhtCfg.Conn == nil && cl.utpSock != nil { dhtCfg.Conn = cl.utpSock } - cl.dHT, err = dht.NewServer(dhtCfg) + cl.dHT, err = dht.NewServer(&dhtCfg) if err != nil { return } diff --git a/client_test.go b/client_test.go index f073f5ee..c992a43e 100644 --- a/client_test.go +++ b/client_test.go @@ -42,6 +42,9 @@ var TestingConfig = Config{ NoDefaultBlocklist: true, DisableMetainfoCache: true, DataDir: filepath.Join(os.TempDir(), "anacrolix"), + DHTConfig: dht.ServerConfig{ + NoDefaultBootstrap: true, + }, } func TestClientDefault(t *testing.T) { @@ -580,10 +583,10 @@ func TestTorrentDroppedDuringResponsiveRead(t *testing.T) { func TestDHTInheritBlocklist(t *testing.T) { ipl := iplist.New(nil) require.NotNil(t, ipl) - cl, err := NewClient(&Config{ - IPBlocklist: iplist.New(nil), - DHTConfig: &dht.ServerConfig{}, - }) + cfg := TestingConfig + cfg.IPBlocklist = ipl + cfg.NoDHT = false + cl, err := NewClient(&cfg) require.NoError(t, err) defer cl.Close() require.Equal(t, ipl, cl.DHT().IPBlocklist()) diff --git a/config.go b/config.go index be0222d1..1f233000 100644 --- a/config.go +++ b/config.go @@ -20,7 +20,7 @@ type Config struct { // Don't create a DHT. NoDHT bool `long:"disable-dht"` // Overrides the default DHT configuration. - DHTConfig *dht.ServerConfig + DHTConfig dht.ServerConfig // Don't ever send chunks to peers. NoUpload bool `long:"no-upload"` // Upload even after there's nothing in it for us. By default uploading is diff --git a/issue35_test.go b/issue35_test.go index 59dbe38f..47227f91 100644 --- a/issue35_test.go +++ b/issue35_test.go @@ -1,15 +1,16 @@ package torrent import ( - "github.com/anacrolix/torrent/metainfo" - "testing" - "path/filepath" - "os" - "github.com/anacrolix/torrent/dht" - "io" "errors" "fmt" + "io" + "os" + "path/filepath" "runtime" + "testing" + + "github.com/anacrolix/torrent/dht" + "github.com/anacrolix/torrent/metainfo" ) var numclients int = 0 @@ -42,12 +43,13 @@ func testingConfig() *Config { Seed: true, DataDir: filepath.Join(os.TempDir(), "torrent-test/data"), ConfigDir: filepath.Join(os.TempDir(), "torrent-test/config"), - DHTConfig: &dht.ServerConfig{ - Passive: false, - BootstrapNodes: []string{}, - NoSecurity: false, + DHTConfig: dht.ServerConfig{ + Passive: false, + BootstrapNodes: []string{}, + NoSecurity: false, + NoDefaultBootstrap: true, }, - Debug: true, + Debug: true, } } @@ -74,7 +76,7 @@ func writeranddata(path string) error { return nil } -func TestInfohash(t *testing.T){ +func TestInfohash(t *testing.T) { os.RemoveAll(filepath.Join(os.TempDir(), "torrent-test")) os.MkdirAll(filepath.Join(os.TempDir(), "torrent-test"), 0700) var cl_one *Client