From d4d3e24c6f097bb22aeb05375bf4fd2cf670ecd9 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 15 Jul 2018 10:09:58 +1000 Subject: [PATCH] Track metadata chunks read with its own Count --- client.go | 2 +- conn_stats.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 1091070e..c4278582 100644 --- a/client.go +++ b/client.go @@ -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: diff --git a/conn_stats.go b/conn_stats.go index 2f1a5030..a691fb34 100644 --- a/conn_stats.go +++ b/conn_stats.go @@ -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)