client.go | 2 +- torrent.go | 9 +++++++++ diff --git a/client.go b/client.go index 9809fd6699a16746ae985fbe09e644a67a51aae5..dadd87a0503f7b2c4189544bb356c68ed6900df5 100644 --- a/client.go +++ b/client.go @@ -287,7 +287,7 @@ if index >= t.NumPieces() { 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 21a3e4130f2d5f6927b98c51e2bafc99fb1c5ecb..b05ff34f6af1b9277a782aa9a072c665666c8b7a 100644 --- a/torrent.go +++ b/torrent.go @@ -77,6 +77,15 @@ gotMetainfo chan 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