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"
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 {
Begin: msg.Begin,
Piece: p,
})
+ uploadChunksPosted.Add(1)
case pp.Cancel:
req := newRequest(msg.Index, msg.Begin, msg.Length)
if !c.PeerCancel(req) {
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))
package torrent
import (
- "container/list"
+ "fmt"
+ "io"
pp "bitbucket.org/anacrolix/go.torrent/peer_protocol"
)
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 {
// 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) {
// }
// }
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)
}