Documentation ¶
Overview ¶
Package models implements the common data types used throughout a BitTorrent tracker.
Index ¶
- Variables
- func AppendPeer(ipv4s, ipv6s *PeerList, ann *Announce, peer *Peer) int
- func IsPublicError(err error) bool
- type Announce
- type AnnounceDelta
- type AnnounceResponse
- type ClientError
- type Endpoint
- type NotFoundError
- type Peer
- type PeerKey
- type PeerList
- type PeerMap
- func (pm *PeerMap) AppendPeers(ipv4s, ipv6s PeerList, ann *Announce, wanted int) (PeerList, PeerList)
- func (pm *PeerMap) Contains(pk PeerKey) bool
- func (pm *PeerMap) Delete(pk PeerKey)
- func (pm *PeerMap) Len() int
- func (pm *PeerMap) LookUp(pk PeerKey) (peer Peer, exists bool)
- func (pm *PeerMap) Purge(unixtime int64)
- func (pm *PeerMap) Put(p Peer)
- type ProtocolError
- type Scrape
- type ScrapeResponse
- type Torrent
- type User
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMalformedRequest is returned when a request does not contain the // required parameters needed to create a model. ErrMalformedRequest = ClientError("malformed request") // ErrBadRequest is returned when a request is invalid in the peer's // current state. For example, announcing a "completed" event while // not a leecher or a "stopped" event while not active. ErrBadRequest = ClientError("bad request") // ErrUserDNE is returned when a user does not exist. ErrUserDNE = NotFoundError("user does not exist") // ErrTorrentDNE is returned when a torrent does not exist. ErrTorrentDNE = NotFoundError("torrent does not exist") // ErrClientUnapproved is returned when a clientID is not in the whitelist. ErrClientUnapproved = ClientError("client is not approved") // ErrInvalidPasskey is returned when a passkey is not properly formatted. ErrInvalidPasskey = ClientError("passkey is invalid") )
Functions ¶
func AppendPeer ¶
AppendPeer adds a peer to its corresponding peerlist.
func IsPublicError ¶
IsPublicError determines whether an error should be propogated to the client.
Types ¶
type Announce ¶
type Announce struct { Config *config.Config `json:"config"` Compact bool `json:"compact"` Downloaded uint64 `json:"downloaded"` Event string `json:"event"` IPv4 Endpoint `json:"ipv4"` IPv6 Endpoint `json:"ipv6"` Infohash string `json:"infohash"` Left uint64 `json:"left"` NumWant int `json:"numwant"` Passkey string `json:"passkey"` PeerID string `json:"peer_id"` Uploaded uint64 `json:"uploaded"` Torrent *Torrent `json:"-"` User *User `json:"-"` Peer *Peer `json:"-"` PeerV4 *Peer `json:"-"` // Only valid if HasIPv4() is true. PeerV6 *Peer `json:"-"` // Only valid if HasIPv6() is true. }
Announce is an Announce by a Peer.
func (*Announce) BuildPeer ¶
BuildPeer creates the Peer representation of an Announce. When provided nil for the user or torrent parameter, it creates a Peer{UserID: 0} or Peer{TorrentID: 0}, respectively. BuildPeer creates one peer for each IP in the announce, and panics if there are none.
func (*Announce) ClientID ¶
ClientID returns the part of a PeerID that identifies a Peer's client software.
type AnnounceDelta ¶
type AnnounceDelta struct { Peer *Peer Torrent *Torrent User *User // Created is true if this announce created a new peer or changed an existing // peer's address Created bool // Snatched is true if this announce completed the download Snatched bool // Uploaded contains the upload delta for this announce, in bytes Uploaded uint64 RawUploaded uint64 // Downloaded contains the download delta for this announce, in bytes Downloaded uint64 RawDownloaded uint64 }
AnnounceDelta contains the changes to a Peer's state. These changes are recorded by the backend driver.
type AnnounceResponse ¶
type AnnounceResponse struct { Announce *Announce Complete, Incomplete int Interval, MinInterval time.Duration IPv4Peers, IPv6Peers PeerList Compact bool }
AnnounceResponse contains the information needed to fulfill an announce.
type ClientError ¶
type ClientError string
func (ClientError) Error ¶
func (e ClientError) Error() string
type Endpoint ¶
type Endpoint struct { // Always has length net.IPv4len if IPv4, and net.IPv6len if IPv6 IP net.IP `json:"ip"` Port uint16 `json:"port"` }
Endpoint is an IP and port pair.
type NotFoundError ¶
type NotFoundError ClientError
func (NotFoundError) Error ¶
func (e NotFoundError) Error() string
type Peer ¶
type Peer struct { ID string `json:"id"` UserID uint64 `json:"user_id"` TorrentID uint64 `json:"torrent_id"` Uploaded uint64 `json:"uploaded"` Downloaded uint64 `json:"downloaded"` Left uint64 `json:"left"` LastAnnounce int64 `json:"last_announce"` Endpoint }
Peer is a participant in a swarm.
func (*Peer) HasIPv4 ¶
HasIPv4 determines if a peer's IP address can be represented as an IPv4 address.
type PeerKey ¶
type PeerKey string
PeerKey is the key used to uniquely identify a peer in a swarm.
func NewPeerKey ¶
NewPeerKey creates a properly formatted PeerKey.
type PeerList ¶
type PeerList []Peer
PeerList represents a list of peers: either seeders or leechers.
type PeerMap ¶
type PeerMap struct { Peers map[string]map[PeerKey]Peer `json:"peers"` Seeders bool `json:"seeders"` Config config.SubnetConfig `json:"config"` Size int32 `json:"size"` sync.RWMutex }
PeerMap is a thread-safe map from PeerKeys to Peers. When PreferredSubnet is enabled, it is a thread-safe map of maps from MaskedIPs to Peerkeys to Peers.
func NewPeerMap ¶
NewPeerMap initializes the map for a new PeerMap.
func (*PeerMap) AppendPeers ¶
func (pm *PeerMap) AppendPeers(ipv4s, ipv6s PeerList, ann *Announce, wanted int) (PeerList, PeerList)
AppendPeers adds peers to given IPv4 or IPv6 lists.
type ProtocolError ¶
type ProtocolError ClientError
func (ProtocolError) Error ¶
func (e ProtocolError) Error() string
type ScrapeResponse ¶
type ScrapeResponse struct {
Files []*Torrent
}
ScrapeResponse contains the information needed to fulfill a scrape.
type Torrent ¶
type Torrent struct { ID uint64 `json:"id"` Infohash string `json:"infohash"` Seeders *PeerMap `json:"seeders"` Leechers *PeerMap `json:"leechers"` Snatches uint64 `json:"snatches"` UpMultiplier float64 `json:"up_multiplier"` DownMultiplier float64 `json:"down_multiplier"` LastAction int64 `json:"last_action"` }
Torrent is a swarm for a given torrent file.