forked from I2P_Developers/i2p.i2p
* CapacityCalculator: Small boost for connected peers, new peers, and
same-country peers; deduct for recently-unreachable peers
This commit is contained in:
@@ -61,6 +61,8 @@ public abstract class CommSystemFacade implements Service {
|
||||
public boolean isEstablished(Hash dest) { return false; }
|
||||
public byte[] getIP(Hash dest) { return null; }
|
||||
public void queueLookup(byte[] ip) {}
|
||||
/** @since 0.8.11 */
|
||||
public String getOurCountry() { return null; }
|
||||
public String getCountry(Hash peer) { return null; }
|
||||
public String getCountryName(String code) { return code; }
|
||||
public String renderPeerHTML(Hash peer) {
|
||||
|
||||
@@ -15,6 +15,13 @@ class CapacityCalculator {
|
||||
|
||||
/** the calculator estimates over a 1 hour period */
|
||||
private static long ESTIMATE_PERIOD = 60*60*1000;
|
||||
|
||||
// total of all possible bonuses should be less than 4, since
|
||||
// crappy peers start at 1 and the base is 5.
|
||||
private static final double BONUS_NEW = 1.25;
|
||||
private static final double BONUS_ESTABLISHED = 1;
|
||||
private static final double BONUS_SAME_COUNTRY = .85;
|
||||
private static final double PENALTY_UNREACHABLE = 2;
|
||||
|
||||
public static double calc(PeerProfile profile) {
|
||||
double capacity;
|
||||
@@ -49,7 +56,20 @@ class CapacityCalculator {
|
||||
capacity = 1;
|
||||
else if (profile.getTunnelHistory().getLastRejectedProbabalistic() > now - 5*60*1000)
|
||||
capacity -= _context.random().nextInt(5);
|
||||
|
||||
|
||||
// boost new profiles
|
||||
if (now - profile.getFirstHeardAbout() < 45*60*1000)
|
||||
capacity += BONUS_NEW;
|
||||
// boost connected peers
|
||||
if (profile.isEstablished())
|
||||
capacity += BONUS_ESTABLISHED;
|
||||
// boost same country
|
||||
if (profile.isSameCountry())
|
||||
capacity += BONUS_SAME_COUNTRY;
|
||||
// penalize unreachable peers
|
||||
if (profile.wasUnreachable())
|
||||
capacity -= PENALTY_UNREACHABLE;
|
||||
|
||||
capacity += profile.getCapacityBonus();
|
||||
if (capacity < 0)
|
||||
capacity = 0;
|
||||
|
||||
@@ -99,6 +99,22 @@ public class PeerProfile {
|
||||
return getIsActive(5*60*1000);
|
||||
}
|
||||
|
||||
/** @since 0.8.11 */
|
||||
public boolean isEstablished() {
|
||||
return _context.commSystem().isEstablished(_peer);
|
||||
}
|
||||
|
||||
/** @since 0.8.11 */
|
||||
public boolean wasUnreachable() {
|
||||
return _context.commSystem().wasUnreachable(_peer);
|
||||
}
|
||||
|
||||
/** @since 0.8.11 */
|
||||
public boolean isSameCountry() {
|
||||
String us = _context.commSystem().getOurCountry();
|
||||
return us != null && us.equals(_context.commSystem().getCountry(_peer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this peer active at the moment (sending/receiving messages within the
|
||||
* given period?)
|
||||
|
||||
@@ -447,6 +447,15 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
_geoIP.add(ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return two-letter lower-case country code or null
|
||||
* @since 0.8.11
|
||||
*/
|
||||
@Override
|
||||
public String getOurCountry() {
|
||||
return _context.getProperty(GeoIP.PROP_IP_COUNTRY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the transport IP first because that lookup is fast,
|
||||
* then the SSU IP from the netDb.
|
||||
|
||||
Reference in New Issue
Block a user