The rarest-first sort is stable, so randomize the wantedPieces list to ensure a healthy swarm when you have mostly seeders.

This commit is contained in:
ragnarok
2005-10-20 22:31:28 +00:00
committed by zzz
parent 05e2da7c22
commit 0b9e4967a0
2 changed files with 2 additions and 0 deletions

View File

@ -75,6 +75,7 @@ public class PeerCoordinator implements PeerListener
for(int i = 0; i < metainfo.getPieces(); i++) for(int i = 0; i < metainfo.getPieces(); i++)
if (!bitfield.get(i)) if (!bitfield.get(i))
wantedPieces.add(new Piece(i)); wantedPieces.add(new Piece(i));
Collections.shuffle(wantedPieces);
// Install a timer to check the uploaders. // Install a timer to check the uploaders.
timer.schedule(new PeerCheckerTask(this), CHECK_PERIOD, CHECK_PERIOD); timer.schedule(new PeerCheckerTask(this), CHECK_PERIOD, CHECK_PERIOD);

View File

@ -12,6 +12,7 @@ public class Piece implements Comparable {
public Piece(int id) { public Piece(int id) {
this.id = id; this.id = id;
this.peers = new HashSet(); this.peers = new HashSet();
this.requested = false;
} }
public int compareTo(Object o) throws ClassCastException { public int compareTo(Object o) throws ClassCastException {