From 51aad774ab4ae964e67521520594beabaddc98ca Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 4 Aug 2015 01:07:22 +1000 Subject: [PATCH] Add IPBlocklist option to Config, and test it's inherited by DHT --- client.go | 8 +++++++- client_test.go | 14 ++++++++++++++ config.go | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 045919a3..13b67cfa 100644 --- a/client.go +++ b/client.go @@ -463,7 +463,9 @@ func NewClient(cfg *Config) (cl *Client, err error) { cl.torrentDataOpener = cfg.TorrentDataOpener } - if !cfg.NoDefaultBlocklist { + if cfg.IPBlocklist != nil { + cl.ipBlockList = cfg.IPBlocklist + } else if !cfg.NoDefaultBlocklist { err = cl.setEnvBlocklist() if err != nil { return @@ -2671,3 +2673,7 @@ func (me *Client) AddTorrentFromFile(filename string) (T Torrent, err error) { T, _, err = me.AddTorrentSpec(TorrentSpecFromMetaInfo(mi)) return } + +func (me *Client) DHT() *dht.Server { + return me.dHT +} diff --git a/client_test.go b/client_test.go index bb4fc361..c59eeef6 100644 --- a/client_test.go +++ b/client_test.go @@ -22,7 +22,9 @@ import ( "github.com/anacrolix/torrent/bencode" "github.com/anacrolix/torrent/data" "github.com/anacrolix/torrent/data/blob" + "github.com/anacrolix/torrent/dht" "github.com/anacrolix/torrent/internal/testutil" + "github.com/anacrolix/torrent/iplist" "github.com/anacrolix/torrent/metainfo" ) @@ -445,3 +447,15 @@ func TestResponsive(t *testing.T) { assert.EqualValues(t, 2, n) assert.EqualValues(t, "d\n", string(b)) } + +func TestDHTInheritBlocklist(t *testing.T) { + ipl := iplist.New(nil) + require.NotNil(t, ipl) + cl, err := NewClient(&Config{ + IPBlocklist: iplist.New(nil), + DHTConfig: &dht.ServerConfig{}, + }) + require.NoError(t, err) + defer cl.Close() + require.Equal(t, ipl, cl.DHT().IPBlocklist()) +} diff --git a/config.go b/config.go index b6921182..e7de8d88 100644 --- a/config.go +++ b/config.go @@ -2,6 +2,7 @@ package torrent import ( "github.com/anacrolix/torrent/dht" + "github.com/anacrolix/torrent/iplist" ) // Override Client defaults. @@ -43,4 +44,6 @@ type Config struct { // are in $REPO/data. If not set, the "file" implementation is used. TorrentDataOpener DisableEncryption bool `long:"disable-encryption"` + + IPBlocklist *iplist.IPList }