Track metadata chunks read with its own Count

This commit is contained in:
Matt Joiner 2018-07-15 10:09:58 +10:00
parent 91730696cf
commit d4d3e24c6f
2 changed files with 5 additions and 1 deletions

View File

@ -890,6 +890,7 @@ func (cl *Client) gotMetadataExtensionMsg(payload []byte, t *Torrent, c *connect
piece := d["piece"]
switch msgType {
case pp.DataMetadataExtensionMsgType:
c.allStats(add(1, func(cs *ConnStats) *Count { return &cs.MetadataChunksRead }))
if !c.requestedMetadataPiece(piece) {
return fmt.Errorf("got unexpected piece %d", piece)
}
@ -899,7 +900,6 @@ func (cl *Client) gotMetadataExtensionMsg(payload []byte, t *Torrent, c *connect
return fmt.Errorf("data has bad offset in payload: %d", begin)
}
t.saveMetadataPiece(piece, payload[begin:])
c.allStats(add(1, func(cs *ConnStats) *Count { return &cs.ChunksReadUseful }))
c.lastUsefulChunkReceived = time.Now()
return t.maybeCompleteMetadata()
case pp.RequestMetadataExtensionMsgType:

View File

@ -29,6 +29,8 @@ type ConnStats struct {
ChunksReadUseful Count
ChunksReadWasted Count
MetadataChunksRead Count
// Number of pieces data was written to, that subsequently passed verification.
PiecesDirtiedGood Count
// Number of pieces data was written to, that subsequently failed
@ -73,6 +75,8 @@ func (cs *ConnStats) wroteMsg(msg *pp.Message) {
}
func (cs *ConnStats) readMsg(msg *pp.Message) {
// We want to also handle extended metadata pieces here, but we wouldn't
// have decoded the extended payload yet.
switch msg.Type {
case pp.Piece:
cs.ChunksRead.Add(1)