client.go | 2 +- conn_stats.go | 4 ++++ diff --git a/client.go b/client.go index 1091070e81781f45dd818654cc5209a336d08335..c4278582ac7dcadf9b857060d9eedf68189a0976 100644 --- a/client.go +++ b/client.go @@ -890,6 +890,7 @@ } 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 @@ if begin < 0 || begin >= len(payload) { 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: diff --git a/conn_stats.go b/conn_stats.go index 2f1a50300ee92557342b212be54e2e8722f05b69..a691fb342f24bbe30fac479840097c8901e5dd5c 100644 --- a/conn_stats.go +++ b/conn_stats.go @@ -29,6 +29,8 @@ ChunksRead Count 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) 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)