global.go | 2 ++ peerconn.go | 12 ++++++------ diff --git a/global.go b/global.go index ff237c8ee1edda4f9d464d08d9db1bb49c7fa670..1a09b06e6b4d6dbd96cd018a6522721429af593b 100644 --- a/global.go +++ b/global.go @@ -26,6 +26,7 @@ } 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 @@ // may be attached to a Client someday. 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 41e8662d295f31dcd93e81720ccbf5cbb31b157b..a9decda15e2be4616a550175b077aa1fc5e10ed4 100644 --- a/peerconn.go +++ b/peerconn.go @@ -1357,22 +1357,22 @@ // Handle a received chunk from a peer. 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 @@ if c.expectingChunks() { 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 }