From 5a4e8cd4c5f8c1f90a9b03bffaa5e90b45a740b6 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sat, 3 Feb 2018 00:41:13 +1100 Subject: [PATCH] Rename and rearrange some conn stats --- client_test.go | 4 ++-- conn_stats.go | 20 +++++++++----------- connection.go | 4 ++-- torrent.go | 4 ++-- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/client_test.go b/client_test.go index 75084800..edaa4ffb 100644 --- a/client_test.go +++ b/client_test.go @@ -416,9 +416,9 @@ func testClientTransfer(t *testing.T, ps testClientTransferParams) { 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 89650c9a..a54fd7b8 100644 --- a/conn_stats.go +++ b/conn_stats.go @@ -14,10 +14,12 @@ import ( // 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 @@ type ConnStats struct { 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 a8530e34..73d74604 100644 --- a/connection.go +++ b/connection.go @@ -1153,7 +1153,7 @@ func (c *connection) uploadAllowed() bool { 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 @@ func (cn *connection) Drop() { } 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 60119b59..99908a92 100644 --- a/torrent.go +++ b/torrent.go @@ -1515,7 +1515,7 @@ func (t *Torrent) pieceHashed(piece int, correct bool) { 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 @@ func (t *Torrent) pieceHashed(piece int, correct bool) { 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 {