From ac788d973f6decffa31870fe2bd9625473363087 Mon Sep 17 00:00:00 2001 From: zzz Date: Sun, 14 May 2017 12:16:25 +0000 Subject: [PATCH] Router: New method to get bandwidth class, for efficiency --- history.txt | 11 +++++ router/java/src/net/i2p/router/Router.java | 42 ++++++++++++------- .../src/net/i2p/router/RouterVersion.java | 2 +- .../i2p/router/transport/TransportImpl.java | 3 +- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/history.txt b/history.txt index e88f9933f..fdfe5affd 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,14 @@ +2017-05-14 zzz + * i2psnark: Fix HTML double-escape (ticket #1992) + * Router: New method to get bandwidth class + +2017-05-12 zzz + * i2psnark: Better handling of read-only i2psnark dir (ticket #1990) + +2017-05-10 zzz + * Debian: Fix apparmor profile (ticket #1986) + * SusiDNS: Fix display of default subscription + 2017-05-05 zzz * Blockfile: Move from i2p.jar to addressbook.jar * i2psnark: Initial support for ut_comment, no UI yet diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java index a45ab6d9d..1a4b0c9b7 100644 --- a/router/java/src/net/i2p/router/Router.java +++ b/router/java/src/net/i2p/router/Router.java @@ -949,41 +949,53 @@ public class Router implements RouterClock.ClockShiftListener { public static final char CAPABILITY_NEW_TUNNEL = 'T'; /** + * The current bandwidth class. * For building our RI. Not for external use. * - * @return a capabilities string to be added to the RI + * @return a character to be added to the RI, one of "KLMNOPX" + * @since 0.9.31 */ - public String getCapabilities() { - StringBuilder rv = new StringBuilder(4); + public char getBandwidthClass() { int bwLim = Math.min(_context.bandwidthLimiter().getInboundKBytesPerSecond(), _context.bandwidthLimiter().getOutboundKBytesPerSecond()); bwLim = (int)(bwLim * getSharePercentage()); String force = _context.getProperty(PROP_FORCE_BWCLASS); if (force != null && force.length() > 0) { - rv.append(force.charAt(0)); + return force.charAt(0); } else if (bwLim < 12) { - rv.append(CAPABILITY_BW12); + return CAPABILITY_BW12; } else if (bwLim <= 48) { - rv.append(CAPABILITY_BW32); + return CAPABILITY_BW32; } else if (bwLim <= 64) { - rv.append(CAPABILITY_BW64); + return CAPABILITY_BW64; } else if (bwLim <= 128) { - rv.append(CAPABILITY_BW128); + return CAPABILITY_BW128; } else if (bwLim <= 256) { - rv.append(CAPABILITY_BW256); + return CAPABILITY_BW256; } else if (bwLim <= 2000) { // TODO adjust threshold // 512 supported as of 0.9.18; - // Add 256 as well for compatibility - rv.append(CAPABILITY_BW512); - rv.append(CAPABILITY_BW256); + return CAPABILITY_BW512; } else { // Unlimited supported as of 0.9.18; - // Add 256 as well for compatibility - rv.append(CAPABILITY_BW_UNLIMITED); - rv.append(CAPABILITY_BW256); + return CAPABILITY_BW_UNLIMITED; } + } + /** + * For building our RI. Not for external use. + * + * @return a capabilities string to be added to the RI + */ + public String getCapabilities() { + StringBuilder rv = new StringBuilder(4); + char bw = getBandwidthClass(); + rv.append(bw); + // 512 and unlimited supported as of 0.9.18; + // Add 256 as well for compatibility + if (bw == CAPABILITY_BW512 || bw == CAPABILITY_BW_UNLIMITED) + rv.append(CAPABILITY_BW256); + // if prop set to true, don't tell people we are ff even if we are if (_context.netDb().floodfillEnabled() && !_context.getBooleanProperty("router.hideFloodfillParticipant")) diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 0725033fa..f6e6df3a5 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 3; + public final static long BUILD = 4; /** for example "-test" */ public final static String EXTRA = ""; diff --git a/router/java/src/net/i2p/router/transport/TransportImpl.java b/router/java/src/net/i2p/router/transport/TransportImpl.java index f132f47b7..19987fd56 100644 --- a/router/java/src/net/i2p/router/transport/TransportImpl.java +++ b/router/java/src/net/i2p/router/transport/TransportImpl.java @@ -142,9 +142,8 @@ public abstract class TransportImpl implements Transport { maxProp = "i2np." + style.toLowerCase(Locale.US) + ".maxConnections"; int def = MAX_CONNECTION_FACTOR; // get it from here, not the RI, to avoid deadlock - String caps = _context.router().getCapabilities(); + char bw = _context.router().getBandwidthClass(); - char bw = caps.charAt(0); switch (bw) { case Router.CAPABILITY_BW12: case 'u': // unknown