Merge pull request #371 from mrd0ll4r/min-interval

middleware, config: re-add support for min interval
This commit is contained in:
mrd0ll4r 2017-12-07 19:44:19 +01:00 committed by GitHub
commit d28c6717b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 10 deletions

View file

@ -3,6 +3,10 @@ chihaya:
# frequently they should announce in between client events. # frequently they should announce in between client events.
announce_interval: 30m announce_interval: 30m
# The interval communicated with BitTorrent clients informing them of the
# minimal duration between announces.
min_announce_interval: 15m
# The network interface that will bind to an HTTP endpoint that can be # The network interface that will bind to an HTTP endpoint that can be
# scraped by an instance of the Prometheus time series database. # scraped by an instance of the Prometheus time series database.
# For more info see: https://prometheus.io # For more info see: https://prometheus.io

View file

@ -16,6 +16,7 @@ import (
// Config holds the configuration common across all middleware. // Config holds the configuration common across all middleware.
type Config struct { type Config struct {
AnnounceInterval time.Duration `yaml:"announce_interval"` AnnounceInterval time.Duration `yaml:"announce_interval"`
MinAnnounceInterval time.Duration `yaml:"min_announce_interval"`
} }
var _ frontend.TrackerLogic = &Logic{} var _ frontend.TrackerLogic = &Logic{}
@ -25,6 +26,7 @@ var _ frontend.TrackerLogic = &Logic{}
func NewLogic(cfg Config, peerStore storage.PeerStore, preHooks, postHooks []Hook) *Logic { func NewLogic(cfg Config, peerStore storage.PeerStore, preHooks, postHooks []Hook) *Logic {
return &Logic{ return &Logic{
announceInterval: cfg.AnnounceInterval, announceInterval: cfg.AnnounceInterval,
minAnnounceInterval: cfg.MinAnnounceInterval,
peerStore: peerStore, peerStore: peerStore,
preHooks: append(preHooks, &responseHook{store: peerStore}), preHooks: append(preHooks, &responseHook{store: peerStore}),
postHooks: append(postHooks, &swarmInteractionHook{store: peerStore}), postHooks: append(postHooks, &swarmInteractionHook{store: peerStore}),
@ -35,6 +37,7 @@ func NewLogic(cfg Config, peerStore storage.PeerStore, preHooks, postHooks []Hoo
// executing a series of middleware hooks. // executing a series of middleware hooks.
type Logic struct { type Logic struct {
announceInterval time.Duration announceInterval time.Duration
minAnnounceInterval time.Duration
peerStore storage.PeerStore peerStore storage.PeerStore
preHooks []Hook preHooks []Hook
postHooks []Hook postHooks []Hook
@ -44,7 +47,7 @@ type Logic struct {
func (l *Logic) HandleAnnounce(ctx context.Context, req *bittorrent.AnnounceRequest) (_ context.Context, resp *bittorrent.AnnounceResponse, err error) { func (l *Logic) HandleAnnounce(ctx context.Context, req *bittorrent.AnnounceRequest) (_ context.Context, resp *bittorrent.AnnounceResponse, err error) {
resp = &bittorrent.AnnounceResponse{ resp = &bittorrent.AnnounceResponse{
Interval: l.announceInterval, Interval: l.announceInterval,
MinInterval: l.announceInterval, MinInterval: l.minAnnounceInterval,
Compact: req.Compact, Compact: req.Compact,
} }
for _, h := range l.preHooks { for _, h := range l.preHooks {