From ef166a61593cf3ee1b073333e4555d4ac6543d5f Mon Sep 17 00:00:00 2001 From: Leo Balduf Date: Sat, 2 Dec 2017 22:56:35 +0100 Subject: [PATCH] middleware, config: re-add support for min interval --- example_config.yaml | 4 ++++ middleware/middleware.go | 23 +++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/example_config.yaml b/example_config.yaml index 4116a99..65de121 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -3,6 +3,10 @@ chihaya: # frequently they should announce in between client events. 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 # scraped by an instance of the Prometheus time series database. # For more info see: https://prometheus.io diff --git a/middleware/middleware.go b/middleware/middleware.go index 0fdabb8..691e006 100644 --- a/middleware/middleware.go +++ b/middleware/middleware.go @@ -15,7 +15,8 @@ import ( // Config holds the configuration common across all middleware. 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{} @@ -24,27 +25,29 @@ var _ frontend.TrackerLogic = &Logic{} // middleware hooks. func NewLogic(cfg Config, peerStore storage.PeerStore, preHooks, postHooks []Hook) *Logic { return &Logic{ - announceInterval: cfg.AnnounceInterval, - peerStore: peerStore, - preHooks: append(preHooks, &responseHook{store: peerStore}), - postHooks: append(postHooks, &swarmInteractionHook{store: peerStore}), + announceInterval: cfg.AnnounceInterval, + minAnnounceInterval: cfg.MinAnnounceInterval, + peerStore: peerStore, + preHooks: append(preHooks, &responseHook{store: peerStore}), + postHooks: append(postHooks, &swarmInteractionHook{store: peerStore}), } } // Logic is an implementation of the TrackerLogic that functions by // executing a series of middleware hooks. type Logic struct { - announceInterval time.Duration - peerStore storage.PeerStore - preHooks []Hook - postHooks []Hook + announceInterval time.Duration + minAnnounceInterval time.Duration + peerStore storage.PeerStore + preHooks []Hook + postHooks []Hook } // HandleAnnounce generates a response for an Announce. func (l *Logic) HandleAnnounce(ctx context.Context, req *bittorrent.AnnounceRequest) (_ context.Context, resp *bittorrent.AnnounceResponse, err error) { resp = &bittorrent.AnnounceResponse{ Interval: l.announceInterval, - MinInterval: l.announceInterval, + MinInterval: l.minAnnounceInterval, Compact: req.Compact, } for _, h := range l.preHooks {