tracker

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnnounceRequest

type AnnounceRequest struct {
	InfoHash   dht.Key // BEP 3: 20-byte SHA-1 info hash (urlencoded)
	PeerID     dht.Key // BEP 3: 20-byte peer ID (urlencoded)
	Port       uint16  // BEP 3: port this client is listening on
	Uploaded   int64   // BEP 3: total bytes uploaded since "started" event
	Downloaded int64   // BEP 3: total bytes downloaded since "started" event
	Left       int64   // BEP 3: bytes remaining to download
	Compact    bool    // BEP 23: request compact peer list (6 bytes per peer)
	NoPeerID   bool    // BEP 3: omit peer_id in responses (compact implies this)
	Event      Event   // BEP 3: started/stopped/completed or empty
	NumWant    int     // BEP 3: number of peers requested (tracker may ignore)
}

AnnounceRequest contains parameters for tracker announce. BEP 3 §Tracker Request: all fields map to tracker query parameters.

type AnnounceResponse

type AnnounceResponse struct {
	Interval    int64  // BEP 3: seconds client should wait before next announce
	MinInterval int64  // BEP 3: optional minimum re-announce interval
	TrackerID   string // BEP 3: optional tracker identifier for future announces
	Complete    int64  // BEP 3: number of seeders
	Incomplete  int64  // BEP 3: number of leechers
	Peers       []Peer // BEP 3/23: peer list (compact or dict format)
	ExternalIP  net.IP // BEP 24: client's public IP as seen by the tracker (may be nil)
}

AnnounceResponse represents the tracker's response. BEP 3 §Tracker Response: bencoded dictionary with peer list and timing.

type Client

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

Client handles communication with BitTorrent trackers

func NewClient

func NewClient(timeout time.Duration) *Client

NewClient creates a new tracker client

func (*Client) Announce

func (c *Client) Announce(trackerURL string, req *AnnounceRequest) (*AnnounceResponse, error)

Announce sends an announce request to a tracker

func (*Client) Scrape

func (c *Client) Scrape(trackerURL string, req *ScrapeRequest) (*ScrapeResponse, error)

Scrape sends a scrape request to a tracker

type Event

type Event string

Event represents the event type for tracker announces. BEP 3 §Tracker Request: event is optional; if not present, it's a regular re-announce.

const (
	EventNone      Event = ""          // BEP 3: regular re-announce (no event key sent)
	EventStarted   Event = "started"   // BEP 3: first announce for this download
	EventStopped   Event = "stopped"   // BEP 3: client is shutting down gracefully
	EventCompleted Event = "completed" // BEP 3: download completed (leecher → seeder)
)

type Peer

type Peer struct {
	IP   net.IP
	Port uint16
	ID   []byte
}

Peer represents a peer returned by the tracker

type PeerAddr

type PeerAddr struct {
	IP   net.IP
	Port uint16
}

PeerAddr implements net.Addr for a peer

func (*PeerAddr) Network

func (p *PeerAddr) Network() string

Network returns the network type

func (*PeerAddr) String

func (p *PeerAddr) String() string

String returns the peer address as a string IPv6 addresses are wrapped in brackets per RFC 3986

type ScrapeRequest

type ScrapeRequest struct {
	InfoHashes []dht.Key // Can scrape multiple torrents (up to ~74 for UDP)
}

ScrapeRequest contains parameters for tracker scrape

type ScrapeResponse

type ScrapeResponse struct {
	Files map[string]ScrapeStats // Key is hex-encoded info hash
}

ScrapeResponse represents the tracker's scrape response

type ScrapeStats

type ScrapeStats struct {
	Complete   int64 // Number of seeders
	Downloaded int64 // Number of complete downloads (peers that completed)
	Incomplete int64 // Number of leechers
}

ScrapeStats contains statistics for a single torrent

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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