middleware

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

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 RegisterBuilder

func RegisterBuilder(name string, b Builder)

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 Builder

type Builder func(conf.MapConfig, storage.PeerStorage) (Hook, error)

Builder is the function used to initialize a new Hook with provided 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 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.

func (*Logic) Ping added in v0.0.2

func (l *Logic) Ping(ctx context.Context) (err error)

Ping executes checks if all Hook-s are operational

type Pinger added in v0.0.2

type Pinger interface {
	Ping(ctx context.Context) error
}

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

Jump to

Keyboard shortcuts

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