]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Add IPBlocklist option to Config, and test it's inherited by DHT
authorMatt Joiner <anacrolix@gmail.com>
Mon, 3 Aug 2015 15:07:22 +0000 (01:07 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 3 Aug 2015 15:07:22 +0000 (01:07 +1000)
client.go
client_test.go
config.go

index 045919a30956d7fbf5fabadd2f83be264e28724a..13b67cfae2dedd3a7a169f63b58ef1dedb953817 100644 (file)
--- 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
+}
index bb4fc36154fc7f7ce081fd1c5c283faf67322150..c59eeef639be588f31f4665926ece2491ba030e8 100644 (file)
@@ -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())
+}
index b6921182a2fd6416e05cbc44baa68646fe7aa446..e7de8d882b91ecdaf4084d0ab4ff9ae8c7eba7b2 100644 (file)
--- 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
 }