tracker

package
v1.12.15 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package tracker provides support for announcing torrents to HTTP and UDP trackers.

Index

Constants

This section is empty.

Variables

View Source
var ErrDecode = errors.New("cannot decode response")

ErrDecode is returned from Tracker.Announce method when there is problem with the encoding of response.

Functions

func DecodePeersCompact

func DecodePeersCompact(b []byte) ([]*net.TCPAddr, error)

DecodePeersCompact parses and returns addresses for list of CompactPeers.

Types

type AnnounceRequest

type AnnounceRequest struct {
	Torrent Torrent
	Event   Event
	NumWant int
}

AnnounceRequest contains the parameters that are sent in an announce request to trackers.

type AnnounceResponse

type AnnounceResponse struct {
	Interval       time.Duration
	MinInterval    time.Duration
	Leechers       int32
	Seeders        int32
	WarningMessage string
	Peers          []*net.TCPAddr
}

AnnounceResponse contains fields from a response to announce request.

type CompactPeer

type CompactPeer struct {
	IP   [net.IPv4len]byte
	Port uint16
}

CompactPeer is a struct value which consist of a 4-bytes IP address and a 2-bytes port value. CompactPeer can be used as a key in maps because it does not contain any pointers.

func NewCompactPeer

func NewCompactPeer(addr *net.TCPAddr) CompactPeer

NewCompactPeer returns a new CompactPeer from a net.TCPAddr.

func (CompactPeer) Addr

func (p CompactPeer) Addr() *net.TCPAddr

Addr returns a net.TCPAddr from CompactPeer.

func (CompactPeer) MarshalBinary

func (p CompactPeer) MarshalBinary() ([]byte, error)

MarshalBinary returns the bytes.

func (*CompactPeer) UnmarshalBinary

func (p *CompactPeer) UnmarshalBinary(data []byte) error

UnmarshalBinary reads bytes from a slice into the CompactPeer.

type Error

type Error struct {
	FailureReason string
	RetryIn       time.Duration
}

Error is the string that is sent by the tracker from announce or scrape.

func (*Error) Error

func (e *Error) Error() string

type Event

type Event int32

Event type that is sent in an announce request.

const (
	EventNone Event = iota
	EventCompleted
	EventStarted
	EventStopped
)

Tracker Announce Events. Numbers corresponds to constants in UDP tracker protocol.

func (Event) String

func (e Event) String() string

String returns the name of event as represented in HTTP tracker protocol.

type Tier added in v0.8.0

type Tier struct {
	Trackers []Tracker
	// contains filtered or unexported fields
}

Tier implements the Tracker interface and contains multiple Trackers which tries to announce to the working Tracker.

func NewTier added in v0.8.0

func NewTier(trackers []Tracker) *Tier

NewTier returns a new Tier.

func (*Tier) Announce added in v0.8.0

func (t *Tier) Announce(ctx context.Context, req AnnounceRequest) (*AnnounceResponse, error)

Announce a torrent to the tracker. If annouce fails, the next announce will be made to the next Tracker in the tier.

func (*Tier) URL added in v0.8.0

func (t *Tier) URL() string

URL returns the current Tracker in the Tier.

type Torrent

type Torrent struct {
	BytesUploaded   int64
	BytesDownloaded int64
	BytesLeft       int64
	InfoHash        [20]byte
	PeerID          [20]byte
	Port            int
}

Torrent contains fields that are sent in an announce request.

type Tracker

type Tracker interface {
	// Announce transfer to the tracker.
	// Announce should be called periodically with the interval returned in AnnounceResponse.
	// Announce should also be called on specific events.
	Announce(ctx context.Context, req AnnounceRequest) (*AnnounceResponse, error)

	// URL of the tracker.
	URL() string
}

Tracker tracks the IP address of peers of a Torrent swarm.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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