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.
18 BytesWrittenData int64
22 BytesReadUsefulData int64
27 ChunksReadUseful int64
28 ChunksReadUnwanted int64
30 // Number of pieces data was written to, that subsequently passed verification.
31 PiecesDirtiedGood int64
32 // Number of pieces data was written to, that subsequently failed
33 // verification. Note that a connection may not have been the sole dirtier
35 PiecesDirtiedBad int64
38 func (cs *ConnStats) wroteMsg(msg *pp.Message) {
42 cs.BytesWrittenData += int64(len(msg.Piece))
46 func (cs *ConnStats) readMsg(msg *pp.Message) {
50 cs.BytesReadData += int64(len(msg.Piece))
54 func (cs *ConnStats) wroteBytes(n int64) {
58 func (cs *ConnStats) readBytes(n int64) {
62 type connStatsReadWriter struct {
68 func (me connStatsReadWriter) Write(b []byte) (n int, err error) {
69 n, err = me.rw.Write(b)
71 me.c.wroteBytes(int64(n))
76 func (me connStatsReadWriter) Read(b []byte) (n int, err error) {
77 n, err = me.rw.Read(b)
79 me.c.readBytes(int64(n))