]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Improve status and logging
authorMatt Joiner <anacrolix@gmail.com>
Fri, 22 Aug 2014 07:33:17 +0000 (17:33 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 22 Aug 2014 07:33:17 +0000 (17:33 +1000)
client.go
connection.go
download_strategies.go
torrent.go

index fc5f92fdc11a7497fbc69e1f8a6cae71c3a9c780..023e4707e5b6497fa991308b93a8a555285e77c1 100644 (file)
--- a/client.go
+++ b/client.go
@@ -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) {
index e79b5d665839e6a15de8ec99b28a9f3fb513c2c1..00c92da63d412c90c337ddc6eb8a44ab794707b6 100644 (file)
@@ -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))
index 8ffa61fdac5e6b065ddef023231c6fc9999a2d70..d4c91a0000c1e3769c51d17b65077b3bce1401fc 100644 (file)
@@ -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) {
index 9fdb79d5817a1f4784410558a2ee3257da16e12f..c046897c366a62ef7284b0c3a24da1cd94afac7b 100644 (file)
@@ -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)
        }