]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Rename and rearrange some conn stats
authorMatt Joiner <anacrolix@gmail.com>
Fri, 2 Feb 2018 13:41:13 +0000 (00:41 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 2 Feb 2018 13:41:13 +0000 (00:41 +1100)
client_test.go
conn_stats.go
connection.go
torrent.go

index 7508480073536089c2cd053aae4f90217ae0ef94..edaa4ffb521d689b530b15dd2c4909b1127c6723 100644 (file)
@@ -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.
index 89650c9aeeab5d56d9c094c10331bcd9e9638f5b..a54fd7b89917d86b744eec7a6bc27899040f7ee7 100644 (file)
@@ -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))
        }
 }
 
index a8530e34f5556455789a86918bd8781775464dbe..73d74604549fd2a9a876d10e316ab9532d941b09 100644 (file)
@@ -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 {
index 60119b592c1094aa67224fecf754c95711bd836b..99908a92cd0264744ffdb258d7170523e00f451d 100644 (file)
@@ -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 {