Transports: Adjust conn limits for some platforms

This commit is contained in:
zzz
2021-02-25 06:25:55 -05:00
parent e63e9c58a8
commit c609e43d90

View File

@@ -46,6 +46,7 @@ import net.i2p.util.Log;
import net.i2p.util.SimpleTimer;
import net.i2p.util.SystemVersion;
import net.i2p.util.Translate;
import net.i2p.util.VersionComparator;
/**
* Defines a way to send a message to another peer and start listening for messages
@@ -93,6 +94,11 @@ public abstract class TransportImpl implements Transport {
_IPMap = new LHMCache<Hash, byte[]>(size);
}
/** 50/100/150/250/450/550/700 for BW Tiers K/L/M/N/O/P/X */
private static final int MAX_CONNECTION_FACTOR = 50;
// see constructor
private final boolean REBALANCE_NTCP;
/**
* Initialize the new transport
*
@@ -119,6 +125,12 @@ public abstract class TransportImpl implements Transport {
_wasUnreachableEntries = new ConcurrentHashMap<Hash, Long>(32);
_localAddresses = new ConcurrentHashSet<InetAddress>(4);
_context.simpleTimer2().addPeriodicEvent(new CleanupUnreachable(), 2 * UNREACHABLE_PERIOD, UNREACHABLE_PERIOD / 2);
// if the router is slow, or we have the i2prouter script on linux that bumps the ulimit,
// allow more NTCP2 and less SSU. See getMaxConnections() below.
String installed = _context.getProperty("router.firstVersion");
REBALANCE_NTCP = SystemVersion.isSlow() ||
(!SystemVersion.isMac() && !SystemVersion.isWindows() &&
SystemVersion.hasWrapper() && installed != null && VersionComparator.comp(installed, "0.9.33") >= 0);
}
/**
@@ -139,9 +151,6 @@ public abstract class TransportImpl implements Transport {
*/
public abstract int countActiveSendPeers();
/** ...and 50/100/150/200/250 for BW Tiers K/L/M/N/O */
private static final int MAX_CONNECTION_FACTOR = 50;
/** Per-transport connection limit */
public int getMaxConnections() {
if (_context.commSystem().isDummy())
@@ -190,9 +199,19 @@ public abstract class TransportImpl implements Transport {
def *= 17; def /= 10;
}
// increase limit for SSU, for now
if (style.equals("SSU"))
//def = def * 3 / 2;
def *= 3;
if (style.equals("SSU")) {
if (REBALANCE_NTCP) {
def *= 5; def /= 2;
} else {
def *= 3;
}
} else if (style.equals("NTCP")) {
if (REBALANCE_NTCP) {
def *= 3; def /= 2;
if (def > 1500)
def = 1500;
}
}
return _context.getProperty(maxProp, def);
}