From: Matt Joiner Date: Fri, 2 Feb 2018 05:06:24 +0000 (+1100) Subject: Count requested chunk lengths X-Git-Tag: v1.0.0~230 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=c9507786f2b38a74b3732d9b45f2fa6661f2b2bc;p=btrtrc.git Count requested chunk lengths Have seen some very ridiculous lengths causing data read errors --- diff --git a/connection.go b/connection.go index 46083d56..fbf86e56 100644 --- a/connection.go +++ b/connection.go @@ -884,6 +884,7 @@ func (c *connection) mainReadLoop() error { case pp.Have: err = c.peerSentHave(int(msg.Index)) case pp.Request: + requestedChunkLengths.Add(strconv.FormatUint(msg.Length.Uint64(), 10), 1) if c.Choked { break } diff --git a/global.go b/global.go index ffc30f49..4b27f2e5 100644 --- a/global.go +++ b/global.go @@ -62,6 +62,7 @@ var ( postedKeepalives = expvar.NewInt("postedKeepalives") // Requests received for pieces we don't have. requestsReceivedForMissingPieces = expvar.NewInt("requestsReceivedForMissingPieces") + requestedChunkLengths = expvar.NewMap("requestedChunkLengths") messageTypesReceived = expvar.NewMap("messageTypesReceived") messageTypesSent = expvar.NewMap("messageTypesSent") diff --git a/peer_protocol/protocol.go b/peer_protocol/protocol.go index bc4d6ee6..27827eed 100644 --- a/peer_protocol/protocol.go +++ b/peer_protocol/protocol.go @@ -25,6 +25,10 @@ func (i Integer) Int() int { return int(i) } +func (i Integer) Uint64() uint64 { + return uint64(i) +} + const ( Protocol = "\x13BitTorrent protocol" )