Documentation ¶
Index ¶
- Constants
- func CheckHmac(secret, hash string) bool
- func DecodeInfoDict(bencodedInfo []byte) (map[string]interface{}, error)
- type BenPeer
- type Peer
- type PeerMap
- type PeerStatus
- type Torrent
- func (t *Torrent) AddPeer(peerId, ipAddr, port, secret string)
- func (t *Torrent) EnumeratePeers() (int, int)
- func (t *Torrent) GetPeerList(numWant int) (string, string)
- func (t *Torrent) ReadPeers(closure func(map[string]*Peer))
- func (t *Torrent) UpdateStatsFor(peerId string, uploaded, downloaded, left string) error
- func (t *Torrent) WritePeers(closure func(map[string]*Peer))
- type TorrentFile
Constants ¶
const ( MIN_PEER_THRESHOLD = 30 DEFAULT_NUMWANT = 30 )
Performance tuning constants.
const ( SEEDING PeerStatus = iota // Announced a complete copy of the file. LEECHING = iota // Announced an incomplete copy of the file. QUASI = iota // Announced an incomplete copy; but does not appear to be downloading. )
Variables ¶
This section is empty.
Functions ¶
func CheckHmac ¶
Compares a message (the secret) and an HMAC of that message against a secret-key.
This ensures that the .torrent file originated from this tracker and is linked to an active user account.
The secret and hash are []byte arrays and stored as such. They must be deserialized
func DecodeInfoDict ¶
Types ¶
type BenPeer ¶
type BenPeer struct { ID string `bencode:"peer id"` IP string `bencode:"ip"` Port int64 `bencode:"port"` }
Simpler data structured used for non-compact peer lists.
type Peer ¶
type Peer struct { ID string IPAddr net.IP Port uint16 Status PeerStatus // what is the peer doing? DownloadedBytes int64 // curently completed bytes UploadedBytes int64 // currently uploaded bytes LeftBytes int64 // number of bytes remaining LastSeen time.Time // last announce at: LastCompleteBytes int64 // last completed bytes Secret string // uniquely identifies a peer }
A peer being tracked on a torrent
func (*Peer) EncodePeer ¶
Returns a bencodable version of this peer.
func (*Peer) UpdateLastSeen ¶
func (p *Peer) UpdateLastSeen()
Updates timestamp to current server time.
func (*Peer) UpdateStats ¶
Updates download statistics and promotes the peer if necessary. Strings should be ASCII encoded base 10 numbers. (Per bep-003)
type PeerMap ¶
type PeerMap struct {
// contains filtered or unexported fields
}
A protected mapping of peerIds to peers.
This map is safe for multiple readers; but read and write calls will block while a writer holds the lock.
type PeerStatus ¶
type PeerStatus int64
type Torrent ¶
type Torrent struct { InfoHash string Info *TorrentFile // contains filtered or unexported fields }
Represents a torrent being actively used by the tracker. A torrent includes a [decoded] copy of the metainfo file as well as a list of active peers that is periodically culled.
func NewTorrent ¶
func NewTorrent(file *TorrentFile) *Torrent
Writes a new torrent to be used by the tracker for maintaining peer lists.
func ReadFile ¶
Reads a torrent-file from the filesystem. TODO: Model will create torrent-file; obsoleting this.
func (*Torrent) EnumeratePeers ¶
Returns the seeders followed by the leechers for this torrent.
func (*Torrent) GetPeerList ¶
Send numWant -1 for "no peers requested", 0 for default, and n if client wants more peers. Returns a ranked peerlist that attempts to maintain a balanced ratio of seeders:leechers. First return val is compact-form `peers` dict, second is `peers6` dict.
func (*Torrent) ReadPeers ¶
Takes a closure which will obtain a readlock for this torrent's peer-map.
Reading from the torrent's peer map is safe from within the closure.
func (*Torrent) UpdateStatsFor ¶
Updates the in-memory statistics for a peer being tracked for this torrent. Returns an error if the peer is not found or the request cannot be fulfilled. The stats-collector job will ensure they get written to disk.
func (*Torrent) WritePeers ¶
Takes a closure which will obtain a writelock for this torrents' peer-map.
Updates to the map are safe within the context of the closure.
type TorrentFile ¶
type TorrentFile struct { Announce string `bencode:"announce"` Comment string `bencode:"comment"` CreatedBy string `bencode:"created by"` CreationDate int64 `bencode:"creation date"` Encoding string `bencode:"encoding"` Info map[string]interface{} `bencode:"info"` }
Represents a `babou` torrent. We don't care about other fields so they will be discarded from uploaded torrents.
func (*TorrentFile) BencodeInfoDict ¶
func (t *TorrentFile) BencodeInfoDict() ([]byte, error)
Returns a bencoded version of the torrent's info dict.
func (*TorrentFile) EncodeInfo ¶
func (t *TorrentFile) EncodeInfo() []byte
Encode's the `info` dictionary into a SHA1 hash; used to uniquely identify a torrent.
func (*TorrentFile) EncodeInfoToString ¶
func (t *TorrentFile) EncodeInfoToString() string
Encode's the `info` dictionary into a SHA1 hash; used to uniquely identify a torrent. Converts hash to a string [two chars per byte]
func (*TorrentFile) WriteFile ¶
func (t *TorrentFile) WriteFile(secret, hash []byte) ([]byte, error)
Converts torrent to SUPRA-PRIVATE torrent
Sets the private flag to 1 and embeds the supplied secret and hash for authentication purposes.
This torrent file SHOULD NOT be shared between users or statistics collection and anti-abuse mechanisms will be skewed for that user.