Rename and rearrange some conn stats

This commit is contained in:
Matt Joiner 2018-02-03 00:41:13 +11:00
parent ffe778392c
commit 5a4e8cd4c5
4 changed files with 15 additions and 17 deletions

View File

@ -416,9 +416,9 @@ func testClientTransfer(t *testing.T, ps testClientTransferParams) {
r.SetReadahead(ps.Readahead) r.SetReadahead(ps.Readahead)
} }
assertReadAllGreeting(t, r) 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, 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) assert.True(t, 8 <= leecherTorrent.Stats().ChunksRead)
// Try reading through again for the cases where the torrent data size // Try reading through again for the cases where the torrent data size
// exceeds the size of the cache. // exceeds the size of the cache.

View File

@ -15,9 +15,11 @@ import (
type ConnStats struct { type ConnStats struct {
// Total bytes on the wire. Includes handshakes and encryption. // Total bytes on the wire. Includes handshakes and encryption.
BytesWritten int64 BytesWritten int64
BytesRead int64 BytesWrittenData int64
// The rest of the stats only occur on connections after handshakes. BytesRead int64
BytesReadData int64
BytesReadUsefulData int64
ChunksWritten int64 ChunksWritten int64
@ -25,23 +27,19 @@ type ConnStats struct {
ChunksReadUseful int64 ChunksReadUseful int64
ChunksReadUnwanted int64 ChunksReadUnwanted int64
DataBytesWritten int64
DataBytesRead int64
UsefulDataBytesRead int64
// Number of pieces data was written to, that subsequently passed verification. // 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 // Number of pieces data was written to, that subsequently failed
// verification. Note that a connection may not have been the sole dirtier // verification. Note that a connection may not have been the sole dirtier
// of a piece. // of a piece.
BadPiecesDirtied int64 PiecesDirtiedBad int64
} }
func (cs *ConnStats) wroteMsg(msg *pp.Message) { func (cs *ConnStats) wroteMsg(msg *pp.Message) {
switch msg.Type { switch msg.Type {
case pp.Piece: case pp.Piece:
cs.ChunksWritten++ 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 { switch msg.Type {
case pp.Piece: case pp.Piece:
cs.ChunksRead++ cs.ChunksRead++
cs.DataBytesRead += int64(len(msg.Piece)) cs.BytesReadData += int64(len(msg.Piece))
} }
} }

View File

@ -1153,7 +1153,7 @@ func (c *connection) uploadAllowed() bool {
return false return false
} }
// Don't upload more than 100 KiB more than we download. // 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 false
} }
return true return true
@ -1223,7 +1223,7 @@ func (cn *connection) Drop() {
} }
func (cn *connection) netGoodPiecesDirtied() int64 { func (cn *connection) netGoodPiecesDirtied() int64 {
return cn.stats.GoodPiecesDirtied - cn.stats.BadPiecesDirtied return cn.stats.PiecesDirtiedGood - cn.stats.PiecesDirtiedBad
} }
func (c *connection) peerHasWantedPieces() bool { func (c *connection) peerHasWantedPieces() bool {

View File

@ -1515,7 +1515,7 @@ func (t *Torrent) pieceHashed(piece int, correct bool) {
p.everHashed = true p.everHashed = true
if correct { if correct {
for _, c := range touchers { for _, c := range touchers {
c.stats.GoodPiecesDirtied++ c.stats.PiecesDirtiedGood++
} }
err := p.Storage().MarkComplete() err := p.Storage().MarkComplete()
if err != nil { if err != nil {
@ -1525,7 +1525,7 @@ func (t *Torrent) pieceHashed(piece int, correct bool) {
if len(touchers) != 0 { if len(touchers) != 0 {
for _, c := range touchers { for _, c := range touchers {
// Y u do dis peer?! // Y u do dis peer?!
c.stats.BadPiecesDirtied++ c.stats.PiecesDirtiedBad++
} }
slices.Sort(touchers, connLessTrusted) slices.Sort(touchers, connLessTrusted)
if t.cl.config.Debug { if t.cl.config.Debug {