]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Drop peers for sending too many unwanted pieces
authorMatt Joiner <anacrolix@gmail.com>
Mon, 3 Aug 2015 15:32:45 +0000 (01:32 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 3 Aug 2015 15:32:45 +0000 (01:32 +1000)
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

index 12eca58459ebcab79317df581b5af6f68f5cff58..66123a8e95e95820ac90593e12dc54d060bfd4a5 100644 (file)
@@ -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
 }