From 85a0fe6b61d0f9bb73f3c08b74b61893566b73fb Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 4 Aug 2015 01:32:45 +1000 Subject: [PATCH] Drop peers for sending too many unwanted pieces So the algorithm is now, drop the worst half if they get too old, and drop any connection if it's ratio is poor. --- torrent.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/torrent.go b/torrent.go index 12eca584..66123a8e 100644 --- a/torrent.go +++ b/torrent.go @@ -745,14 +745,17 @@ func (t *torrent) extentPieces(off, _len int64) (pieces []int) { func (t *torrent) worstBadConn(cl *Client) *connection { wcs := t.worstConns(cl) heap.Init(wcs) - // A connection can only be bad if it's in the worst half, rounded down. - for wcs.Len() > (socketsPerTorrent+1)/2 { + for wcs.Len() != 0 { c := heap.Pop(wcs).(*connection) - // Give connections 1 minute to prove themselves. - if time.Since(c.completedHandshake) < time.Minute { - continue + if c.UnwantedChunksReceived >= 6 && c.UnwantedChunksReceived > c.UsefulChunksReceived { + return c + } + if wcs.Len() >= (socketsPerTorrent+1)/2 { + // Give connections 1 minute to prove themselves. + if time.Since(c.completedHandshake) > time.Minute { + return c + } } - return c } return nil } -- 2.48.1