From e2ffcd008bfda4fde39c6119ab0f446f5d6dc50e Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 22 Mar 2016 09:06:48 +1100 Subject: [PATCH] Add t.bytesLeftAnnounce Now it's safe to remove tracker specific bytesLeft contract --- client.go | 4 ++-- torrent.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) 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 -- 2.48.1