cmd/tracker-announce/main.go | 6 +++--- torrent.go | 10 +++++----- tracker/http.go | 12 +++++++++++- tracker/tracker.go | 2 +- diff --git a/cmd/tracker-announce/main.go b/cmd/tracker-announce/main.go index f2eb02e419708bf8029af9924e96554aa49f957a..4c029c39d18fba2722c6dfbda54e9d57d77d23c8 100644 --- a/cmd/tracker-announce/main.go +++ b/cmd/tracker-announce/main.go @@ -2,16 +2,16 @@ package main import ( "log" - "math" "net/url" "strings" "sync" + + "github.com/davecgh/go-spew/spew" "github.com/anacrolix/tagflag" "github.com/anacrolix/torrent" "github.com/anacrolix/torrent/metainfo" "github.com/anacrolix/torrent/tracker" - "github.com/davecgh/go-spew/spew" ) func argSpec(arg string) (ts *torrent.TorrentSpec, err error) { @@ -37,7 +37,7 @@ } tagflag.Parse(&flags) ar := tracker.AnnounceRequest{ NumWant: -1, - Left: math.MaxUint64, + Left: -1, Port: flags.Port, } var wg sync.WaitGroup diff --git a/torrent.go b/torrent.go index 33f43b30bcef09240250573eeaae219d5830a873..15029945d1af9db6e5f190e8562349145c45d0f1 100644 --- a/torrent.go +++ b/torrent.go @@ -6,7 +6,6 @@ "crypto/sha1" "errors" "fmt" "io" - "math" "math/rand" "net/url" "os" @@ -14,6 +13,8 @@ "sync" "text/tabwriter" "time" "unsafe" + + "github.com/davecgh/go-spew/spew" "github.com/anacrolix/dht" "github.com/anacrolix/log" @@ -28,7 +29,6 @@ "github.com/anacrolix/torrent/metainfo" pp "github.com/anacrolix/torrent/peer_protocol" "github.com/anacrolix/torrent/storage" "github.com/anacrolix/torrent/tracker" - "github.com/davecgh/go-spew/spew" ) func (t *Torrent) chunkIndexSpec(chunkIndex pp.Integer, piece pieceIndex) chunkSpec { @@ -635,11 +635,11 @@ return } // Bytes left to give in tracker announces. -func (t *Torrent) bytesLeftAnnounce() uint64 { +func (t *Torrent) bytesLeftAnnounce() int64 { if t.haveInfo() { - return uint64(t.bytesLeft()) + return t.bytesLeft() } else { - return math.MaxUint64 + return -1 } } diff --git a/tracker/http.go b/tracker/http.go index 87927e773214ba348cadb1b09cf98e6c956f766b..65cb198956b06608a1b5465cfa05b11cf0544d54 100644 --- a/tracker/http.go +++ b/tracker/http.go @@ -5,6 +5,7 @@ "bytes" "crypto/tls" "fmt" "io" + "math" "net" "net/http" "net/url" @@ -74,7 +75,16 @@ // AFAICT, port is mandatory, and there's no implied port key. q.Set("port", fmt.Sprintf("%d", ar.Port)) q.Set("uploaded", strconv.FormatInt(ar.Uploaded, 10)) q.Set("downloaded", strconv.FormatInt(ar.Downloaded, 10)) - q.Set("left", strconv.FormatUint(ar.Left, 10)) + + // The AWS S3 tracker returns "400 Bad Request: left(-1) was not in the valid range 0 - + // 9223372036854775807" if left is out of range, or "500 Internal Server Error: Internal Server + // Error" if omitted entirely. + left := ar.Left + if left < 0 { + left = math.MaxInt64 + } + q.Set("left", strconv.FormatInt(left, 10)) + if ar.Event != None { q.Set("event", ar.Event.String()) } diff --git a/tracker/tracker.go b/tracker/tracker.go index 446e2cb295ba9b8b283a477919c6ade4c5674072..c3eefb98d929957f569fda9280275ac6aee576e7 100644 --- a/tracker/tracker.go +++ b/tracker/tracker.go @@ -14,7 +14,7 @@ type AnnounceRequest struct { InfoHash [20]byte PeerId [20]byte Downloaded int64 - Left uint64 + Left int64 // If less than 0, math.MaxInt64 will be used for HTTP trackers instead. Uploaded int64 // Apparently this is optional. None can be used for announces done at // regular intervals.