]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Count requested chunk lengths
authorMatt Joiner <anacrolix@gmail.com>
Fri, 2 Feb 2018 05:06:24 +0000 (16:06 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 2 Feb 2018 05:06:24 +0000 (16:06 +1100)
Have seen some very ridiculous lengths causing data read errors

connection.go
global.go
peer_protocol/protocol.go

index 46083d56d3794b6aa2d55a641a69a72951d2f238..fbf86e56600cb993db8fae4f85a1cf864e5c391b 100644 (file)
@@ -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
                        }
index ffc30f493348c455c360187964c935d66a0899b8..4b27f2e50b7a2e277e57a2a28157ca12c7c7332d 100644 (file)
--- 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")
index bc4d6ee604451711f812e37129b4d488d4bf3325..27827eed72afa693604b78c3137b2bee77e30f2b 100644 (file)
@@ -25,6 +25,10 @@ func (i Integer) Int() int {
        return int(i)
 }
 
+func (i Integer) Uint64() uint64 {
+       return uint64(i)
+}
+
 const (
        Protocol = "\x13BitTorrent protocol"
 )