Router: New method to get bandwidth class, for efficiency

This commit is contained in:
zzz
2017-05-14 12:16:25 +00:00
parent e973185be1
commit ac788d973f
4 changed files with 40 additions and 18 deletions

View File

@@ -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

View File

@@ -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"))

View File

@@ -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 = "";

View File

@@ -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