Documentation
¶
Overview ¶
Package tracker provides support for announcing torrents to HTTP and UDP trackers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDecode = errors.New("cannot decode response")
ErrDecode is returned from Tracker.Announce method when there is problem with the encoding of response.
Functions ¶
Types ¶
type AnnounceRequest ¶
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 ¶
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 Event ¶
type Event int32
Event type that is sent in an announce request.
Tracker Announce Events. Numbers corresponds to constants in UDP tracker protocol.
type Tier ¶
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 (*Tier) Announce ¶
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.
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.