7 pp "github.com/anacrolix/torrent/peer_protocol"
10 // Various connection-level metrics. At the Torrent level these are
11 // aggregates. Chunks are messages with data payloads. Data is actual torrent
12 // content without any overhead. Useful is something we needed locally.
13 // Unwanted is something we didn't ask for (but may still be useful). Written
14 // is things sent to the peer, and Read is stuff received from them.
15 type ConnStats struct {
16 // Total bytes on the wire. Includes handshakes and encryption.
20 // The rest of the stats only occur on connections after handshakes.
25 ChunksReadUseful int64
26 ChunksReadUnwanted int64
28 DataBytesWritten int64
30 UsefulDataBytesRead int64
32 // Number of pieces data was written to, that subsequently passed verification.
33 GoodPiecesDirtied int64
34 // Number of pieces data was written to, that subsequently failed
35 // verification. Note that a connection may not have been the sole dirtier
37 BadPiecesDirtied int64
40 func (cs *ConnStats) wroteMsg(msg *pp.Message) {
44 cs.DataBytesWritten += int64(len(msg.Piece))
48 func (cs *ConnStats) readMsg(msg *pp.Message) {
52 cs.DataBytesRead += int64(len(msg.Piece))
56 func (cs *ConnStats) wroteBytes(n int64) {
60 func (cs *ConnStats) readBytes(n int64) {
64 type connStatsReadWriter struct {
70 func (me connStatsReadWriter) Write(b []byte) (n int, err error) {
71 n, err = me.rw.Write(b)
73 me.c.wroteBytes(int64(n))
78 func (me connStatsReadWriter) Read(b []byte) (n int, err error) {
79 n, err = me.rw.Read(b)
81 me.c.readBytes(int64(n))