Improve status and logging
This commit is contained in:
parent
60df4e100c
commit
95d5d4a30c
|
@ -47,6 +47,7 @@ var (
|
|||
chunksDownloadedCount = expvar.NewInt("chunksDownloadedCount")
|
||||
peersFoundByDHT = expvar.NewInt("peersFoundByDHT")
|
||||
peersFoundByPEX = expvar.NewInt("peersFoundByPEX")
|
||||
uploadChunksPosted = expvar.NewInt("uploadChunksPosted")
|
||||
)
|
||||
|
||||
const extensionBytes = "\x00\x00\x00\x00\x00\x10\x00\x00"
|
||||
|
@ -122,6 +123,7 @@ func (cl *Client) WriteStatus(w io.Writer) {
|
|||
fmt.Fprintf(w, "DHT nodes: %d\n", cl.dHT.NumNodes())
|
||||
fmt.Fprintf(w, "DHT Server ID: %x\n", cl.dHT.IDString())
|
||||
}
|
||||
cl.downloadStrategy.WriteStatus(w)
|
||||
fmt.Fprintln(w)
|
||||
for _, t := range cl.torrents {
|
||||
fmt.Fprintf(w, "%s: %f%%\n", t.Name(), func() float32 {
|
||||
|
@ -714,6 +716,7 @@ func (me *Client) connectionLoop(t *torrent, c *connection) error {
|
|||
Begin: msg.Begin,
|
||||
Piece: p,
|
||||
})
|
||||
uploadChunksPosted.Add(1)
|
||||
case pp.Cancel:
|
||||
req := newRequest(msg.Index, msg.Begin, msg.Length)
|
||||
if !c.PeerCancel(req) {
|
||||
|
|
|
@ -121,26 +121,19 @@ func (cn *connection) WriteStatus(w io.Writer) {
|
|||
c := func(b byte) {
|
||||
fmt.Fprintf(w, "%c", b)
|
||||
}
|
||||
// https://trac.transmissionbt.com/wiki/PeerStatusText
|
||||
if cn.PeerInterested && !cn.Choked {
|
||||
c('O')
|
||||
}
|
||||
// Inspired by https://trac.transmissionbt.com/wiki/PeerStatusText
|
||||
if len(cn.Requests) != 0 {
|
||||
c('D')
|
||||
}
|
||||
if cn.PeerChoked && cn.Interested {
|
||||
c('d')
|
||||
}
|
||||
if !cn.Choked && cn.PeerInterested {
|
||||
c('U')
|
||||
} else {
|
||||
c('u')
|
||||
}
|
||||
if !cn.PeerChoked && !cn.Interested {
|
||||
c('K')
|
||||
}
|
||||
if !cn.Choked && !cn.PeerInterested {
|
||||
c('?')
|
||||
if !cn.Choked {
|
||||
if cn.PeerInterested {
|
||||
c('U')
|
||||
} else {
|
||||
c('u')
|
||||
}
|
||||
}
|
||||
if cn.Discovery != 0 {
|
||||
c(byte(cn.Discovery))
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package torrent
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
pp "bitbucket.org/anacrolix/go.torrent/peer_protocol"
|
||||
)
|
||||
|
@ -14,12 +15,15 @@ type DownloadStrategy interface {
|
|||
TorrentPrioritize(t *torrent, off, _len int64)
|
||||
TorrentGotChunk(t *torrent, r request)
|
||||
TorrentGotPiece(t *torrent, piece int)
|
||||
WriteStatus(w io.Writer)
|
||||
}
|
||||
|
||||
type DefaultDownloadStrategy struct {
|
||||
heat map[*torrent]map[request]int
|
||||
}
|
||||
|
||||
func (me *DefaultDownloadStrategy) WriteStatus(w io.Writer) {}
|
||||
|
||||
func (s *DefaultDownloadStrategy) FillRequests(t *torrent, c *connection) {
|
||||
if c.Interested {
|
||||
if c.PeerChoked {
|
||||
|
@ -115,7 +119,18 @@ type responsiveDownloadStrategy struct {
|
|||
// the last piece read for a given torrent.
|
||||
Readahead int
|
||||
lastReadPiece map[*torrent]int
|
||||
priorities map[*torrent]*list.List
|
||||
priorities map[*torrent]map[request]struct{}
|
||||
}
|
||||
|
||||
func (me *responsiveDownloadStrategy) WriteStatus(w io.Writer) {
|
||||
fmt.Fprintf(w, "Priorities:\n")
|
||||
for t, pp := range me.priorities {
|
||||
fmt.Fprintf(w, "\t%s:", t.Name())
|
||||
for r := range pp {
|
||||
fmt.Fprintf(w, "%v ", r)
|
||||
}
|
||||
fmt.Fprintln(w)
|
||||
}
|
||||
}
|
||||
|
||||
func (me *responsiveDownloadStrategy) TorrentStarted(t *torrent) {
|
||||
|
|
|
@ -233,6 +233,7 @@ func (t *torrent) WriteStatus(w io.Writer) {
|
|||
// }
|
||||
// }
|
||||
fmt.Fprintf(w, "Pending peers: %d\n", len(t.Peers))
|
||||
fmt.Fprintf(w, "Active peers: %d\n", len(t.Conns))
|
||||
for _, c := range t.Conns {
|
||||
c.WriteStatus(w)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue