Documentation
¶
Overview ¶
Package udp implements a BitTorrent tracker via the UDP protocol as described in BEP 15.
Index ¶
Constants ¶
const (
// Name - registered name of the frontend
Name = "udp"
)
Variables ¶
var ErrInvalidQueryEscape = bittorrent.ClientError("invalid query escape")
ErrInvalidQueryEscape is returned when a query string contains invalid escapes.
Functions ¶
func NewFrontend ¶
NewFrontend builds and starts udp bittorrent frontend from provided configuration
Types ¶
type Config ¶
type Config struct { frontend.ListenOptions PrivateKey string `cfg:"private_key"` MaxClockSkew time.Duration `cfg:"max_clock_skew"` frontend.ParseOptions }
Config represents all 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 []byte, maxClockSkew time.Duration) *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 byte is random salt, next 2 bytes - truncated unix timestamp when ID was generated, last 5 bytes are a truncated HMAC token created from salt (1 byte), full unix timestamp (8 bytes) and source IP (4/16 bytes).
Salt used to mitigate generation same MAC if there are several clients from same IP sent requests within one second.
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 40 bits, thus a forgery probability of approximately 1 in 4 billion.
The generated ID is written to g.buffer, which is also returned. g.buffer 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 ResponseWriter ¶
type ResponseWriter struct {
// contains filtered or unexported fields
}
ResponseWriter implements the ability to respond to a Request via the io.Writer interface.