2
0
mirror of synced 2025-02-23 14:18:13 +00:00

Rework stats for receiving chunks

Related to #253.
This commit is contained in:
Matt Joiner 2018-06-25 14:06:30 +10:00
parent 7619994ef5
commit 85dc3c204a
3 changed files with 16 additions and 15 deletions

View 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

View 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
}

View 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