]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Rework stats for receiving chunks
authorMatt Joiner <anacrolix@gmail.com>
Mon, 25 Jun 2018 04:06:30 +0000 (14:06 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 25 Jun 2018 04:06:30 +0000 (14:06 +1000)
Related to #253.

conn_stats.go
connection.go
torrent.go

index 67188acb0e1fd10b6c441d0b80b3be8cd411278f..2f1a50300ee92557342b212be54e2e8722f05b69 100644 (file)
@@ -25,9 +25,9 @@ type ConnStats struct {
 
        ChunksWritten Count
 
-       ChunksRead         Count
-       ChunksReadUseful   Count
-       ChunksReadUnwanted Count
+       ChunksRead       Count
+       ChunksReadUseful Count
+       ChunksReadWasted Count
 
        // Number of pieces data was written to, that subsequently passed verification.
        PiecesDirtiedGood Count
index a019ff2062f14b4b95b13d026f7ec0dfd614c673..6e9fd0288390d28831c4aeb1e0dd2a5d166b144f 100644 (file)
@@ -1287,32 +1287,33 @@ func (c *connection) receiveChunk(msg *pp.Message) error {
 
        req := newRequestFromMessage(msg)
 
+       if c.PeerChoked {
+               torrent.Add("chunks received while choked", 1)
+       }
+
        if _, ok := c.validReceiveChunks[req]; !ok {
+               torrent.Add("chunks received unexpected", 1)
                return errors.New("received unexpected chunk")
        }
        delete(c.validReceiveChunks, req)
 
+       if c.PeerChoked && c.peerAllowedFast.Get(int(req.Index)) {
+               torrent.Add("chunks received due to allowed fast", 1)
+       }
+
        // Request has been satisfied.
        if c.deleteRequest(req) {
                if c.expectingChunks() {
                        c.chunksReceivedWhileExpecting++
                }
-               c.updateRequests()
        } else {
-               torrent.Add("chunks received unexpected", 1)
-       }
-
-       if c.PeerChoked {
-               torrent.Add("chunks received while choked", 1)
-               if c.peerAllowedFast.Get(int(req.Index)) {
-                       torrent.Add("chunks received due to allowed fast", 1)
-               }
+               torrent.Add("chunks received unwanted", 1)
        }
 
        // Do we actually want this chunk?
        if t.haveChunk(req) {
-               torrent.Add("chunks received unwanted", 1)
-               c.allStats(add(1, func(cs *ConnStats) *Count { return &cs.ChunksReadUnwanted }))
+               torrent.Add("chunks received wasted", 1)
+               c.allStats(add(1, func(cs *ConnStats) *Count { return &cs.ChunksReadWasted }))
                return nil
        }
 
index 36fa77065f4a0eb36d782c24b0e2772dd3c868c9..fe3df93f4ca125c1f5685f541d757d8bf3c1310c 100644 (file)
@@ -857,7 +857,7 @@ func (t *Torrent) worstBadConn() *connection {
        heap.Init(&wcs)
        for wcs.Len() != 0 {
                c := heap.Pop(&wcs).(*connection)
-               if c.stats.ChunksReadUnwanted.Int64() >= 6 && c.stats.ChunksReadUnwanted.Int64() > c.stats.ChunksReadUseful.Int64() {
+               if c.stats.ChunksReadWasted.Int64() >= 6 && c.stats.ChunksReadWasted.Int64() > c.stats.ChunksReadUseful.Int64() {
                        return c
                }
                // If the connection is in the worst half of the established