Documentation ¶
Overview ¶
Package httptracker implements the tracker protocol based on HTTP/HTTPS.
You can use the package to implement a HTTP tracker server to track the information that other peers upload or download the file, or to create a HTTP tracker client to communicate with the HTTP tracker server.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AnnounceRequest ¶
type AnnounceRequest struct { // InfoHash is the sha1 hash of the bencoded form of the info value from the metainfo file. InfoHash metainfo.Hash `bencode:"info_hash"` // BEP 3 // PeerID is the id of the downloader. // // Each downloader generates its own id at random at the start of a new download. PeerID metainfo.Hash `bencode:"peer_id"` // BEP 3 // Uploaded is the total amount uploaded so far, encoded in base ten ascii. Uploaded int64 `bencode:"uploaded"` // BEP 3 // Downloaded is the total amount downloaded so far, encoded in base ten ascii. Downloaded int64 `bencode:"downloaded"` // BEP 3 // Left is the number of bytes this peer still has to download, // encoded in base ten ascii. // // Note that this can't be computed from downloaded and the file length // since it might be a resume, and there's a chance that some of the // downloaded data failed an integrity check and had to be re-downloaded. // // If less than 0, math.MaxInt64 will be used for HTTP trackers instead. Left int64 `bencode:"left"` // BEP 3 // Port is the port that this peer is listening on. // // Common behavior is for a downloader to try to listen on port 6881, // and if that port is taken try 6882, then 6883, etc. and give up after 6889. Port uint16 `bencode:"port"` // BEP 3 // IP is the ip or DNS name which this peer is at, which generally used // for the origin if it's on the same machine as the tracker. // // Optional. IP string `bencode:"ip,omitempty"` // BEP 3 // If not present, this is one of the announcements done at regular intervals. // An announcement using started is sent when a download first begins, // and one using completed is sent when the download is complete. // No completed is sent if the file was complete when started. // Downloaders send an announcement using stopped when they cease downloading. // // Optional Event uint32 `bencode:"event,omitempty"` // BEP 3 // Compact indicates whether it hopes the tracker to return the compact // peer lists. // // Optional Compact bool `bencode:"compact,omitempty"` // BEP 23 // NumWant is the number of peers that the client would like to receive // from the tracker. This value is permitted to be zero. If omitted, // typically defaults to 50 peers. // // See https://wiki.theory.org/index.php/BitTorrentSpecification // // Optional. NumWant int32 `bencode:"numwant,omitempty"` Key int32 `bencode:"key,omitempty"` }
AnnounceRequest is the tracker announce requests.
BEP 3
func (*AnnounceRequest) FromQuery ¶
func (r *AnnounceRequest) FromQuery(vs url.Values) (err error)
FromQuery converts URL Query to itself.
func (AnnounceRequest) ToQuery ¶
func (r AnnounceRequest) ToQuery() (vs url.Values)
ToQuery converts the Request to URL Query.
type AnnounceResponse ¶
type AnnounceResponse struct { FailureReason string `bencode:"failure reason,omitempty"` // Interval is the seconds the downloader should wait before next rerequest. Interval uint32 `bencode:"interval,omitempty"` // BEP 3 // Peers is the list of the peers. Peers Peers `bencode:"peers,omitempty"` // BEP 3, BEP 23 // Peers6 is only used for ipv6 in the compact case. Peers6 Peers6 `bencode:"peers6,omitempty"` // BEP 7 // Complete is the number of peers with the entire file. Complete uint32 `bencode:"complete,omitempty"` // Incomplete is the number of non-seeder peers. Incomplete uint32 `bencode:"incomplete,omitempty"` // TrackerID is that the client should send back on its next announcements. // If absent and a previous announce sent a tracker id, // do not discard the old value; keep using it. TrackerID string `bencode:"tracker id,omitempty"` }
AnnounceResponse is a announce response.
type Client ¶
Client represents a tracker client based on HTTP/HTTPS.
func NewClient ¶
NewClient returns a new HTTPClient.
scrapeURL may be empty, which will replace the "announce" in announceURL with "scrape" to generate the scrapeURL.
func (*Client) Announce ¶
func (t *Client) Announce(c context.Context, req *AnnounceRequest) (resp AnnounceResponse, err error)
Announce sends a Announce request to the tracker.
type Peer ¶
type Peer struct { // ID is the peer's self-selected ID. ID string `bencode:"peer id"` // BEP 3 // IP is the IP address or dns name. IP string `bencode:"ip"` // BEP 3 Port uint16 `bencode:"port"` // BEP 3 }
Peer is a tracker peer.
type Peers ¶
type Peers []Peer
Peers is a set of the peers.
func (Peers) MarshalBencode ¶
MarshalBencode implements the interface bencode.Marshaler.
func (*Peers) UnmarshalBencode ¶
UnmarshalBencode implements the interface bencode.Unmarshaler.
type Peers6 ¶
type Peers6 []Peer
Peers6 is a set of the peers for IPv6 in the compact case.
BEP 7
func (Peers6) MarshalBencode ¶
MarshalBencode implements the interface bencode.Marshaler.
func (*Peers6) UnmarshalBencode ¶
UnmarshalBencode implements the interface bencode.Unmarshaler.
type ScrapeResponse ¶
type ScrapeResponse struct { FailureReason string `bencode:"failure_reason,omitempty"` Files map[metainfo.Hash]ScrapeResponseResult `bencode:"files,omitempty"` }
ScrapeResponse represents a Scrape response.
BEP 48
func (*ScrapeResponse) DecodeFrom ¶
func (sr *ScrapeResponse) DecodeFrom(r io.Reader) (err error)
DecodeFrom reads the []byte data from r and decodes them to sr by bencode.
r may be the body of the request from the http client.
type ScrapeResponseResult ¶
type ScrapeResponseResult struct { // Complete is the number of active peers that have completed downloading. Complete uint32 `bencode:"complete"` // BEP 48 // Incomplete is the number of active peers that have not completed downloading. Incomplete uint32 `bencode:"incomplete"` // BEP 48 // The number of peers that have ever completed downloading. Downloaded uint32 `bencode:"downloaded"` // BEP 48 }
ScrapeResponseResult is the result of the scraped file.