parent
fb30e9fb03
commit
3f29aa358b
4 changed files with 16 additions and 6 deletions
|
@ -16,6 +16,7 @@ config:
|
||||||
prometheus_addr: 0.0.0.0:6880
|
prometheus_addr: 0.0.0.0:6880
|
||||||
max_numwant: 50
|
max_numwant: 50
|
||||||
default_numwant: 25
|
default_numwant: 25
|
||||||
|
max_scrape_infohashes: 50
|
||||||
http:
|
http:
|
||||||
addr: 0.0.0.0:6881
|
addr: 0.0.0.0:6881
|
||||||
allow_ip_spoofing: true
|
allow_ip_spoofing: true
|
||||||
|
|
|
@ -14,6 +14,9 @@ chihaya:
|
||||||
# The default number of peers returned in an announce.
|
# The default number of peers returned in an announce.
|
||||||
default_numwant: 25
|
default_numwant: 25
|
||||||
|
|
||||||
|
# The number of infohashes a single scrape can request before being truncated.
|
||||||
|
max_scrape_infohashes: 50
|
||||||
|
|
||||||
# This block defines configuration for the tracker's HTTP interface.
|
# This block defines configuration for the tracker's HTTP interface.
|
||||||
# If you do not wish to run this, delete this section.
|
# If you do not wish to run this, delete this section.
|
||||||
http:
|
http:
|
||||||
|
|
|
@ -85,6 +85,7 @@ var ErrInvalidIP = errors.New("invalid IP")
|
||||||
type sanitizationHook struct {
|
type sanitizationHook struct {
|
||||||
maxNumWant uint32
|
maxNumWant uint32
|
||||||
defaultNumWant uint32
|
defaultNumWant uint32
|
||||||
|
maxScrapeInfoHashes uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *sanitizationHook) HandleAnnounce(ctx context.Context, req *bittorrent.AnnounceRequest, resp *bittorrent.AnnounceResponse) (context.Context, error) {
|
func (h *sanitizationHook) HandleAnnounce(ctx context.Context, req *bittorrent.AnnounceRequest, resp *bittorrent.AnnounceResponse) (context.Context, error) {
|
||||||
|
@ -109,6 +110,10 @@ func (h *sanitizationHook) HandleAnnounce(ctx context.Context, req *bittorrent.A
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *sanitizationHook) HandleScrape(ctx context.Context, req *bittorrent.ScrapeRequest, resp *bittorrent.ScrapeResponse) (context.Context, error) {
|
func (h *sanitizationHook) HandleScrape(ctx context.Context, req *bittorrent.ScrapeRequest, resp *bittorrent.ScrapeResponse) (context.Context, error) {
|
||||||
|
if len(req.InfoHashes) > int(h.maxScrapeInfoHashes) {
|
||||||
|
req.InfoHashes = req.InfoHashes[:h.maxScrapeInfoHashes]
|
||||||
|
}
|
||||||
|
|
||||||
return ctx, nil
|
return ctx, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ type Config struct {
|
||||||
AnnounceInterval time.Duration `yaml:"announce_interval"`
|
AnnounceInterval time.Duration `yaml:"announce_interval"`
|
||||||
MaxNumWant uint32 `yaml:"max_numwant"`
|
MaxNumWant uint32 `yaml:"max_numwant"`
|
||||||
DefaultNumWant uint32 `yaml:"default_numwant"`
|
DefaultNumWant uint32 `yaml:"default_numwant"`
|
||||||
|
MaxScrapeInfoHashes uint32 `yaml:"max_scrape_infohashes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ frontend.TrackerLogic = &Logic{}
|
var _ frontend.TrackerLogic = &Logic{}
|
||||||
|
@ -28,7 +29,7 @@ func NewLogic(cfg Config, peerStore storage.PeerStore, preHooks, postHooks []Hoo
|
||||||
l := &Logic{
|
l := &Logic{
|
||||||
announceInterval: cfg.AnnounceInterval,
|
announceInterval: cfg.AnnounceInterval,
|
||||||
peerStore: peerStore,
|
peerStore: peerStore,
|
||||||
preHooks: []Hook{&sanitizationHook{maxNumWant: cfg.MaxNumWant, defaultNumWant: cfg.DefaultNumWant}},
|
preHooks: []Hook{&sanitizationHook{cfg.MaxNumWant, cfg.DefaultNumWant, cfg.MaxScrapeInfoHashes}},
|
||||||
postHooks: append(postHooks, &swarmInteractionHook{store: peerStore}),
|
postHooks: append(postHooks, &swarmInteractionHook{store: peerStore}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue