Limit fast tier to 30 max

This commit is contained in:
zzz
2010-01-16 23:23:58 +00:00
parent abb62b93e3
commit 4803e60db4
2 changed files with 52 additions and 0 deletions

View File

@ -76,6 +76,7 @@ public class ProfileOrganizer {
*/
public static final String PROP_MINIMUM_FAST_PEERS = "profileOrganizer.minFastPeers";
public static final int DEFAULT_MINIMUM_FAST_PEERS = 8;
/** this is misnamed, it is really the max minimum number. */
private static final int DEFAULT_MAXIMUM_FAST_PEERS = 16;
/**
* Defines the minimum number of 'high capacity' peers that the organizer should
@ -674,6 +675,7 @@ public class ProfileOrganizer {
locked_unfailAsNecessary();
locked_promoteFastAsNecessary();
locked_demoteFastAsNecessary();
Collections.shuffle(_notFailingPeersList, _context.random());
@ -747,6 +749,28 @@ public class ProfileOrganizer {
return;
}
/**
* We want to put a cap on the fast pool, to use only a small set of routers
* for client tunnels for anonymity reasons. Also, unless we use only a small
* number, we don't really find out who the fast ones are.
* @since 0.7.10
*/
private void locked_demoteFastAsNecessary() {
int maxFastPeers = getMaximumFastPeers();
int numToDemote = _fastPeers.size() - maxFastPeers;
if (numToDemote > 0) {
if (_log.shouldLog(Log.INFO))
_log.info("Need to explicitly demote " + numToDemote + " peers from the fast group");
// sort by speed, slowest-first
Set<PeerProfile> sorted = new TreeSet(new SpeedComparator());
sorted.addAll(_fastPeers.values());
Iterator<PeerProfile> iter = sorted.iterator();
for (int i = 0; i < numToDemote; i++) {
_fastPeers.remove(iter.next().getPeer());
}
}
}
/** how many not failing/active peers must we have? */
private final static int MIN_NOT_FAILING_ACTIVE = 3;
/**
@ -916,6 +940,7 @@ public class ProfileOrganizer {
locked_calculateSpeedThresholdMean(reordered);
return;
}
/*****
Set speeds = new TreeSet();
for (Iterator iter = reordered.iterator(); iter.hasNext(); ) {
PeerProfile profile = (PeerProfile)iter.next();
@ -939,6 +964,7 @@ public class ProfileOrganizer {
}
if (_log.shouldLog(Log.INFO))
_log.info("Threshold value for speed: " + _thresholdSpeedValue + " out of speeds: " + speeds);
*****/
}
private void locked_calculateSpeedThresholdMean(Set reordered) {
@ -1196,6 +1222,10 @@ public class ProfileOrganizer {
return _context.getProperty(PROP_MINIMUM_FAST_PEERS, def);
}
/** fixme add config @since 0.7.10 */
protected int getMaximumFastPeers() {
return 30;
}
/**
* Defines the minimum number of 'fast' peers that the organizer should select. If

View File

@ -0,0 +1,22 @@
package net.i2p.router.peermanager;
import java.util.Comparator;
/**
* Order profiles by their speed (lowest first).
* @since 0.7.10
*/
class SpeedComparator implements Comparator<PeerProfile> {
public int compare(PeerProfile left, PeerProfile right) {
double lval = left.getSpeedValue();
double rval = right.getSpeedValue();
if (lval > rval)
return 1;
if (lval < rval)
return -1;
return 0;
}
}