udp

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolID     = 0x41727101980
	ConnectAction  = 0x00
	AnnounceAction = 0x01
	ScrapeAction   = 0x02
	ErrorAction    = 0x03

	// Connection ID timeout (2 minutes as per BEP 15)
	ConnectionTimeout = 2 * time.Minute

	// Default announce interval
	DefaultInterval = 1800 // 30 minutes
)

BEP 15 protocol constants

Variables

This section is empty.

Functions

This section is empty.

Types

type AnnounceRequest

type AnnounceRequest struct {
	ConnectionID  uint64
	Action        uint32
	TransactionID uint32
	InfoHash      dht.Key
	PeerID        dht.Key
	Downloaded    uint64
	Left          uint64
	Uploaded      uint64
	Event         uint32
	IP            uint32
	Key           uint32
	NumWant       int32
	Port          uint16
}

AnnounceRequest represents a UDP announce request according to BEP 15

type Client

type Client struct {
	// Timeout for each round-trip (connect + announce/scrape). Default: 15s.
	Timeout time.Duration
}

Client is a UDP BitTorrent tracker client (BEP 15).

func NewClient

func NewClient(timeout time.Duration) *Client

NewClient returns a UDP tracker client with the given per-request timeout.

func (*Client) Announce

Announce sends an announce to the UDP tracker at addr ("host:port").

func (*Client) Scrape

func (c *Client) Scrape(ctx context.Context, addr string, req *tracker.ScrapeRequest) (*tracker.ScrapeResponse, error)

Scrape sends a scrape to the UDP tracker at addr.

type PeerInfo

type PeerInfo struct {
	IP       net.IP
	Port     uint16
	Left     uint64 // Bytes left to download (0 = seeder)
	LastSeen time.Time
}

PeerInfo stores information about a peer for UDP tracker

func (*PeerInfo) IsSeeder

func (p *PeerInfo) IsSeeder() bool

IsSeeder returns true if the peer has completed the download

type ScrapeFileInfo

type ScrapeFileInfo struct {
	Seeders   int32
	Completed int32
	Leechers  int32
}

ScrapeFileInfo represents file information in scrape response

type ScrapeRequest

type ScrapeRequest struct {
	ConnectionID  uint64
	Action        uint32
	TransactionID uint32
	InfoHashes    []string
}

ScrapeRequest represents a UDP scrape request according to BEP 15

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents a UDP BitTorrent tracker server (BEP 15)

func NewServer

func NewServer(config *ServerConfig) *Server

NewServer creates a new UDP tracker server

func (*Server) GetStats

func (s *Server) GetStats() *ServerStats

GetStats returns current server statistics

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown gracefully shuts down the server

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start starts the UDP tracker server

type ServerConfig

type ServerConfig struct {
	Port             int
	Storage          string
	AnnounceInterval int
	MaxPeers         int
	EnableStats      bool
}

ServerConfig holds configuration for UDP tracker server

type ServerStats

type ServerStats struct {
	TotalConnections  int64
	ActiveConnections int
	TotalAnnounces    int64
	TotalScrapes      int64
	ActiveTorrents    int
	TotalPeers        int64
	StartTime         time.Time
}

ServerStats tracks UDP tracker statistics

type TorrentInfo

type TorrentInfo struct {
	InfoHash    string
	Seeders     int
	Leechers    int
	Completed   int64
	LastUpdated time.Time
	Peers       []*PeerInfo
	// contains filtered or unexported fields
}

TorrentInfo stores information about a torrent for UDP tracker

Jump to

Keyboard shortcuts

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