Skip to content

Commit

Permalink
Fix announcing to S3 HTTP trackers
Browse files Browse the repository at this point in the history
  • Loading branch information
anacrolix committed Jul 17, 2019
1 parent b17f011 commit 27b7fbe
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
6 changes: 3 additions & 3 deletions cmd/tracker-announce/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -37,7 +37,7 @@ func main() {
tagflag.Parse(&flags)
ar := tracker.AnnounceRequest{
NumWant: -1,
Left: math.MaxUint64,
Left: -1,
Port: flags.Port,
}
var wg sync.WaitGroup
Expand Down
10 changes: 5 additions & 5 deletions torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"math"
"math/rand"
"net/url"
"os"
Expand All @@ -15,6 +14,8 @@ import (
"time"
"unsafe"

"github.com/davecgh/go-spew/spew"

"github.com/anacrolix/dht"
"github.com/anacrolix/log"
"github.com/anacrolix/missinggo"
Expand All @@ -28,7 +29,6 @@ import (
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 {
Expand Down Expand Up @@ -635,11 +635,11 @@ func (t *Torrent) bytesLeft() (left int64) {
}

// 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
}
}

Expand Down
12 changes: 11 additions & 1 deletion tracker/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"fmt"
"io"
"math"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -74,7 +75,16 @@ func setAnnounceParams(_url *url.URL, ar *AnnounceRequest, opts Announce) {
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())
}
Expand Down
2 changes: 1 addition & 1 deletion tracker/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 27b7fbe

Please sign in to comment.