From 8f164ae956cc2a3a0d34e5858b86427551f7d1c6 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 4 Apr 2016 14:04:48 +1000 Subject: [PATCH] Remove some of the magic ConfigDir stuff This might become a helper. Torrent file cache still remains. --- client.go | 90 -------------------------------------------- client_test.go | 1 - config.go | 2 - doc.go | 5 --- fs/torrentfs_test.go | 11 +----- issue35_test.go | 1 - 6 files changed, 1 insertion(+), 109 deletions(-) diff --git a/client.go b/client.go index 66b2d81e..21446ff6 100644 --- a/client.go +++ b/client.go @@ -28,7 +28,6 @@ import ( "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 @@ func NewClient(cfg *Config) (cl *Client, err error) { } 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 bc20fed3..14b0ffd0 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 bde89e0e..718e95cc 100644 --- a/config.go +++ b/config.go @@ -33,8 +33,6 @@ type Config struct { 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 5545d343..012f6bfe 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 cca21992..8334f109 100644 --- a/fs/torrentfs_test.go +++ b/fs/torrentfs_test.go @@ -98,8 +98,6 @@ func TestUnmountWedged(t *testing.T) { ListenAddr: "redonk", DisableTCP: true, DisableUTP: true, - - NoDefaultBlocklist: true, }) require.NoError(t, err) defer client.Close() @@ -171,8 +169,6 @@ func TestDownloadOnDemand(t *testing.T) { 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 @@ func TestDownloadOnDemand(t *testing.T) { 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 b5e7adf1..ca3d6f99 100644 --- a/issue35_test.go +++ b/issue35_test.go @@ -35,7 +35,6 @@ func issue35TestingConfig() *Config { ListenAddr: "localhost:0", NoDHT: false, DisableTrackers: true, - NoDefaultBlocklist: true, DisableUTP: false, DisableMetainfoCache: true, DisableIPv6: true, -- 2.44.0