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) {
39 // TODO: Track messages and not just chunks.
43 cs.BytesWrittenData += int64(len(msg.Piece))
47 func (cs *ConnStats) readMsg(msg *pp.Message) {
51 cs.BytesReadData += int64(len(msg.Piece))
55 func (cs *ConnStats) wroteBytes(n int64) {
59 func (cs *ConnStats) readBytes(n int64) {
63 type connStatsReadWriter struct {
69 func (me connStatsReadWriter) Write(b []byte) (n int, err error) {
70 n, err = me.rw.Write(b)
72 me.c.wroteBytes(int64(n))
77 func (me connStatsReadWriter) Read(b []byte) (n int, err error) {
78 n, err = me.rw.Read(b)
80 me.c.readBytes(int64(n))