]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Scale readahead with unchoked connections
authorMatt Joiner <anacrolix@gmail.com>
Sat, 10 Jan 2015 13:16:57 +0000 (00:16 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Sat, 10 Jan 2015 13:16:57 +0000 (00:16 +1100)
client.go
torrent.go

index 9809fd6699a16746ae985fbe09e644a67a51aae5..dadd87a0503f7b2c4189544bb356c68ed6900df5 100644 (file)
--- a/client.go
+++ b/client.go
@@ -287,7 +287,7 @@ func (cl *Client) readRaisePiecePriorities(t *torrent, off, _len int64) {
                return
        }
        cl.raisePiecePriority(t, index, piecePriorityNext)
-       for i := 0; i < 5; i++ {
+       for i := 0; i < t.numConnsUnchoked()-2; i++ {
                index++
                if index >= t.NumPieces() {
                        break
index 21a3e4130f2d5f6927b98c51e2bafc99fb1c5ecb..b05ff34f6af1b9277a782aa9a072c665666c8b7a 100644 (file)
@@ -77,6 +77,15 @@ type torrent struct {
        GotMetainfo <-chan struct{}
 }
 
+func (t *torrent) numConnsUnchoked() (num int) {
+       for _, c := range t.Conns {
+               if !c.PeerChoked {
+                       num++
+               }
+       }
+       return
+}
+
 func (t *torrent) addrActive(addr string) bool {
        if _, ok := t.HalfOpen[addr]; ok {
                return true