From 9567aa901c2f5e9f3fc2dc3237645fe0b2d6a5a2 Mon Sep 17 00:00:00 2001
From: Matt Joiner <anacrolix@gmail.com>
Date: Sat, 3 Feb 2018 11:53:11 +1100
Subject: [PATCH] Add missing increments to some stats

---
 client.go     | 1 +
 connection.go | 4 ++++
 torrent.go    | 4 ++++
 3 files changed, 9 insertions(+)

diff --git a/client.go b/client.go
index 3072dcd1..bab9e560 100644
--- a/client.go
+++ b/client.go
@@ -948,6 +948,7 @@ func (cl *Client) gotMetadataExtensionMsg(payload []byte, t *Torrent, c *connect
 		}
 		t.saveMetadataPiece(piece, payload[begin:])
 		c.stats.ChunksReadUseful++
+		c.t.stats.ChunksReadUseful++
 		c.lastUsefulChunkReceived = time.Now()
 		return t.maybeCompleteMetadata()
 	case pp.RequestMetadataExtensionMsgType:
diff --git a/connection.go b/connection.go
index 73d74604..c3a56650 100644
--- a/connection.go
+++ b/connection.go
@@ -1080,6 +1080,7 @@ func (c *connection) receiveChunk(msg *pp.Message) {
 	if !t.wantPiece(req) {
 		unwantedChunksReceived.Add(1)
 		c.stats.ChunksReadUnwanted++
+		c.t.stats.ChunksReadUnwanted++
 		return
 	}
 
@@ -1087,6 +1088,9 @@ func (c *connection) receiveChunk(msg *pp.Message) {
 	piece := &t.pieces[index]
 
 	c.stats.ChunksReadUseful++
+	c.t.stats.ChunksReadUseful++
+	c.stats.BytesReadUsefulData += int64(len(msg.Piece))
+	c.t.stats.BytesReadUsefulData += int64(len(msg.Piece))
 	c.lastUsefulChunkReceived = time.Now()
 	// if t.fastestConn != c {
 	// log.Printf("setting fastest connection %p", c)
diff --git a/torrent.go b/torrent.go
index 99908a92..a58d6b8f 100644
--- a/torrent.go
+++ b/torrent.go
@@ -1514,6 +1514,9 @@ func (t *Torrent) pieceHashed(piece int, correct bool) {
 	}
 	p.everHashed = true
 	if correct {
+		if len(touchers) != 0 {
+			t.stats.PiecesDirtiedGood++
+		}
 		for _, c := range touchers {
 			c.stats.PiecesDirtiedGood++
 		}
@@ -1523,6 +1526,7 @@ func (t *Torrent) pieceHashed(piece int, correct bool) {
 		}
 	} else {
 		if len(touchers) != 0 {
+			t.stats.PiecesDirtiedBad++
 			for _, c := range touchers {
 				// Y u do dis peer?!
 				c.stats.PiecesDirtiedBad++
-- 
2.51.0