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:
@ -75,6 +75,7 @@ public class PeerCoordinator implements PeerListener
|
||||
for(int i = 0; i < metainfo.getPieces(); i++)
|
||||
if (!bitfield.get(i))
|
||||
wantedPieces.add(new Piece(i));
|
||||
Collections.shuffle(wantedPieces);
|
||||
|
||||
// Install a timer to check the uploaders.
|
||||
timer.schedule(new PeerCheckerTask(this), CHECK_PERIOD, CHECK_PERIOD);
|
||||
|
@ -12,6 +12,7 @@ public class Piece implements Comparable {
|
||||
public Piece(int id) {
|
||||
this.id = id;
|
||||
this.peers = new HashSet();
|
||||
this.requested = false;
|
||||
}
|
||||
|
||||
public int compareTo(Object o) throws ClassCastException {
|
||||
|
Reference in New Issue
Block a user