Documentation
¶
Overview ¶
Package udp implements a BitTorrent tracker via the UDP protocol as described in BEP 15.
Index ¶
- func ParseAnnounce(r Request, v6Action bool, opts frontend.ParseOptions) (*bittorrent.AnnounceRequest, error)
- func ParseScrape(r Request, opts frontend.ParseOptions) (*bittorrent.ScrapeRequest, error)
- 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 Request
- type ResponseWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseAnnounce ¶
func ParseAnnounce(r Request, v6Action bool, opts frontend.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 frontend.ParseOptions) (*bittorrent.ScrapeRequest, error)
ParseScrape parses a ScrapeRequest from a UDP request.
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 PrivateKey string `cfg:"private_key"` MaxClockSkew time.Duration `cfg:"max_clock_skew"` EnableRequestTiming bool `cfg:"enable_request_timing"` frontend.ParseOptions }
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 ¶
NewFrontend creates a new instance of an UDP Frontend that asynchronously serves requests.
type ResponseWriter ¶
type ResponseWriter struct {
// contains filtered or unexported fields
}
ResponseWriter implements the ability to respond to a Request via the io.Writer interface.