diff --git a/server/store/middleware/infohash/README.md b/server/store/middleware/infohash/README.md index b47e423..213bcec 100644 --- a/server/store/middleware/infohash/README.md +++ b/server/store/middleware/infohash/README.md @@ -7,11 +7,11 @@ It also provides the configurable scrape middleware `infohash_blacklist` and `in #### For Announces -The `infohash_blacklist` middleware uses all infohashes stored in the `StringStore` with the `store.PrefixInfohash` prefix to blacklist, i.e. block announces. +The `infohash_blacklist` middleware uses all infohashes stored in the `StringStore` with the `PrefixInfohash` prefix to blacklist, i.e. block announces. #### For Scrapes -The configurable `infohash_blacklist` middleware uses all infohashes stored in the `StringStore` with the `store.PrefixInfohash` prefix to blacklist scrape requests. +The configurable `infohash_blacklist` middleware uses all infohashes stored in the `StringStore` with the `PrefixInfohash` prefix to blacklist scrape requests. The scrape middleware has two modes of operation: _Block_ and _Filter_. @@ -25,11 +25,11 @@ See the configuration section for information about how to configure the scrape #### For Announces -The `infohash_blacklist` middleware uses all infohashes stored in the `StringStore` with the `store.PrefixInfohash` prefix to whitelist, i.e. allow announces. +The `infohash_blacklist` middleware uses all infohashes stored in the `StringStore` with the `PrefixInfohash` prefix to whitelist, i.e. allow announces. #### For Scrapes -The configurable `infohash_blacklist` middleware uses all infohashes stored in the `StringStore` with the `store.PrefixInfohash` prefix to whitelist scrape requests. +The configurable `infohash_blacklist` middleware uses all infohashes stored in the `StringStore` with the `PrefixInfohash` prefix to whitelist scrape requests. The scrape middleware has two modes of operation: _Block_ and _Filter_. diff --git a/server/store/middleware/infohash/blacklist.go b/server/store/middleware/infohash/blacklist.go index 25b11dd..47c4eef 100644 --- a/server/store/middleware/infohash/blacklist.go +++ b/server/store/middleware/infohash/blacklist.go @@ -23,7 +23,7 @@ var ErrBlockedInfohash = tracker.ClientError("disallowed infohash") // for infohashes that are not stored in a StringStore. func blacklistAnnounceInfohash(next tracker.AnnounceHandler) tracker.AnnounceHandler { return func(cfg *chihaya.TrackerConfig, req *chihaya.AnnounceRequest, resp *chihaya.AnnounceResponse) (err error) { - blacklisted, err := store.MustGetStore().HasString(store.PrefixInfohash + string(req.InfoHash)) + blacklisted, err := store.MustGetStore().HasString(PrefixInfohash + string(req.InfoHash)) if err != nil { return err } else if blacklisted { @@ -67,7 +67,7 @@ func blacklistFilterScrape(next tracker.ScrapeHandler) tracker.ScrapeHandler { infohashes := req.InfoHashes for i, ih := range infohashes { - blacklisted, err = storage.HasString(store.PrefixInfohash + string(ih)) + blacklisted, err = storage.HasString(PrefixInfohash + string(ih)) if err != nil { return err @@ -87,7 +87,7 @@ func blacklistBlockScrape(next tracker.ScrapeHandler) tracker.ScrapeHandler { storage := store.MustGetStore() for _, ih := range req.InfoHashes { - blacklisted, err = storage.HasString(store.PrefixInfohash + string(ih)) + blacklisted, err = storage.HasString(PrefixInfohash + string(ih)) if err != nil { return err diff --git a/server/store/middleware/infohash/blacklist_test.go b/server/store/middleware/infohash/blacklist_test.go index d260072..32a334a 100644 --- a/server/store/middleware/infohash/blacklist_test.go +++ b/server/store/middleware/infohash/blacklist_test.go @@ -41,7 +41,7 @@ func TestASetUp(t *testing.T) { assert.Nil(t, err) srv.Start() - store.MustGetStore().PutString(store.PrefixInfohash + "abc") + store.MustGetStore().PutString(PrefixInfohash + "abc") } func TestBlacklistAnnounceMiddleware(t *testing.T) { diff --git a/server/store/middleware/infohash/whitelist.go b/server/store/middleware/infohash/whitelist.go index 4861465..53e425f 100644 --- a/server/store/middleware/infohash/whitelist.go +++ b/server/store/middleware/infohash/whitelist.go @@ -15,11 +15,14 @@ func init() { tracker.RegisterScrapeMiddlewareConstructor("infohash_whitelist", whitelistScrapeInfohash) } +// PrefixInfohash is the prefix to be used for infohashes. +const PrefixInfohash = "ih-" + // whitelistAnnounceInfohash provides a middleware that only allows announces // for infohashes that are not stored in a StringStore func whitelistAnnounceInfohash(next tracker.AnnounceHandler) tracker.AnnounceHandler { return func(cfg *chihaya.TrackerConfig, req *chihaya.AnnounceRequest, resp *chihaya.AnnounceResponse) (err error) { - whitelisted, err := store.MustGetStore().HasString(store.PrefixInfohash + string(req.InfoHash)) + whitelisted, err := store.MustGetStore().HasString(PrefixInfohash + string(req.InfoHash)) if err != nil { return err @@ -63,7 +66,7 @@ func whitelistFilterScrape(next tracker.ScrapeHandler) tracker.ScrapeHandler { infohashes := req.InfoHashes for i, ih := range infohashes { - whitelisted, err = storage.HasString(store.PrefixInfohash + string(ih)) + whitelisted, err = storage.HasString(PrefixInfohash + string(ih)) if err != nil { return err @@ -83,7 +86,7 @@ func whitelistBlockScrape(next tracker.ScrapeHandler) tracker.ScrapeHandler { storage := store.MustGetStore() for _, ih := range req.InfoHashes { - whitelisted, err = storage.HasString(store.PrefixInfohash + string(ih)) + whitelisted, err = storage.HasString(PrefixInfohash + string(ih)) if err != nil { return err diff --git a/server/store/string_store.go b/server/store/string_store.go index ab2c992..4c28f23 100644 --- a/server/store/string_store.go +++ b/server/store/string_store.go @@ -6,9 +6,6 @@ package store import "fmt" -// PrefixInfohash is the prefix to be used for infohashes. -const PrefixInfohash = "ih-" - var stringStoreDrivers = make(map[string]StringStoreDriver) // StringStore represents an interface for manipulating strings.