Make Config.DHTConfig not a pointer

This commit is contained in:
Matt Joiner 2016-01-17 00:12:53 +11:00
parent 2beb5f8bd4
commit 8696f32e58
4 changed files with 23 additions and 21 deletions

View File

@ -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
}

View 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())

View File

@ -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

View 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