]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Make Config.DHTConfig not a pointer
authorMatt Joiner <anacrolix@gmail.com>
Sat, 16 Jan 2016 13:12:53 +0000 (00:12 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Sat, 16 Jan 2016 13:12:53 +0000 (00:12 +1100)
client.go
client_test.go
config.go
issue35_test.go

index 0c383cafd4de9e1195828b76dd01937de4f454b0..fadd8eea94cd01e5077aabddbfdf01beb06d6be7 100644 (file)
--- 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
                }
index f073f5eebdba2536f38f8e83655129727efeb34d..c992a43ebf516caaf44ef2245bb06c464f1481e3 100644 (file)
@@ -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())
index be0222d183256fd6f421babd7c32aaf5064035cb..1f2330005ad69fc3dac81b14484a5eded19585a2 100644 (file)
--- 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
index 59dbe38fbd83db62991badafd2dff30129e94d7e..47227f91ee6758d226d99483c5f40b3de6ba49d4 100644 (file)
@@ -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