Documentation
¶
Overview ¶
Package udp implements a BitTorrent tracker via the UDP protocol as described in BEP 15.
Index ¶
- func NewConnectionID(ip net.IP, now time.Time, key string) []byte
- func ParseAnnounce(r Request, v6Action bool, opts ParseOptions) (*bittorrent.AnnounceRequest, error)
- func ParseScrape(r Request, opts ParseOptions) (*bittorrent.ScrapeRequest, error)
- func ValidConnectionID(connectionID []byte, ip net.IP, now time.Time, maxClockSkew time.Duration, ...) bool
- func WriteAnnounce(w io.Writer, txID []byte, resp *bittorrent.AnnounceResponse, ...)
- func WriteConnectionID(w io.Writer, txID, connID []byte)
- func WriteError(w io.Writer, txID []byte, err error)
- func WriteScrape(w io.Writer, txID []byte, resp *bittorrent.ScrapeResponse)
- type Config
- type ConnectionIDGenerator
- type Frontend
- type ParseOptions
- type Request
- type ResponseWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewConnectionID ¶
NewConnectionID creates an 8-byte connection identifier for UDP packets as described by BEP 15. This is a wrapper around creating a new ConnectionIDGenerator and generating an ID. It is recommended to use the generator for performance.
func ParseAnnounce ¶
func ParseAnnounce(r Request, v6Action bool, opts ParseOptions) (*bittorrent.AnnounceRequest, error)
ParseAnnounce parses an AnnounceRequest from a UDP request.
If v6Action is true, the announce is parsed the "old opentracker way": https://web.archive.org/web/20170503181830/http://opentracker.blog.h3q.com/2007/12/28/the-ipv6-situation/
func ParseScrape ¶
func ParseScrape(r Request, opts ParseOptions) (*bittorrent.ScrapeRequest, error)
ParseScrape parses a ScrapeRequest from a UDP request.
func ValidConnectionID ¶
func ValidConnectionID(connectionID []byte, ip net.IP, now time.Time, maxClockSkew time.Duration, key string) bool
ValidConnectionID determines whether a connection identifier is legitimate. This is a wrapper around creating a new ConnectionIDGenerator and validating the ID. It is recommended to use the generator for performance.
func WriteAnnounce ¶
func WriteAnnounce(w io.Writer, txID []byte, resp *bittorrent.AnnounceResponse, v6Action, v6Peers bool)
WriteAnnounce encodes an announce response according to BEP 15. The peers returned will be resp.IPv6Peers or resp.IPv4Peers, depending on whether v6Peers is set. If v6Action is set, the action will be 4, according to https://web.archive.org/web/20170503181830/http://opentracker.blog.h3q.com/2007/12/28/the-ipv6-situation/
func WriteConnectionID ¶
WriteConnectionID encodes a new connection response according to BEP 15.
func WriteError ¶
WriteError writes the failure reason as a null-terminated string.
func WriteScrape ¶
func WriteScrape(w io.Writer, txID []byte, resp *bittorrent.ScrapeResponse)
WriteScrape encodes a scrape response according to BEP 15.
Types ¶
type Config ¶
type Config struct { Addr string `yaml:"addr"` PrivateKey string `yaml:"private_key"` MaxClockSkew time.Duration `yaml:"max_clock_skew"` EnableRequestTiming bool `yaml:"enable_request_timing"` ParseOptions `yaml:",inline"` }
Config represents all of the configurable options for a UDP BitTorrent Tracker.
type ConnectionIDGenerator ¶
type ConnectionIDGenerator struct {
// contains filtered or unexported fields
}
A ConnectionIDGenerator is a reusable generator and validator for connection IDs as described in BEP 15. It is not thread safe, but is safe to be pooled and reused by other goroutines. It manages its state itself, so it can be taken from and returned to a pool without any cleanup. After initial creation, it can generate connection IDs without allocating. See Generate and Validate for usage notes and guarantees.
func NewConnectionIDGenerator ¶
func NewConnectionIDGenerator(key string) *ConnectionIDGenerator
NewConnectionIDGenerator creates a new connection ID generator.
func (*ConnectionIDGenerator) Generate ¶
Generate generates an 8-byte connection ID as described in BEP 15 for the given IP and the current time.
The first 4 bytes of the connection identifier is a unix timestamp and the last 4 bytes are a truncated HMAC token created from the aforementioned unix timestamp and the source IP address of the UDP packet.
Truncated HMAC is known to be safe for 2^(-n) where n is the size in bits of the truncated HMAC token. In this use case we have 32 bits, thus a forgery probability of approximately 1 in 4 billion.
The generated ID is written to g.connID, which is also returned. g.connID will be reused, so it must not be referenced after returning the generator to a pool and will be overwritten be subsequent calls to Generate!
type Frontend ¶
type Frontend struct { Config // contains filtered or unexported fields }
Frontend holds the state of a UDP BitTorrent Frontend.
func NewFrontend ¶
func NewFrontend(logic frontend.TrackerLogic, provided Config) (*Frontend, error)
NewFrontend creates a new instance of an UDP Frontend that asynchronously serves requests.
type ParseOptions ¶
type ParseOptions struct { AllowIPSpoofing bool `yaml:"allow_ip_spoofing"` 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 params will be used.
type ResponseWriter ¶
type ResponseWriter struct {
// contains filtered or unexported fields
}
ResponseWriter implements the ability to respond to a Request via the io.Writer interface.