]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Add t.bytesLeftAnnounce
authorMatt Joiner <anacrolix@gmail.com>
Mon, 21 Mar 2016 22:06:48 +0000 (09:06 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 21 Mar 2016 22:06:48 +0000 (09:06 +1100)
Now it's safe to remove tracker specific bytesLeft contract

client.go
torrent.go

index 6d8d7fbb6c7461b506e5fb920f52fa6fa384bcd9..5e4b5d848c5b5cecf2c626372039f81d7e6dc43b 100644 (file)
--- 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
index 00d5ac07aeb3d98e378a92a07b86d486a2447db4..6453c50804994a4eeae997808edf420ed77f2118 100644 (file)
@@ -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