From: Matt Joiner Date: Mon, 21 Mar 2016 22:06:48 +0000 (+1100) Subject: Add t.bytesLeftAnnounce X-Git-Tag: v1.0.0~824 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=e2ffcd008bfda4fde39c6119ab0f446f5d6dc50e;p=btrtrc.git Add t.bytesLeftAnnounce Now it's safe to remove tracker specific bytesLeft contract --- diff --git a/client.go b/client.go index 6d8d7fbb..5e4b5d84 100644 --- a/client.go +++ b/client.go @@ -2219,7 +2219,7 @@ func (cl *Client) announceTorrentTrackers(t *torrent) { return } cl.mu.RLock() - req.Left = uint64(t.bytesLeft()) + req.Left = t.bytesLeftAnnounce() trackers := t.Trackers cl.mu.RUnlock() if cl.announceTorrentTrackersFastStart(&req, trackers, t) { @@ -2228,7 +2228,7 @@ func (cl *Client) announceTorrentTrackers(t *torrent) { newAnnounce: for cl.waitWantPeers(t) { cl.mu.RLock() - req.Left = uint64(t.bytesLeft()) + req.Left = t.bytesLeftAnnounce() trackers = t.Trackers cl.mu.RUnlock() numTrackersTried := 0 diff --git a/torrent.go b/torrent.go index 00d5ac07..6453c508 100644 --- a/torrent.go +++ b/torrent.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "log" + "math" "math/rand" "net" "sort" @@ -519,6 +520,15 @@ func (t *torrent) bytesLeft() (left int64) { return } +// Bytes left to give in tracker announces. +func (t *torrent) bytesLeftAnnounce() uint64 { + if t.haveInfo() { + return uint64(t.bytesLeft()) + } else { + return math.MaxUint64 + } +} + func (t *torrent) piecePartiallyDownloaded(piece int) bool { if t.pieceComplete(piece) { return false