diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java index de219ff39b..6e362a41b9 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java @@ -155,6 +155,7 @@ public class I2PTunnelConnectClient extends I2PTunnelHTTPClientBase implements R Outproxy outproxy = null; long requestId = __requestId.incrementAndGet(); try { + s.setSoTimeout(INITIAL_SO_TIMEOUT); out = s.getOutputStream(); in = s.getInputStream(); String line, method = null, host = null, destination = null, restofline = null; @@ -283,6 +284,7 @@ public class I2PTunnelConnectClient extends I2PTunnelHTTPClientBase implements R } } newRequest.append("\r\n"); // HTTP spec + s.setSoTimeout(0); // do it break; } diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java index e4c61fed36..8554421cd0 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java @@ -393,6 +393,7 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn boolean shout = false; try { + s.setSoTimeout(INITIAL_SO_TIMEOUT); out = s.getOutputStream(); InputReader reader = new InputReader(s.getInputStream()); String line, method = null, protocol = null, host = null, destination = null; @@ -1040,6 +1041,7 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn } } newRequest.append("Connection: close\r\n\r\n"); + s.setSoTimeout(0); break; } else { newRequest.append(line).append("\r\n"); // HTTP spec diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClientBase.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClientBase.java index 6365f5d3a9..92cb2dca78 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClientBase.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClientBase.java @@ -13,6 +13,7 @@ import java.io.Reader; import java.io.UnsupportedEncodingException; import java.io.Writer; import java.net.Socket; +import java.net.SocketTimeoutException; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; @@ -61,6 +62,13 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem private static final int MAX_NONCE_COUNT = 1024; /** @since 0.9.11, moved to Base in 0.9.29 */ public static final String PROP_USE_OUTPROXY_PLUGIN = "i2ptunnel.useLocalOutproxy"; + /** + * This is a standard soTimeout, not a total timeout. + * We have no slowloris protection on the client side. + * See I2PTunnelHTTPServer or SAM's ReadLine if we need that. + * @since 0.9.33 + */ + protected static final int INITIAL_SO_TIMEOUT = 15*1000; private static final String ERR_AUTH1 = "HTTP/1.1 407 Proxy Authentication Required\r\n" + @@ -610,7 +618,9 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem if (out == null) return; String header; - if (usingWWWProxy) + if (ex instanceof SocketTimeoutException) + header = I2PTunnelHTTPServer.ERR_REQUEST_TIMEOUT; + else if (usingWWWProxy) header = getErrorPage(I2PAppContext.getGlobalContext(), "dnfp", ERR_DESTINATION_UNKNOWN); else header = getErrorPage(I2PAppContext.getGlobalContext(), "dnf", ERR_DESTINATION_UNKNOWN); diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java index 19b15d3ab5..9dbac300cb 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java @@ -156,7 +156,8 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer { "