From: Matt Joiner Date: Fri, 27 Mar 2015 06:22:00 +0000 (+1100) Subject: The signedness on several tracker.AnnounceRequest fields now matters X-Git-Tag: v1.0.0~1233 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=90b27618ac0c7a7d3f2be8b02d0b29fb82168f12;p=btrtrc.git The signedness on several tracker.AnnounceRequest fields now matters Sending negative ports and lefts through to HTTP trackers was making them mad. --- diff --git a/client.go b/client.go index 16ded0d7..30e6aa30 100644 --- 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 diff --git a/tracker/http.go b/tracker/http.go index 0a65fc70..97a045a9 100644 --- a/tracker/http.go +++ b/tracker/http.go @@ -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()) } diff --git a/tracker/tracker.go b/tracker/tracker.go index 98a77a18..c54aae0f 100644 --- a/tracker/tracker.go +++ b/tracker/tracker.go @@ -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 {