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())
{
it.remove();
coordinator.removePeerFromPieces(peer);
continue;
}

View File

@ -153,6 +153,7 @@ public class PeerCoordinator implements PeerListener
Peer peer = (Peer)it.next();
peer.disconnect();
it.remove();
removePeerFromPieces(peer);
}
}
}
@ -511,17 +512,23 @@ public class PeerCoordinator implements PeerListener
{
// Unchoke some random other peer
unchokePeer();
synchronized(wantedPieces) {
// 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);
}
}
removePeerFromPieces(peer);
}
}
if (listener != null)
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);
}
}
}
}