From edfc9b14542ee3a19d97e6b3aedfeaffe0fb1c2e Mon Sep 17 00:00:00 2001 From: zzz <zzz@i2pmail.org> Date: Sun, 1 Jan 2023 13:08:25 -0500 Subject: [PATCH] I2CP: Reduce session limit to 50 Set limit to 0 if vmCommSystem i2ptunnel: Do not retry if session limit exceeded --- .../java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java | 4 +++- .../i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java | 4 +++- core/java/src/net/i2p/client/impl/I2PSessionImpl.java | 2 ++ router/java/src/net/i2p/router/client/ClientManager.java | 4 +++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java index 4ae4821eaf..b7e40f94da 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java @@ -489,7 +489,9 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna else msg = "Unable to connect to the router at " + getTunnel().host + ':' + portNum + " and build tunnels for the client"; - if (++retries < MAX_RETRIES) { + String exmsg = ise.getMessage(); + boolean fail = exmsg != null && exmsg.contains("session limit exceeded"); + if (!fail && ++retries < MAX_RETRIES) { if (log != null) log.log(msg + ", retrying in " + (RETRY_DELAY / 1000) + " seconds"); _log.error(msg + ", retrying in " + (RETRY_DELAY / 1000) + " seconds", ise); diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java index dab84d9e51..cddcef0c36 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java @@ -380,7 +380,9 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { else msg = "Unable to connect to the router at " + getTunnel().host + ':' + portNum + " and build tunnels for the server at " + remoteHost.getHostAddress() + ':' + remotePort; - if (++retries < MAX_RETRIES) { + String exmsg = ise.getMessage(); + boolean fail = exmsg != null && exmsg.contains("session limit exceeded"); + if (!fail && ++retries < MAX_RETRIES) { msg += ", retrying in " + (RETRY_DELAY / 1000) + " seconds"; this.l.log(msg); _log.error(msg); diff --git a/core/java/src/net/i2p/client/impl/I2PSessionImpl.java b/core/java/src/net/i2p/client/impl/I2PSessionImpl.java index 3ceea07a74..1d18b48b74 100644 --- a/core/java/src/net/i2p/client/impl/I2PSessionImpl.java +++ b/core/java/src/net/i2p/client/impl/I2PSessionImpl.java @@ -835,6 +835,8 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2 msg = "Failed to bind to the router on " + _options.getProperty(PROP_DOMAIN_SOCKET) + " and build tunnels"; else msg = "Cannot connect to the router on " + _hostname + ':' + _portNum + " and build tunnels"; + if (ioe.getMessage() != null) + msg += " - " + ioe.getMessage(); throw new I2PSessionException(getPrefix() + msg, ioe); } finally { if (success) { diff --git a/router/java/src/net/i2p/router/client/ClientManager.java b/router/java/src/net/i2p/router/client/ClientManager.java index b4757d0320..a8bc8f46ee 100644 --- a/router/java/src/net/i2p/router/client/ClientManager.java +++ b/router/java/src/net/i2p/router/client/ClientManager.java @@ -89,7 +89,7 @@ class ClientManager { /** 2 bytes, save 65535 for unknown */ private static final int MAX_SESSION_ID = 65534; private static final String PROP_MAX_SESSIONS = "i2cp.maxSessions"; - private static final int DEFAULT_MAX_SESSIONS = 100; + private static final int DEFAULT_MAX_SESSIONS = 50; /** 65535 */ public static final SessionId UNKNOWN_SESSION_ID = new SessionId(MAX_SESSION_ID + 1); @@ -431,6 +431,8 @@ class ClientManager { * @since 0.9.12 */ private SessionId locked_getNextSessionId() { + if (_ctx.commSystem().isDummy()) + return null; int max = Math.max(1, Math.min(2048, _ctx.getProperty(PROP_MAX_SESSIONS, DEFAULT_MAX_SESSIONS))); if (_runnerSessionIds.size() >= max) { _log.logAlways(Log.WARN, "Session refused, max is " + max + ", increase " + PROP_MAX_SESSIONS); -- GitLab