client_test.go | 4 ++-- conn_stats.go | 20 +++++++++----------- connection.go | 4 ++-- torrent.go | 4 ++-- diff --git a/client_test.go b/client_test.go index 7508480073536089c2cd053aae4f90217ae0ef94..edaa4ffb521d689b530b15dd2c4909b1127c6723 100644 --- a/client_test.go +++ b/client_test.go @@ -416,9 +416,9 @@ if ps.SetReadahead { r.SetReadahead(ps.Readahead) } assertReadAllGreeting(t, r) - assert.True(t, 13 <= seederTorrent.Stats().DataBytesWritten) + assert.True(t, 13 <= seederTorrent.Stats().BytesWrittenData) assert.True(t, 8 <= seederTorrent.Stats().ChunksWritten) - assert.True(t, 13 <= leecherTorrent.Stats().DataBytesRead) + assert.True(t, 13 <= leecherTorrent.Stats().BytesReadData) assert.True(t, 8 <= leecherTorrent.Stats().ChunksRead) // Try reading through again for the cases where the torrent data size // exceeds the size of the cache. diff --git a/conn_stats.go b/conn_stats.go index 89650c9aeeab5d56d9c094c10331bcd9e9638f5b..a54fd7b89917d86b744eec7a6bc27899040f7ee7 100644 --- a/conn_stats.go +++ b/conn_stats.go @@ -14,10 +14,12 @@ // Unwanted is something we didn't ask for (but may still be useful). Written // is things sent to the peer, and Read is stuff received from them. type ConnStats struct { // Total bytes on the wire. Includes handshakes and encryption. - BytesWritten int64 - BytesRead int64 + BytesWritten int64 + BytesWrittenData int64 - // The rest of the stats only occur on connections after handshakes. + BytesRead int64 + BytesReadData int64 + BytesReadUsefulData int64 ChunksWritten int64 @@ -25,23 +27,19 @@ ChunksRead int64 ChunksReadUseful int64 ChunksReadUnwanted int64 - DataBytesWritten int64 - DataBytesRead int64 - UsefulDataBytesRead int64 - // Number of pieces data was written to, that subsequently passed verification. - GoodPiecesDirtied int64 + PiecesDirtiedGood int64 // Number of pieces data was written to, that subsequently failed // verification. Note that a connection may not have been the sole dirtier // of a piece. - BadPiecesDirtied int64 + PiecesDirtiedBad int64 } func (cs *ConnStats) wroteMsg(msg *pp.Message) { switch msg.Type { case pp.Piece: cs.ChunksWritten++ - cs.DataBytesWritten += int64(len(msg.Piece)) + cs.BytesWrittenData += int64(len(msg.Piece)) } } @@ -49,7 +47,7 @@ func (cs *ConnStats) readMsg(msg *pp.Message) { switch msg.Type { case pp.Piece: cs.ChunksRead++ - cs.DataBytesRead += int64(len(msg.Piece)) + cs.BytesReadData += int64(len(msg.Piece)) } } diff --git a/connection.go b/connection.go index a8530e34f5556455789a86918bd8781775464dbe..73d74604549fd2a9a876d10e316ab9532d941b09 100644 --- a/connection.go +++ b/connection.go @@ -1153,7 +1153,7 @@ if !c.peerHasWantedPieces() { return false } // Don't upload more than 100 KiB more than we download. - if c.stats.DataBytesWritten >= c.stats.DataBytesRead+100<<10 { + if c.stats.BytesWrittenData >= c.stats.BytesReadData+100<<10 { return false } return true @@ -1223,7 +1223,7 @@ cn.t.dropConnection(cn) } func (cn *connection) netGoodPiecesDirtied() int64 { - return cn.stats.GoodPiecesDirtied - cn.stats.BadPiecesDirtied + return cn.stats.PiecesDirtiedGood - cn.stats.PiecesDirtiedBad } func (c *connection) peerHasWantedPieces() bool { diff --git a/torrent.go b/torrent.go index 60119b592c1094aa67224fecf754c95711bd836b..99908a92cd0264744ffdb258d7170523e00f451d 100644 --- a/torrent.go +++ b/torrent.go @@ -1515,7 +1515,7 @@ } p.everHashed = true if correct { for _, c := range touchers { - c.stats.GoodPiecesDirtied++ + c.stats.PiecesDirtiedGood++ } err := p.Storage().MarkComplete() if err != nil { @@ -1525,7 +1525,7 @@ } else { if len(touchers) != 0 { for _, c := range touchers { // Y u do dis peer?! - c.stats.BadPiecesDirtied++ + c.stats.PiecesDirtiedBad++ } slices.Sort(touchers, connLessTrusted) if t.cl.config.Debug {