]> Sergey Matveev's repositories - btrtrc.git/commitdiff
The signedness on several tracker.AnnounceRequest fields now matters
authorMatt Joiner <anacrolix@gmail.com>
Fri, 27 Mar 2015 06:22:00 +0000 (17:22 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 27 Mar 2015 06:22:00 +0000 (17:22 +1100)
Sending negative ports and lefts through to HTTP trackers was making them mad.

client.go
tracker/http.go
tracker/tracker.go

index 16ded0d795a5d8cbd60bc6506f02152e5e4881d2..30e6aa30c6317527d38339a683d9218fd0b7c8f7 100644 (file)
--- a/client.go
+++ b/client.go
@@ -2514,7 +2514,7 @@ func (cl *Client) announceTorrentTrackers(t *torrent) {
        req := tracker.AnnounceRequest{
                Event:    tracker.Started,
                NumWant:  -1,
-               Port:     int16(cl.incomingPeerPort()),
+               Port:     uint16(cl.incomingPeerPort()),
                PeerId:   cl.peerID,
                InfoHash: t.InfoHash,
        }
@@ -2522,7 +2522,7 @@ func (cl *Client) announceTorrentTrackers(t *torrent) {
                return
        }
        cl.mu.RLock()
-       req.Left = t.bytesLeft()
+       req.Left = uint64(t.bytesLeft())
        trackers := t.Trackers
        cl.mu.RUnlock()
        if cl.announceTorrentTrackersFastStart(&req, trackers, t) {
@@ -2531,7 +2531,7 @@ func (cl *Client) announceTorrentTrackers(t *torrent) {
 newAnnounce:
        for cl.waitWantPeers(t) {
                cl.mu.RLock()
-               req.Left = t.bytesLeft()
+               req.Left = uint64(t.bytesLeft())
                trackers = t.Trackers
                cl.mu.RUnlock()
                numTrackersTried := 0
index 0a65fc707bd8ec3d59c628df65744fc188607060..97a045a98609c31ed218ac22ebc1747bd4849fa1 100644 (file)
@@ -63,7 +63,7 @@ func (me *client) Announce(ar *AnnounceRequest) (ret AnnounceResponse, err error
        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.FormatInt(ar.Left, 10))
+       q.Set("left", strconv.FormatUint(ar.Left, 10))
        if ar.Event != None {
                q.Set("event", ar.Event.String())
        }
index 98a77a182c247e54ed2ae4b9e6b6c36a93a9c59f..c54aae0f04e5cede773258050c144defc918788d 100644 (file)
@@ -6,17 +6,18 @@ import (
        "net/url"
 )
 
+// Marshalled as binary by the UDP client, so be careful making changes.
 type AnnounceRequest struct {
        InfoHash   [20]byte
        PeerId     [20]byte
        Downloaded int64
-       Left       int64
+       Left       uint64
        Uploaded   int64
        Event      AnnounceEvent
        IPAddress  int32
        Key        int32
        NumWant    int32 // How many peer addresses are desired. -1 for default.
-       Port       int16
+       Port       uint16
 } // 82 bytes
 
 type AnnounceResponse struct {