middleware

package
v0.0.0-...-0b2e9e9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2020 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package middleware implements the TrackerLogic interface by executing a series of middleware hooks.

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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.

View Source
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.

View Source
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

func RegisterDriver(name string, d Driver)

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

type Driver interface {
	NewHook(options []byte) (Hook, error)
}

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

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.

func New

func New(name string, optionBytes []byte) (Hook, error)

New attempts to initialize a new middleware instance from the list of registered Drivers.

If a driver does not exist, returns ErrDriverDoesNotExist.

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.

func (*Logic) Stop

func (l *Logic) Stop() stop.Result

Stop stops the Logic.

This stops any hooks that implement stop.Stopper.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL