]> Sergey Matveev's repositories - btrtrc.git/blobdiff - conn_stats.go
Drop support for go 1.20
[btrtrc.git] / conn_stats.go
index 9b0865a08051ea4a1bf61739df806642d8d4810d..0c5bfc784e88d4ce142cff68bb552e681cac9e1e 100644 (file)
@@ -10,19 +10,20 @@ import (
        pp "github.com/anacrolix/torrent/peer_protocol"
 )
 
-// Various connection-level metrics. At the Torrent level these are
-// aggregates. Chunks are messages with data payloads. Data is actual torrent
-// content without any overhead. Useful is something we needed locally.
-// 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.
+// Various connection-level metrics. At the Torrent level these are aggregates. Chunks are messages
+// with data payloads. Data is actual torrent content without any overhead. Useful is something we
+// needed locally. 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. Due to the implementation of
+// Count, must be aligned on some platforms: See https://github.com/anacrolix/torrent/issues/262.
 type ConnStats struct {
        // Total bytes on the wire. Includes handshakes and encryption.
        BytesWritten     Count
        BytesWrittenData Count
 
-       BytesRead           Count
-       BytesReadData       Count
-       BytesReadUsefulData Count
+       BytesRead                   Count
+       BytesReadData               Count
+       BytesReadUsefulData         Count
+       BytesReadUsefulIntendedData Count
 
        ChunksWritten Count
 
@@ -78,14 +79,9 @@ func (cs *ConnStats) wroteMsg(msg *pp.Message) {
        }
 }
 
-func (cs *ConnStats) readMsg(msg *pp.Message) {
-       // We want to also handle extended metadata pieces here, but we wouldn't
-       // have decoded the extended payload yet.
-       switch msg.Type {
-       case pp.Piece:
-               cs.ChunksRead.Add(1)
-               cs.BytesReadData.Add(int64(len(msg.Piece)))
-       }
+func (cs *ConnStats) receivedChunk(size int64) {
+       cs.ChunksRead.Add(1)
+       cs.BytesReadData.Add(size)
 }
 
 func (cs *ConnStats) incrementPiecesDirtiedGood() {