Add IPBlocklist option to Config, and test it's inherited by DHT

This commit is contained in:
Matt Joiner 2015-08-04 01:07:22 +10:00
parent 8d581ce7f2
commit 51aad774ab
3 changed files with 24 additions and 1 deletions

View File

@ -463,7 +463,9 @@ func NewClient(cfg *Config) (cl *Client, err error) {
cl.torrentDataOpener = cfg.TorrentDataOpener cl.torrentDataOpener = cfg.TorrentDataOpener
} }
if !cfg.NoDefaultBlocklist { if cfg.IPBlocklist != nil {
cl.ipBlockList = cfg.IPBlocklist
} else if !cfg.NoDefaultBlocklist {
err = cl.setEnvBlocklist() err = cl.setEnvBlocklist()
if err != nil { if err != nil {
return return
@ -2671,3 +2673,7 @@ func (me *Client) AddTorrentFromFile(filename string) (T Torrent, err error) {
T, _, err = me.AddTorrentSpec(TorrentSpecFromMetaInfo(mi)) T, _, err = me.AddTorrentSpec(TorrentSpecFromMetaInfo(mi))
return return
} }
func (me *Client) DHT() *dht.Server {
return me.dHT
}

View File

@ -22,7 +22,9 @@ import (
"github.com/anacrolix/torrent/bencode" "github.com/anacrolix/torrent/bencode"
"github.com/anacrolix/torrent/data" "github.com/anacrolix/torrent/data"
"github.com/anacrolix/torrent/data/blob" "github.com/anacrolix/torrent/data/blob"
"github.com/anacrolix/torrent/dht"
"github.com/anacrolix/torrent/internal/testutil" "github.com/anacrolix/torrent/internal/testutil"
"github.com/anacrolix/torrent/iplist"
"github.com/anacrolix/torrent/metainfo" "github.com/anacrolix/torrent/metainfo"
) )
@ -445,3 +447,15 @@ func TestResponsive(t *testing.T) {
assert.EqualValues(t, 2, n) assert.EqualValues(t, 2, n)
assert.EqualValues(t, "d\n", string(b)) 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())
}

View File

@ -2,6 +2,7 @@ package torrent
import ( import (
"github.com/anacrolix/torrent/dht" "github.com/anacrolix/torrent/dht"
"github.com/anacrolix/torrent/iplist"
) )
// Override Client defaults. // Override Client defaults.
@ -43,4 +44,6 @@ type Config struct {
// are in $REPO/data. If not set, the "file" implementation is used. // are in $REPO/data. If not set, the "file" implementation is used.
TorrentDataOpener TorrentDataOpener
DisableEncryption bool `long:"disable-encryption"` DisableEncryption bool `long:"disable-encryption"`
IPBlocklist *iplist.IPList
} }