diff --git a/client.go b/client.go index b1d39ac7..50f2136b 100644 --- a/client.go +++ b/client.go @@ -1332,7 +1332,6 @@ func (me *Client) replenishConnRequests(t *torrent, c *connection) { // Handle a received chunk from a peer. func (me *Client) downloadedChunk(t *torrent, c *connection, msg *pp.Message) error { chunksDownloadedCount.Add(1) - c.ChunksReceived++ req := newRequest(msg.Index, msg.Begin, pp.Integer(len(msg.Piece))) @@ -1344,6 +1343,7 @@ func (me *Client) downloadedChunk(t *torrent, c *connection, msg *pp.Message) er // Do we actually want this chunk? if _, ok := t.Pieces[req.Index].PendingChunkSpecs[req.chunkSpec]; !ok { unusedDownloadedChunksCount.Add(1) + c.UnwantedChunksReceived++ return nil } diff --git a/connection.go b/connection.go index 6f84c854..7a9db0f4 100644 --- a/connection.go +++ b/connection.go @@ -33,8 +33,8 @@ type connection struct { post chan pp.Message writeCh chan []byte - ChunksReceived int - UsefulChunksReceived int + UnwantedChunksReceived int + UsefulChunksReceived int lastMessageReceived time.Time completedHandshake time.Time @@ -127,8 +127,15 @@ func (cn *connection) setNumPieces(num int) error { return nil } +func eventAgeString(t time.Time) string { + if t.IsZero() { + return "never" + } + return fmt.Sprintf("%.2fs ago", time.Now().Sub(t).Seconds()) +} + func (cn *connection) WriteStatus(w io.Writer) { - fmt.Fprintf(w, "%-90s: %s completed, good chunks: %d/%d reqs: %d-%d, last msg: %.0fs ago age: %.1fmin last useful chunk: %s ago flags: ", fmt.Sprintf("%q: %s-%s", cn.PeerID, cn.Socket.LocalAddr(), cn.Socket.RemoteAddr()), cn.completedString(), cn.UsefulChunksReceived, cn.ChunksReceived, len(cn.Requests), len(cn.PeerRequests), time.Now().Sub(cn.lastMessageReceived).Seconds(), time.Now().Sub(cn.completedHandshake).Minutes(), time.Now().Sub(cn.lastUsefulChunkReceived)) + fmt.Fprintf(w, "%-90s: %s completed, good chunks: %d/%d reqs: %d-%d, last msg: %s, connected: %s, last useful chunk: %s, flags: ", fmt.Sprintf("%q: %s-%s", cn.PeerID, cn.Socket.LocalAddr(), cn.Socket.RemoteAddr()), cn.completedString(), cn.UsefulChunksReceived, cn.UnwantedChunksReceived+cn.UsefulChunksReceived, len(cn.Requests), len(cn.PeerRequests), eventAgeString(cn.lastMessageReceived), eventAgeString(cn.completedHandshake), eventAgeString(cn.lastUsefulChunkReceived)) c := func(b byte) { fmt.Fprintf(w, "%c", b) }