client.go | 90 ----------------------------------------------------- client_test.go | 1 - config.go | 2 -- doc.go | 5 ----- fs/torrentfs_test.go | 11 +---------- issue35_test.go | 1 - diff --git a/client.go b/client.go index 66b2d81ebcecc0bcdd95c5ca5d4a7d175849f6a3..21446ff6f8e578fac364c7a51023be7633969619 100644 --- a/client.go +++ b/client.go @@ -28,7 +28,6 @@ "github.com/anacrolix/missinggo/pproffd" "github.com/anacrolix/missinggo/pubsub" "github.com/anacrolix/sync" "github.com/anacrolix/utp" - "github.com/edsrzf/mmap-go" "github.com/anacrolix/torrent/bencode" "github.com/anacrolix/torrent/dht" @@ -284,85 +283,6 @@ func (cl *Client) ConfigDir() string { return cl.configDir() } -func loadPackedBlocklist(filename string) (ret iplist.Ranger, err error) { - f, err := os.Open(filename) - if os.IsNotExist(err) { - err = nil - return - } - if err != nil { - return - } - defer f.Close() - mm, err := mmap.Map(f, mmap.RDONLY, 0) - if err != nil { - return - } - ret = iplist.NewFromPacked(mm) - return -} - -func (cl *Client) setEnvBlocklist() (err error) { - filename := os.Getenv("TORRENT_BLOCKLIST_FILE") - defaultBlocklist := filename == "" - if defaultBlocklist { - cl.ipBlockList, err = loadPackedBlocklist(filepath.Join(cl.configDir(), "packed-blocklist")) - if err != nil { - return - } - if cl.ipBlockList != nil { - return - } - filename = filepath.Join(cl.configDir(), "blocklist") - } - f, err := os.Open(filename) - if err != nil { - if defaultBlocklist { - err = nil - } - return - } - defer f.Close() - cl.ipBlockList, err = iplist.NewFromReader(f) - return -} - -func (cl *Client) initBannedTorrents() error { - f, err := os.Open(filepath.Join(cl.configDir(), "banned_infohashes")) - if err != nil { - if os.IsNotExist(err) { - return nil - } - return fmt.Errorf("error opening banned infohashes file: %s", err) - } - defer f.Close() - scanner := bufio.NewScanner(f) - cl.bannedTorrents = make(map[metainfo.Hash]struct{}) - for scanner.Scan() { - if strings.HasPrefix(strings.TrimSpace(scanner.Text()), "#") { - continue - } - var ihs string - n, err := fmt.Sscanf(scanner.Text(), "%x", &ihs) - if err != nil { - return fmt.Errorf("error reading infohash: %s", err) - } - if n != 1 { - continue - } - if len(ihs) != 20 { - return errors.New("bad infohash") - } - var ih metainfo.Hash - missinggo.CopyExact(&ih, ihs) - cl.bannedTorrents[ih] = struct{}{} - } - if err := scanner.Err(); err != nil { - return fmt.Errorf("error scanning file: %s", err) - } - return nil -} - // Creates a new client. func NewClient(cfg *Config) (cl *Client, err error) { if cfg == nil { @@ -388,16 +308,6 @@ cl.defaultStorage = storage.NewFile(cfg.DataDir) } if cfg.IPBlocklist != nil { cl.ipBlockList = cfg.IPBlocklist - } else if !cfg.NoDefaultBlocklist { - err = cl.setEnvBlocklist() - if err != nil { - return - } - } - - if err = cl.initBannedTorrents(); err != nil { - err = fmt.Errorf("error initing banned torrents: %s", err) - return } if cfg.PeerID != "" { diff --git a/client_test.go b/client_test.go index bc20fed3af8346280bcbe316ab6889d40c13bbb5..14b0ffd0bca92dabb4a14c34c2e1e8a007e28b5d 100644 --- a/client_test.go +++ b/client_test.go @@ -40,7 +40,6 @@ var TestingConfig = Config{ ListenAddr: "localhost:0", NoDHT: true, DisableTrackers: true, - NoDefaultBlocklist: true, DisableMetainfoCache: true, DataDir: "/dev/null", DHTConfig: dht.ServerConfig{ diff --git a/config.go b/config.go index bde89e0e9d0bc4b7a73128569ff4e4d7399ba9fe..718e95cc4336ab80b87b5e62b501b0fd7ed48579 100644 --- a/config.go +++ b/config.go @@ -33,8 +33,6 @@ // For the bittorrent protocol. DisableUTP bool // For the bittorrent protocol. DisableTCP bool `long:"disable-tcp"` - // Don't automatically load "$ConfigDir/blocklist". - NoDefaultBlocklist bool // Defaults to "$HOME/.config/torrent". This is where "blocklist", // "torrents" and other operational files are stored. TODO: Dump this // stuff, this is specific to the default cmd/torrent client only. diff --git a/doc.go b/doc.go index 5545d3435cfa158686938a6136aa714851f2d929..012f6bfe3ba7ac7ab7957178795f2ee5445f0a5b 100644 --- a/doc.go +++ b/doc.go @@ -18,11 +18,6 @@ ConfigDir A Client has a configurable ConfigDir that defaults to $HOME/.config/torrent. Torrent metainfo files are cached at $CONFIGDIR/torrents/$infohash.torrent. -Infohashes in $CONFIGDIR/banned_infohashes cannot be added to the Client. A -P2P Plaintext Format blocklist is loaded from a file at the location specified -by the environment variable TORRENT_BLOCKLIST_FILE if set. otherwise from -$CONFIGDIR/blocklist. If $CONFIGDIR/packed-blocklist exists, this is memory- -mapped as a packed IP blocklist, saving considerable memory. */ package torrent diff --git a/fs/torrentfs_test.go b/fs/torrentfs_test.go index cca219925184a38e60c53bde93ab2e2f95c6df8b..8334f109239894e9f106240372fe2e75819daeaa 100644 --- a/fs/torrentfs_test.go +++ b/fs/torrentfs_test.go @@ -98,8 +98,6 @@ NoDHT: true, ListenAddr: "redonk", DisableTCP: true, DisableUTP: true, - - NoDefaultBlocklist: true, }) require.NoError(t, err) defer client.Close() @@ -171,8 +169,6 @@ DisableTrackers: true, NoDHT: true, ListenAddr: "localhost:0", Seed: true, - - NoDefaultBlocklist: true, // Ensure that the metainfo is obtained over the wire, since we added // the torrent to the seeder by magnet. DisableMetainfoCache: true, @@ -188,14 +184,9 @@ DisableTrackers: true, NoDHT: true, ListenAddr: "localhost:0", DisableTCP: true, - - NoDefaultBlocklist: true, - - DefaultStorage: storage.NewMMap(filepath.Join(layout.BaseDir, "download")), - + DefaultStorage: storage.NewMMap(filepath.Join(layout.BaseDir, "download")), // This can be used to check if clients can connect to other clients // with the same ID. - // PeerID: seeder.PeerID(), }) leecher.SetIPBlockList(nil) diff --git a/issue35_test.go b/issue35_test.go index b5e7adf19bc901b0dc1b3f7f20d958d0f11bf7ba..ca3d6f9974f83de6d846869ce2979336a65132f0 100644 --- a/issue35_test.go +++ b/issue35_test.go @@ -35,7 +35,6 @@ return &Config{ ListenAddr: "localhost:0", NoDHT: false, DisableTrackers: true, - NoDefaultBlocklist: true, DisableUTP: false, DisableMetainfoCache: true, DisableIPv6: true,