middleware/infohash: move prefix to within package
Let middlewares own their prefixes, makes it simpler to manage for us.
This commit is contained in:
parent
d139335111
commit
d4099a5abf
5 changed files with 14 additions and 14 deletions
|
@ -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_.
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue