Documentation
¶
Overview ¶
Package middleware implements the Logic interface by executing a series of middleware hooks.
Index ¶
- Variables
- func RegisterBuilder(name string, b Builder)
- type Builder
- type Hook
- 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) Ping(ctx context.Context) (err error)
- type Pinger
Constants ¶
This section is empty.
Variables ¶
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 RegisterBuilder ¶
RegisterBuilder makes a Builder available by the provided name.
If called twice with the same name, the name is blank, or if the provided Builder is nil, this function panics.
Types ¶
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 NewHooks ¶
func NewHooks(configs []conf.NamedMapConfig, storage storage.PeerStorage) (hooks []Hook, err error)
NewHooks is a utility function for initializing Hooks in bulk.
type Logic ¶
type Logic struct {
// contains filtered or unexported fields
}
Logic used by a frontend in order to: (1) generate a response from a parsed request, and (2) asynchronously observe anything after the response has been delivered to the client.
func NewLogic ¶
func NewLogic(annInterval, minAnnInterval time.Duration, peerStore storage.PeerStorage, preHooks, postHooks []Hook) *Logic
NewLogic creates a new instance of a Logic 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.
Returns the updated context, the generated AnnounceResponse and no error on success; nil and error on failure.
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.
Returns the updated context, the generated AnnounceResponse and no error on success; nil and error on failure.
type Pinger ¶ added in v0.0.2
Pinger is an optional interface that may be implemented by a pre Hook to check if it is operational. Used in frontend.Logic.
It may be useful in cases when Hook performs foreign requests to some external resources (i.e. storage) and `ping` request should also check resource availability.
Directories
¶
Path | Synopsis |
---|---|
Package clientapproval XXX: implementation is broken, client ID is NOT 6 static bytes refer: - https://wiki.theory.org/BitTorrentSpecification#peer_id - https://github.com/webtorrent/bittorrent-peerid/blob/master/lib/utils.js
|
Package clientapproval XXX: implementation is broken, client ID is NOT 6 static bytes refer: - https://wiki.theory.org/BitTorrentSpecification#peer_id - https://github.com/webtorrent/bittorrent-peerid/blob/master/lib/utils.js |
Package jwt implements a Hook that fails on Announce or Scrape if the client's request is missing a valid JSON Web Token.
|
Package jwt implements a Hook that fails on Announce or Scrape if the client's request is missing a valid JSON Web Token. |
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. |
container
Package container contains interface and register used for torrent approval hash source
|
Package container contains interface and register used for torrent approval hash source |
container/directory
Package directory implements container which checks if hash present in any of torrent file placed in some directory.
|
Package directory implements container which checks if hash present in any of torrent file placed in some directory. |
container/list
Package list implements container with pre-defined list of torrent hashes from config file
|
Package list implements container with pre-defined list of torrent hashes from config file |
Package varinterval contains interval variation middleware
|
Package varinterval contains interval variation middleware |