}
}
+// 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)))
return nil
}
+ c.UsefulChunksReceived++
+ c.lastUsefulChunkReceived = time.Now()
+
// Write the chunk out.
err := t.WriteChunk(int(msg.Index), int64(msg.Begin), msg.Piece)
if err != nil {
post chan pp.Message
writeCh chan []byte
+ ChunksReceived int
+ UsefulChunksReceived int
+
+ lastMessageReceived time.Time
+ completedHandshake time.Time
+ lastUsefulChunkReceived time.Time
+
// Stuff controlled by the local peer.
Interested bool
Choked bool
closing: make(chan struct{}),
writeCh: make(chan []byte),
post: make(chan pp.Message),
+
+ completedHandshake: time.Now(),
}
go c.writer()
go c.writeOptimizer(time.Minute)
}
func (cn *connection) WriteStatus(w io.Writer) {
- fmt.Fprintf(w, "%q: %s-%s: %s completed, reqs: %d-%d, flags: ", cn.PeerID, cn.Socket.LocalAddr(), cn.Socket.RemoteAddr(), cn.completedString(), len(cn.Requests), len(cn.PeerRequests))
+ 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))
c := func(b byte) {
fmt.Fprintf(w, "%c", b)
}