From c455f15b2aff5ab88220d0a4cfc852f66caa366b Mon Sep 17 00:00:00 2001 From: zzz Date: Thu, 16 Aug 2018 18:39:07 +0000 Subject: [PATCH] i2ptunnel: Change read timeout defaults now that streaming read timeout works --- .../net/i2p/i2ptunnel/I2PTunnelClient.java | 32 ++++++++++++++++++- .../i2ptunnel/I2PTunnelHTTPClientBase.java | 6 +++- .../i2p/i2ptunnel/I2PTunnelHTTPServer.java | 5 +++ .../net/i2p/i2ptunnel/I2PTunnelIRCClient.java | 3 +- .../net/i2p/i2ptunnel/I2PTunnelIRCServer.java | 3 ++ .../net/i2p/i2ptunnel/I2PTunnelServer.java | 21 ++++++++++-- .../i2p/i2ptunnel/irc/I2PTunnelDCCServer.java | 3 ++ history.txt | 13 ++++++++ .../src/net/i2p/router/RouterVersion.java | 2 +- 9 files changed, 82 insertions(+), 6 deletions(-) diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClient.java index 7af54060cf..c3d359f641 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClient.java @@ -32,7 +32,8 @@ public class I2PTunnelClient extends I2PTunnelClientBase { * replacement for dests */ private final List _addrs; - private static final long DEFAULT_READ_TIMEOUT = 5*60*1000; // -1 + // We don't know what protocol, so we assume the application has its own timeout mechanism + private static final long DEFAULT_READ_TIMEOUT = -1; protected long readTimeout = DEFAULT_READ_TIMEOUT; private InternalSocketRunner _isr; @@ -107,7 +108,36 @@ public class I2PTunnelClient extends I2PTunnelClientBase { } } + /** + * Set the read idle timeout for newly-created connections (in + * milliseconds). After this time expires without data being reached from + * the I2P network, the connection itself will be closed. + * + * Less than or equal to 0 means forever. + * Default -1 (forever) as of 0.9.36 for standard tunnels, + * but extending classes may override. + * Prior to that, default was 5 minutes, but did not work + * due to streaming bugs. + * + * Applies only to future connections; + * calling this does not affect existing connections. + * + * @param ms in ms + */ public void setReadTimeout(long ms) { readTimeout = ms; } + + /** + * Get the read idle timeout for newly-created connections (in + * milliseconds). + * + * Less than or equal to 0 means forever. + * Default -1 (forever) as of 0.9.36 for standard tunnels, + * but extending classes may override. + * Prior to that, default was 5 minutes, but did not work + * due to streaming bugs. + * + * @return in ms + */ public long getReadTimeout() { return readTimeout; } protected void clientConnectionRun(Socket s) { diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClientBase.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClientBase.java index 60a63ab2d4..3e64286aed 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClientBase.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClientBase.java @@ -137,7 +137,11 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem } } - protected static final int DEFAULT_READ_TIMEOUT = 5*60*1000; + /** + * -1 (forever) as of 0.9.36, + * so that large POSTs won't timeout on the read side + */ + protected static final int DEFAULT_READ_TIMEOUT = -1; protected static final AtomicLong __requestId = new AtomicLong(); diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java index 1d51e776fe..a27201c307 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java @@ -88,6 +88,10 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer { private static final int MAX_HEADERS = 60; /** Includes request, just to prevent OOM DOS @since 0.9.20 */ private static final int MAX_TOTAL_HEADER_SIZE = 32*1024; + // Does not apply to header reads. + // We set it to forever so that it won't timeout when sending a large response. + // The server will presumably have its own timeout implemented for POST + private static final long DEFAULT_HTTP_READ_TIMEOUT = -1; private long _startedOn = 0L; private ConnThrottler _postThrottler; @@ -205,6 +209,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer { private void setupI2PTunnelHTTPServer(String spoofHost) { _spoofHost = (spoofHost != null && spoofHost.trim().length() > 0) ? spoofHost.trim() : null; getTunnel().getContext().statManager().createRateStat("i2ptunnel.httpserver.blockingHandleTime", "how long the blocking handle takes to complete", "I2PTunnel.HTTPServer", new long[] { 60*1000, 10*60*1000, 3*60*60*1000 }); + readTimeout = DEFAULT_HTTP_READ_TIMEOUT; } @Override diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java index 5e31425265..9007c7a4c1 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java @@ -30,7 +30,8 @@ public class I2PTunnelIRCClient extends I2PTunnelClientBase { /** list of Destination objects that we point at */ private final List _addrs; - private static final long DEFAULT_READ_TIMEOUT = 5*60*1000; // -1 + // application should ping timeout before this + private static final long DEFAULT_READ_TIMEOUT = 10*60*1000; protected long readTimeout = DEFAULT_READ_TIMEOUT; private final boolean _dccEnabled; private I2PTunnelDCCServer _DCCServer; diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCServer.java index 6d541b583c..09e964fc4a 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCServer.java @@ -73,6 +73,8 @@ public class I2PTunnelIRCServer extends I2PTunnelServer implements Runnable { private static final long HEADER_TIMEOUT = 15*1000; private static final long TOTAL_HEADER_TIMEOUT = 2 * HEADER_TIMEOUT; private static final int MAX_LINE_LENGTH = 1024; + // application should ping timeout before this + private static final long DEFAULT_IRC_READ_TIMEOUT = 10*60*1000; private final static String ERR_UNAVAILABLE = ":ircserver.i2p 499 you :" + @@ -134,6 +136,7 @@ public class I2PTunnelIRCServer extends I2PTunnelServer implements Runnable { // get the fake hostmask to use this.hostname = opts.getProperty(PROP_HOSTNAME, PROP_HOSTNAME_DEFAULT); + readTimeout = DEFAULT_IRC_READ_TIMEOUT; } @Override diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java index 381f514d0c..6f881bafef 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java @@ -62,8 +62,8 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { protected final Logging l; private I2PSSLSocketFactory _sslFactory; - private static final long DEFAULT_READ_TIMEOUT = 5*60*1000; - /** default timeout to 5 minutes - override if desired */ + private static final long DEFAULT_READ_TIMEOUT = -1; + /** default timeout - override if desired */ protected long readTimeout = DEFAULT_READ_TIMEOUT; /** do we use threads? default true (ignored for standard servers, always false) */ @@ -371,6 +371,17 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { * Set the read idle timeout for newly-created connections (in * milliseconds). After this time expires without data being reached from * the I2P network, the connection itself will be closed. + * + * Less than or equal to 0 means forever. + * Default -1 (forever) as of 0.9.36 for standard tunnels, + * but extending classes may override. + * Prior to that, default was 5 minutes, but did not work + * due to streaming bugs. + * + * Applies only to future connections; + * calling this does not affect existing connections. + * + * @param ms in ms */ public void setReadTimeout(long ms) { readTimeout = ms; @@ -380,6 +391,12 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { * Get the read idle timeout for newly-created connections (in * milliseconds). * + * Less than or equal to 0 means forever. + * Default -1 (forever) as of 0.9.36 for standard tunnels, + * but extending classes may override. + * Prior to that, default was 5 minutes, but did not work + * due to streaming bugs. + * * @return The read timeout used for connections */ public long getReadTimeout() { diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/irc/I2PTunnelDCCServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/irc/I2PTunnelDCCServer.java index 8b49b6995d..f548692236 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/irc/I2PTunnelDCCServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/irc/I2PTunnelDCCServer.java @@ -64,6 +64,8 @@ public class I2PTunnelDCCServer extends I2PTunnelServer { private static final int MAX_OUTGOING_PENDING = 20; private static final int MAX_OUTGOING_ACTIVE = 20; private static final long OUTBOUND_EXPIRE = 30*60*1000; + private static final long DEFAULT_DCC_READ_TIMEOUT = -1; + /** * There's no support for unsolicited incoming I2P connections, * so there's no server host or port parameters. @@ -79,6 +81,7 @@ public class I2PTunnelDCCServer extends I2PTunnelServer { _active = new ConcurrentHashMap(8); _resume = new ConcurrentHashMap(8); _sockList = new CopyOnWriteArrayList(); + readTimeout = DEFAULT_DCC_READ_TIMEOUT; } /** diff --git a/history.txt b/history.txt index 4ff4128974..b8a97b8a76 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,16 @@ +2018-08-16 zzz + * i2ptunnel: Change read timeout defaults now that streaming timeout works + +2018-08-13 zzz + * Console: Format part. tunnel rate + +2018-08-04 zzz + * Data: Check sooner for unknown sig type + * I2NP: Remove unused Stream methods + +2018-08-03 zzz + * NTCP2: Fix termination handling and padding calculation + 2018-08-02 zzz * i2psnark: Don't disconnect seeds if comments enabled (ticket #2288) * NTCP2: Send termination on idle timeout diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 9535f12e9f..f7d70ed0aa 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 = 23; + public final static long BUILD = 24; /** for example "-test" */ public final static String EXTRA = "-rc";