use of net.i2p.router.RouterContext in project i2p.i2p by i2p.
the class CapacityCalculator method calc.
public static double calc(PeerProfile profile) {
double capacity;
if (tooOld(profile)) {
capacity = 1;
} else {
RateStat acceptStat = profile.getTunnelCreateResponseTime();
RateStat rejectStat = profile.getTunnelHistory().getRejectionRate();
RateStat failedStat = profile.getTunnelHistory().getFailedRate();
double capacity10m = estimateCapacity(acceptStat, rejectStat, failedStat, 10 * 60 * 1000);
// if we actively know they're bad, who cares if they used to be good?
if (capacity10m <= 0) {
capacity = 0;
} else {
double capacity30m = estimateCapacity(acceptStat, rejectStat, failedStat, 30 * 60 * 1000);
double capacity60m = estimateCapacity(acceptStat, rejectStat, failedStat, 60 * 60 * 1000);
double capacity1d = estimateCapacity(acceptStat, rejectStat, failedStat, 24 * 60 * 60 * 1000);
capacity = capacity10m * periodWeight(10 * 60 * 1000) + capacity30m * periodWeight(30 * 60 * 1000) + capacity60m * periodWeight(60 * 60 * 1000) + capacity1d * periodWeight(24 * 60 * 60 * 1000);
}
}
// now take into account non-rejection tunnel rejections (which haven't
// incremented the rejection counter, since they were only temporary)
RouterContext context = profile.getContext();
long now = context.clock().now();
if (profile.getTunnelHistory().getLastRejectedTransient() > now - 5 * 60 * 1000)
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()) {
double bonus = BONUS_SAME_COUNTRY;
String b = context.getProperty(PROP_COUNTRY_BONUS);
if (b != null) {
try {
bonus = Double.parseDouble(b);
} catch (NumberFormatException nfe) {
}
}
capacity += bonus;
}
// penalize unreachable peers
if (profile.wasUnreachable())
capacity -= PENALTY_UNREACHABLE;
// credit non-floodfill to reduce conn limit issues at floodfills
// TODO only if we aren't floodfill ourselves?
RouterInfo ri = context.netDb().lookupRouterInfoLocally(profile.getPeer());
if (!FloodfillNetworkDatabaseFacade.isFloodfill(ri))
capacity += BONUS_NON_FLOODFILL;
// a tiny tweak to break ties and encourage closeness, -.25 to +.25
capacity -= profile.getXORDistance() * (BONUS_XOR / 128);
capacity += profile.getCapacityBonus();
if (capacity < 0)
capacity = 0;
return capacity;
}
use of net.i2p.router.RouterContext in project i2p.i2p by i2p.
the class ContextHelper method getContext.
/**
* @throws IllegalStateException if no context available
*/
public static RouterContext getContext(String contextId) {
List<RouterContext> contexts = RouterContext.listContexts();
if ((contexts == null) || (contexts.isEmpty()))
throw new IllegalStateException("No contexts. This is usually because the router is either starting up or shutting down.");
if ((contextId == null) || (contextId.trim().length() <= 0))
return contexts.get(0);
for (int i = 0; i < contexts.size(); i++) {
RouterContext context = contexts.get(i);
Hash hash = context.routerHash();
if (hash == null)
continue;
if (hash.toBase64().startsWith(contextId))
return context;
}
// not found, so just give them the first we can find
return contexts.get(0);
}
use of net.i2p.router.RouterContext in project i2p.i2p by i2p.
the class GeoIP method updateOurCountry.
/**
* Put our country code in the config, where others (such as Timestamper) can get it,
* and it will be there next time at startup.
*
* Does nothing in I2PAppContext
*/
private void updateOurCountry() {
if (!(_context instanceof RouterContext))
return;
RouterContext ctx = (RouterContext) _context;
String oldCountry = ctx.router().getConfigSetting(PROP_IP_COUNTRY);
Hash ourHash = ctx.routerHash();
// we should always have a RouterInfo by now, but we had one report of an NPE here
if (ourHash == null)
return;
String country = ctx.commSystem().getCountry(ourHash);
if (country != null && !country.equals(oldCountry)) {
ctx.router().saveConfig(PROP_IP_COUNTRY, country);
if (ctx.commSystem().isInBadCountry() && ctx.getProperty(Router.PROP_HIDDEN_HIDDEN) == null) {
String name = fullName(country);
if (name == null)
name = country;
_log.logAlways(Log.WARN, "Setting hidden mode to protect you in " + name + ", you may override on the network configuration page");
ctx.router().rebuildRouterInfo();
}
}
/**
*/
}
use of net.i2p.router.RouterContext in project i2p.i2p by i2p.
the class FakeInputStream method setUp.
@BeforeClass
public static void setUp() {
_context = new RouterContext(new Router());
_context.initAll();
}
use of net.i2p.router.RouterContext in project i2p.i2p by i2p.
the class UDPEndpointTestStandalone method main.
public static void main(String[] args) {
try {
System.out.println("Current dir: " + new java.io.File(".").getCanonicalPath());
} catch (Exception e) {
}
new java.io.File("udpEndpointTest.stats").delete();
Properties props = new Properties();
props.setProperty("stat.logFile", "udpEndpointTest.stats");
props.setProperty("stat.logFilters", "*");
props.setProperty("i2p.dummyClientFacade", "true");
props.setProperty("i2p.dummyNetDb", "true");
props.setProperty("i2p.dummyPeerManager", "true");
props.setProperty("i2p.dummyTunnelManager", "true");
props.setProperty("i2p.vmCommSystem", "true");
props.setProperty("i2np.bandwidth.inboundKBytesPerSecond", "9999");
props.setProperty("i2np.bandwidth.outboundKBytesPerSecond", "9999");
RouterContext ctx = new RouterContext(null, props);
ctx.initAll();
UDPEndpointTestStandalone test = new UDPEndpointTestStandalone(ctx);
test.runTest(2);
}
Aggregations