From 78caa4533b46276da4c5770011f23c155fcf22a1 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 11 Jan 2015 00:16:57 +1100 Subject: [PATCH] Scale readahead with unchoked connections --- client.go | 2 +- torrent.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 9809fd66..dadd87a0 100644 --- 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 diff --git a/torrent.go b/torrent.go index 21a3e413..b05ff34f 100644 --- a/torrent.go +++ b/torrent.go @@ -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 -- 2.48.1