Documentation ¶
Overview ¶
Package middleware implements the TrackerLogic interface by executing a series of middleware hooks.
Index ¶
- Variables
- func RegisterDriver(name string, d Driver)
- type Driver
- type Hook
- type HookConfig
- type Logic
- func (l *Logic) AfterAnnounce(ctx context.Context, req *bittorrent.AnnounceRequest, ...)
- func (l *Logic) AfterScrape(ctx context.Context, req *bittorrent.ScrapeRequest, ...)
- func (l *Logic) HandleAnnounce(ctx context.Context, req *bittorrent.AnnounceRequest) (_ context.Context, resp *bittorrent.AnnounceResponse, err error)
- func (l *Logic) HandleScrape(ctx context.Context, req *bittorrent.ScrapeRequest) (_ context.Context, resp *bittorrent.ScrapeResponse, err error)
- func (l *Logic) Stop() stop.Result
- type ResponseConfig
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDriverDoesNotExist is the error returned by NewMiddleware when a // middleware driver with that name does not exist. ErrDriverDoesNotExist = errors.New("middleware driver with that name does not exist") )
var ScrapeIsIPv6Key = scrapeAddressType{}
ScrapeIsIPv6Key is the key under which to store whether or not the address used to request a scrape was an IPv6 address. The value is expected to be of type bool. A missing value or a value that is not a bool for this key is equivalent to it being set to false.
var SkipResponseHookKey = skipResponseHook{}
SkipResponseHookKey is a key for the context of an Announce or Scrape to control whether the response middleware should run. Any non-nil value set for this key will cause the response middleware to skip.
var SkipSwarmInteractionKey = skipSwarmInteraction{}
SkipSwarmInteractionKey is a key for the context of an Announce to control whether the swarm interaction middleware should run. Any non-nil value set for this key will cause the swarm interaction middleware to skip.
Functions ¶
func RegisterDriver ¶
RegisterDriver makes a Driver available by the provided name.
If called twice with the same name, the name is blank, or if the provided Driver is nil, this function panics.
Types ¶
type Driver ¶
Driver is the interface used to initialize a new type of middleware.
The options parameter is YAML encoded bytes that should be unmarshalled into the hook's custom configuration.
type Hook ¶
type Hook interface { HandleAnnounce(context.Context, *bittorrent.AnnounceRequest, *bittorrent.AnnounceResponse) (context.Context, error) HandleScrape(context.Context, *bittorrent.ScrapeRequest, *bittorrent.ScrapeResponse) (context.Context, error) }
Hook abstracts the concept of anything that needs to interact with a BitTorrent client's request and response to a BitTorrent tracker. PreHooks and PostHooks both use the same interface.
A Hook can implement stop.Stopper if clean shutdown is required.
func HooksFromHookConfigs ¶
func HooksFromHookConfigs(cfgs []HookConfig) (hooks []Hook, err error)
HooksFromHookConfigs is a utility function for initializing Hooks in bulk.
type HookConfig ¶
type HookConfig struct { Name string `yaml:"name"` Options map[string]interface{} `yaml:"options"` }
HookConfig is the generic configuration format used for all registered Hooks.
type Logic ¶
type Logic struct {
// contains filtered or unexported fields
}
Logic is an implementation of the TrackerLogic that functions by executing a series of middleware hooks.
func NewLogic ¶
func NewLogic(cfg ResponseConfig, peerStore storage.PeerStore, preHooks, postHooks []Hook) *Logic
NewLogic creates a new instance of a TrackerLogic that executes the provided middleware hooks.
func (*Logic) AfterAnnounce ¶
func (l *Logic) AfterAnnounce(ctx context.Context, req *bittorrent.AnnounceRequest, resp *bittorrent.AnnounceResponse)
AfterAnnounce does something with the results of an Announce after it has been completed.
func (*Logic) AfterScrape ¶
func (l *Logic) AfterScrape(ctx context.Context, req *bittorrent.ScrapeRequest, resp *bittorrent.ScrapeResponse)
AfterScrape does something with the results of a Scrape after it has been completed.
func (*Logic) HandleAnnounce ¶
func (l *Logic) HandleAnnounce(ctx context.Context, req *bittorrent.AnnounceRequest) (_ context.Context, resp *bittorrent.AnnounceResponse, err error)
HandleAnnounce generates a response for an Announce.
func (*Logic) HandleScrape ¶
func (l *Logic) HandleScrape(ctx context.Context, req *bittorrent.ScrapeRequest) (_ context.Context, resp *bittorrent.ScrapeResponse, err error)
HandleScrape generates a response for a Scrape.
type ResponseConfig ¶
type ResponseConfig struct { AnnounceInterval time.Duration `yaml:"announce_interval"` MinAnnounceInterval time.Duration `yaml:"min_announce_interval"` }
ResponseConfig holds the configuration used for the actual response.
TODO(jzelinskie): Evaluate whether we would like to make this optional. We can make Chihaya extensible enough that you can program a new response generator at the cost of making it possible for users to create config that won't compose a functional tracker.
Directories ¶
Path | Synopsis |
---|---|
Package clientapproval implements a Hook that fails an Announce based on a whitelist or blacklist of BitTorrent client IDs.
|
Package clientapproval implements a Hook that fails an Announce based on a whitelist or blacklist of BitTorrent client IDs. |
Package jwt implements a Hook that fails an Announce if the client's request is missing a valid JSON Web Token.
|
Package jwt implements a Hook that fails an Announce if the client's request is missing a valid JSON Web Token. |
pkg
|
|
random
Package random implements the XORShift PRNG and a way to derive random state from an AnnounceRequest.
|
Package random implements the XORShift PRNG and a way to derive random state from an AnnounceRequest. |
Package torrentapproval implements a Hook that fails an Announce based on a whitelist or blacklist of torrent hash.
|
Package torrentapproval implements a Hook that fails an Announce based on a whitelist or blacklist of torrent hash. |
Package varinterval provides a middleware implementation that handles announcement intervals according to configured ranges, giving different values for each peer so they don't re-announce at the same time.
|
Package varinterval provides a middleware implementation that handles announcement intervals according to configured ranges, giving different values for each peer so they don't re-announce at the same time. |