java.lang.Object
net.i2p.router.peermanager.CapacityCalculator
Estimate how many of our tunnels the peer can join per hour.
Combines measured tunnel accept/reject/fail rates across three time windows (10 min, 1 hour, 1 day) with capability-based penalties and bonuses (congestion caps, unreachable, established connection, XOR distance). Peers with no recent activity (tooOld) default to 1 tunnel/hour. New peers receive a time-based penalty that ramps from PENALTY_NEW down to 0 over the first 2 hours of observed lifetime.
Field Summary
Modifier and TypeFieldDescriptionprivate static doubleCached moderate congestion penalty.private static StringConfig text the cached D penalty was parsed from.private static doubleCached severe congestion penalty.private static StringConfig text the cached E penalty was parsed from.private static final doubleBonus for a peer we are connected to.private static final doubleBonus when the last send to the peer succeeded.private static final doubleBonus for a peer that is not a floodfill.private static final doubleBonus for a recent send success.private static final doubleBonus for a peer close in XOR distance.private static longThe calculator estimates over a 1 hour period.(package private) static final longUsed to adjust each period so that we keep trying to expand the peer's capacity.private static final doubleDefault penalty for moderate congestion.private static final doubleDefault penalty for severe congestion.private static final doublePenalty for a peer with the low bandwidth flag.private static final doublePenalty when the last send to the peer failed.private static final doublePenalty for a peer never tried.private static final doublePenalty for a peer without the reachable flag.private static final doublePenalty for a peer with no router info.private static final doublePenalty for a recent send failure.private static final doublePenalty for a peer with the unreachable flag.private static final doublePenalty for a peer marked unreachable.static final StringProperty for bonus applied to peers in the same country.private static final StringConfig key for the moderate congestion penalty.private static final StringConfig key for the severe congestion penalty.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionstatic doublecalc(PeerProfile profile) Calculate the capacity for the given peer profile.private static doubleestimateCapacity(RateStat acceptStat, RateStat rejectStat, RateStat failedStat, int period) Compute a tunnel accept capacity-per-hour for the given period This is perhaps the most critical part of the peer ranking and selection system, so adjust with great care and testing to ensure good network performance and prevent congestion collapse.private static doubleGet the D-cap penalty, cached to avoid repeated Double.parseDouble.private static doubleGet the E-cap penalty, cached to avoid repeated Double.parseDouble.private static booleantooOld(PeerProfile profile, long now) If we haven't heard from them in an hour, they aren't too useful.
Field Details
PROP_COUNTRY_BONUS
Property for bonus applied to peers in the same country.- See Also:
GROWTH_FACTOR
static final long GROWTH_FACTORUsed to adjust each period so that we keep trying to expand the peer's capacity.- See Also:
ESTIMATE_PERIOD
private static long ESTIMATE_PERIODThe calculator estimates over a 1 hour period.BONUS_ESTABLISHED
private static final double BONUS_ESTABLISHEDBonus for a peer we are connected to. The total of all the bonuses stays under 4, since bad peers start at 1 and the base is 5.- See Also:
BONUS_XOR
private static final double BONUS_XORBonus for a peer close in XOR distance.- See Also:
PENALTY_NEW
private static final double PENALTY_NEWPenalty for a peer never tried.- See Also:
PENALTY_UNREACHABLE
private static final double PENALTY_UNREACHABLEPenalty for a peer marked unreachable.- See Also:
PENALTY_NO_RI
private static final double PENALTY_NO_RIPenalty for a peer with no router info.- See Also:
PENALTY_L_CAP
private static final double PENALTY_L_CAPPenalty for a peer with the low bandwidth flag.- See Also:
PENALTY_NO_R_CAP
private static final double PENALTY_NO_R_CAPPenalty for a peer without the reachable flag.- See Also:
PENALTY_U_CAP
private static final double PENALTY_U_CAPPenalty for a peer with the unreachable flag.- See Also:
PENALTY_LAST_SEND_FAIL
private static final double PENALTY_LAST_SEND_FAILPenalty when the last send to the peer failed.- See Also:
PROP_D_CAP
Config key for the moderate congestion penalty.- See Also:
PENALTY_CAP_D
private static final double PENALTY_CAP_DDefault penalty for moderate congestion.- See Also:
PROP_E_CAP
Config key for the severe congestion penalty.- See Also:
PENALTY_CAP_E
private static final double PENALTY_CAP_EDefault penalty for severe congestion.- See Also:
PENALTY_RECENT_SEND_FAIL
private static final double PENALTY_RECENT_SEND_FAILPenalty for a recent send failure.- See Also:
_cachedDcapProp
Config text the cached D penalty was parsed from._cachedDcap
private static double _cachedDcapCached moderate congestion penalty._cachedEcapProp
Config text the cached E penalty was parsed from._cachedEcap
private static double _cachedEcapCached severe congestion penalty.BONUS_LAST_SEND_SUCCESS
private static final double BONUS_LAST_SEND_SUCCESSBonus when the last send to the peer succeeded.- See Also:
BONUS_RECENT_SEND_SUCCESS
private static final double BONUS_RECENT_SEND_SUCCESSBonus for a recent send success.- See Also:
BONUS_NON_FLOODFILL
private static final double BONUS_NON_FLOODFILLBonus for a peer that is not a floodfill. A bonus for the others, not a penalty for floodfills, keeps the floodfills at the default.- See Also:
Constructor Details
CapacityCalculator
private CapacityCalculator()Prevents instantiating the utility class.
Method Details
getCachedDcap
Get the D-cap penalty, cached to avoid repeated Double.parseDouble.- Parameters:
ctx- the router context, source of the d-cap property- Returns:
- the cached dcap
getCachedEcap
Get the E-cap penalty, cached to avoid repeated Double.parseDouble.- Parameters:
ctx- the router context, source of the e-cap property- Returns:
- the cached ecap
calc
Calculate the capacity for the given peer profile.- Parameters:
profile- the peer profile- Returns:
- the calculated capacity
tooOld
If we haven't heard from them in an hour, they aren't too useful.- Parameters:
profile- the peer profile whose activity is checkednow- the current time in ms since epoch- Returns:
- true if the peer has not been active in the last hour
estimateCapacity
private static double estimateCapacity(RateStat acceptStat, RateStat rejectStat, RateStat failedStat, int period) Compute a tunnel accept capacity-per-hour for the given period This is perhaps the most critical part of the peer ranking and selection system, so adjust with great care and testing to ensure good network performance and prevent congestion collapse.The baseline or "growth factor" is 5. Rejects will not reduce the baseline. Failures will. Let A = accepts, R = rejects, F = fails.
- Parameters:
acceptStat- Accept counter (1 = 1 accept)rejectStat- Reject counter (1 = 1 reject)failedStat- Failed counter (100 = 1 fail)period- the rate period in ms whose rates are evaluated- Returns:
- estimated and adjusted accepts per hour, for the given period which is, more or less, max(0, 5 + (A * (A / (A + 2R))) - (4 * F))