Cought a few places where peers could be taken off the list but not removed for the purposes of rarest-first calculations.

This commit is contained in:
ragnarok
2005-10-21 01:09:31 +00:00
committed by zzz
parent 3816c79193
commit 6534c84578
2 changed files with 15 additions and 7 deletions

View File

@ -69,6 +69,7 @@ class PeerCheckerTask extends TimerTask
if (!peer.isConnected()) if (!peer.isConnected())
{ {
it.remove(); it.remove();
coordinator.removePeerFromPieces(peer);
continue; continue;
} }

View File

@ -153,6 +153,7 @@ public class PeerCoordinator implements PeerListener
Peer peer = (Peer)it.next(); Peer peer = (Peer)it.next();
peer.disconnect(); peer.disconnect();
it.remove(); it.remove();
removePeerFromPieces(peer);
} }
} }
} }
@ -511,17 +512,23 @@ public class PeerCoordinator implements PeerListener
{ {
// Unchoke some random other peer // Unchoke some random other peer
unchokePeer(); unchokePeer();
synchronized(wantedPieces) { removePeerFromPieces(peer);
// Don't count disconnected peers for the rarest-first calculations
for(Iterator iter = wantedPieces.iterator(); iter.hasNext(); ) {
Piece piece = (Piece)iter.next();
piece.removePeer(peer);
}
}
} }
} }
if (listener != null) if (listener != null)
listener.peerChange(this, peer); listener.peerChange(this, peer);
} }
/** Called when a peer is removed, to prevent it from being used in
* rarest-first calculations.
*/
public void removePeerFromPieces(Peer peer) {
synchronized(wantedPieces) {
for(Iterator iter = wantedPieces.iterator(); iter.hasNext(); ) {
Piece piece = (Piece)iter.next();
piece.removePeer(peer);
}
}
}
} }