From: Matt Joiner <anacrolix@gmail.com>
Date: Tue, 11 May 2021 07:13:03 +0000 (+1000)
Subject: Track chunks received in nexted expvar.Map
X-Git-Tag: v1.28.0~8
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=f01d93cee0bff22a1fc101f5958e264ab0bef0c3;p=btrtrc.git

Track chunks received in nexted expvar.Map
---

diff --git a/global.go b/global.go
index ff237c8e..1a09b06e 100644
--- 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")
diff --git a/peerconn.go b/peerconn.go
index 41e8662d..a9decda1 100644
--- a/peerconn.go
+++ b/peerconn.go
@@ -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
 	}