diff --git a/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java b/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java index a3eebc33293ef4ab6bbb673be917e871cd69993d..875223c21bd139095af330420367239f8356d75b 100644 --- a/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java +++ b/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java @@ -894,7 +894,7 @@ public class ProfileOrganizer { Set<PeerProfile> sorted = new TreeSet(new SpeedComparator()); sorted.addAll(_fastPeers.values()); Iterator<PeerProfile> iter = sorted.iterator(); - for (int i = 0; i < numToDemote; i++) { + for (int i = 0; i < numToDemote && iter.hasNext(); i++) { _fastPeers.remove(iter.next().getPeer()); } } diff --git a/router/java/src/net/i2p/router/peermanager/SpeedComparator.java b/router/java/src/net/i2p/router/peermanager/SpeedComparator.java index 793501e235cca1c72efbcea9933d4d078b8ef00a..aad404335781fe6c4591db36b0c279d0ab7e9c5a 100644 --- a/router/java/src/net/i2p/router/peermanager/SpeedComparator.java +++ b/router/java/src/net/i2p/router/peermanager/SpeedComparator.java @@ -2,6 +2,8 @@ package net.i2p.router.peermanager; import java.util.Comparator; +import net.i2p.data.DataHelper; + /** * Order profiles by their speed (lowest first). * @since 0.7.10 @@ -17,6 +19,14 @@ class SpeedComparator implements Comparator<PeerProfile> { return 1; if (lval < rval) return -1; - return 0; + + // we don't wan't to return 0 so profiles don't vanish in the TreeSet + lval = left.getCapacityValue(); + rval = right.getCapacityValue(); + if (lval > rval) + return 1; + if (lval < rval) + return -1; + return DataHelper.compareTo(right.getPeer().getData(), left.getPeer().getData()); } }