diff --git a/router/java/src/net/i2p/router/CommSystemFacade.java b/router/java/src/net/i2p/router/CommSystemFacade.java index 0b5ebb24be2e88c8a2c94340316202bb23d2cf21..f9644f388ebe7d2a31b7250d56949437055b4cd9 100644 --- a/router/java/src/net/i2p/router/CommSystemFacade.java +++ b/router/java/src/net/i2p/router/CommSystemFacade.java @@ -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) { diff --git a/router/java/src/net/i2p/router/peermanager/CapacityCalculator.java b/router/java/src/net/i2p/router/peermanager/CapacityCalculator.java index 96570260c5de43c09b24efe897e8ca963b4a0b8c..76a6f1b587d7a8d661f4cddf4d179f48b1976b50 100644 --- a/router/java/src/net/i2p/router/peermanager/CapacityCalculator.java +++ b/router/java/src/net/i2p/router/peermanager/CapacityCalculator.java @@ -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; diff --git a/router/java/src/net/i2p/router/peermanager/PeerProfile.java b/router/java/src/net/i2p/router/peermanager/PeerProfile.java index 034f559ae43f4e045d2c19afb7b35aa9d4e174b5..e21c7c383f295394e32a99dc9b219c0d43c4a67c 100644 --- a/router/java/src/net/i2p/router/peermanager/PeerProfile.java +++ b/router/java/src/net/i2p/router/peermanager/PeerProfile.java @@ -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?) diff --git a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java index dfc2a07df434a1584cebe23abee15f067f70fbe9..2f6a478cd167bae768fb7e15e2964cc1554213f9 100644 --- a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java +++ b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java @@ -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.