]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Track chunks received in nexted expvar.Map
authorMatt Joiner <anacrolix@gmail.com>
Tue, 11 May 2021 07:13:03 +0000 (17:13 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 14 May 2021 05:42:02 +0000 (15:42 +1000)
global.go
peerconn.go

index ff237c8ee1edda4f9d464d08d9db1bb49c7fa670..1a09b06e6b4d6dbd96cd018a6522721429af593b 100644 (file)
--- a/global.go
+++ b/global.go
@@ -26,6 +26,7 @@ func defaultPeerExtensionBytes() PeerExtensionBits {
 
 func init() {
        torrent.Set("peers supporting extension", &peersSupportingExtension)
+       torrent.Set("chunks received", &chunksReceived)
 }
 
 // I could move a lot of these counters to their own file, but I suspect they
@@ -33,6 +34,7 @@ func init() {
 var (
        torrent                  = expvar.NewMap("torrent")
        peersSupportingExtension expvar.Map
+       chunksReceived           expvar.Map
 
        pieceHashedCorrect    = expvar.NewInt("pieceHashedCorrect")
        pieceHashedNotCorrect = expvar.NewInt("pieceHashedNotCorrect")
index 41e8662d295f31dcd93e81720ccbf5cbb31b157b..a9decda15e2be4616a550175b077aa1fc5e10ed4 100644 (file)
@@ -1357,22 +1357,22 @@ func (cn *PeerConn) rw() io.ReadWriter {
 func (c *Peer) receiveChunk(msg *pp.Message) error {
        t := c.t
        cl := t.cl
-       torrent.Add("chunks received", 1)
+       chunksReceived.Add("total", 1)
 
        req := newRequestFromMessage(msg)
 
        if c.peerChoking {
-               torrent.Add("chunks received while choking", 1)
+               chunksReceived.Add("while choked", 1)
        }
 
        if c.validReceiveChunks[req] <= 0 {
-               torrent.Add("chunks received unexpected", 1)
+               chunksReceived.Add("unexpected", 1)
                return errors.New("received unexpected chunk")
        }
        c.decExpectedChunkReceive(req)
 
        if c.peerChoking && c.peerAllowedFast.Get(int(req.Index)) {
-               torrent.Add("chunks received due to allowed fast", 1)
+               chunksReceived.Add("due to allowed fast", 1)
        }
 
        // TODO: This needs to happen immediately, to prevent cancels occurring asynchronously when have
@@ -1389,13 +1389,13 @@ func (c *Peer) receiveChunk(msg *pp.Message) error {
                                c._chunksReceivedWhileExpecting++
                        }
                } else {
-                       torrent.Add("chunks received unwanted", 1)
+                       chunksReceived.Add("unwanted", 1)
                }
        }
 
        // Do we actually want this chunk?
        if t.haveChunk(req) {
-               torrent.Add("chunks received wasted", 1)
+               chunksReceived.Add("wasted", 1)
                c.allStats(add(1, func(cs *ConnStats) *Count { return &cs.ChunksReadWasted }))
                return nil
        }