http

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: 13 Imported by: 0

Documentation

Overview

Package http implements a BitTorrent frontend via the HTTP protocol as described in BEP 3 and BEP 23.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseAnnounce

func ParseAnnounce(r *http.Request, opts ParseOptions) (*bittorrent.AnnounceRequest, error)

ParseAnnounce parses an bittorrent.AnnounceRequest from an http.Request.

func ParseScrape

func ParseScrape(r *http.Request, opts ParseOptions) (*bittorrent.ScrapeRequest, error)

ParseScrape parses an bittorrent.ScrapeRequest from an http.Request.

func WriteAnnounceResponse

func WriteAnnounceResponse(w http.ResponseWriter, resp *bittorrent.AnnounceResponse) error

WriteAnnounceResponse communicates the results of an Announce to a BitTorrent client over HTTP.

func WriteError

func WriteError(w http.ResponseWriter, err error) error

WriteError communicates an error to a BitTorrent client over HTTP.

func WriteScrapeResponse

func WriteScrapeResponse(w http.ResponseWriter, resp *bittorrent.ScrapeResponse) error

WriteScrapeResponse communicates the results of a Scrape to a BitTorrent client over HTTP.

Types

type Config

type Config struct {
	Addr                string        `yaml:"addr"`
	HTTPSAddr           string        `yaml:"https_addr"`
	ReadTimeout         time.Duration `yaml:"read_timeout"`
	WriteTimeout        time.Duration `yaml:"write_timeout"`
	IdleTimeout         time.Duration `yaml:"idle_timeout"`
	EnableKeepAlive     bool          `yaml:"enable_keepalive"`
	TLSCertPath         string        `yaml:"tls_cert_path"`
	TLSKeyPath          string        `yaml:"tls_key_path"`
	AnnounceRoutes      []string      `yaml:"announce_routes"`
	ScrapeRoutes        []string      `yaml:"scrape_routes"`
	EnableRequestTiming bool          `yaml:"enable_request_timing"`
	ParseOptions        `yaml:",inline"`
}

Config represents all of the configurable options for an HTTP BitTorrent Frontend.

func (Config) LogFields

func (cfg Config) LogFields() log.Fields

LogFields renders the current config as a set of Logrus fields.

func (Config) Validate

func (cfg Config) Validate() Config

Validate sanity checks values set in a config and returns a new config with default values replacing anything that is invalid.

This function warns to the logger when a value is changed.

type Frontend

type Frontend struct {
	Config
	// contains filtered or unexported fields
}

Frontend represents the state of an HTTP BitTorrent Frontend.

func NewFrontend

func NewFrontend(logic frontend.TrackerLogic, provided Config) (*Frontend, error)

NewFrontend creates a new instance of an HTTP Frontend that asynchronously serves requests.

func (*Frontend) Stop

func (f *Frontend) Stop() stop.Result

Stop provides a thread-safe way to shutdown a currently running Frontend.

type ParseOptions

type ParseOptions struct {
	AllowIPSpoofing     bool   `yaml:"allow_ip_spoofing"`
	RealIPHeader        string `yaml:"real_ip_header"`
	MaxNumWant          uint32 `yaml:"max_numwant"`
	DefaultNumWant      uint32 `yaml:"default_numwant"`
	MaxScrapeInfoHashes uint32 `yaml:"max_scrape_infohashes"`
}

ParseOptions is the configuration used to parse an Announce Request.

If AllowIPSpoofing is true, IPs provided via BitTorrent params will be used. If RealIPHeader is not empty string, the value of the first HTTP Header with that name will be used.

Directories

Path Synopsis
Package bencode implements bencoding of data as defined in BEP 3 using type assertion over reflection for performance.
Package bencode implements bencoding of data as defined in BEP 3 using type assertion over reflection for performance.

Jump to

Keyboard shortcuts

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