Changeset 6cd5f1d8


Ignore:
Timestamp:
Nov 23, 2017 5:44:03 PM (3 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
7f6ba8cd
Parents:
2a279582
Message:

i2ptunnel: Add timeout to header reads for CONNECT, HTTP, and SOCKS client proxies
Clean up SOCKS exceptions

Location:
apps/i2ptunnel/java/src/net/i2p/i2ptunnel
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java

    r2a279582 r6cd5f1d8  
    156156        long requestId = __requestId.incrementAndGet();
    157157        try {
     158            s.setSoTimeout(INITIAL_SO_TIMEOUT);
    158159            out = s.getOutputStream();
    159160            in = s.getInputStream();
     
    284285                    }
    285286                    newRequest.append("\r\n"); // HTTP spec
     287                    s.setSoTimeout(0);
    286288                    // do it
    287289                    break;
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java

    r2a279582 r6cd5f1d8  
    394394
    395395        try {
     396            s.setSoTimeout(INITIAL_SO_TIMEOUT);
    396397            out = s.getOutputStream();
    397398            InputReader reader = new InputReader(s.getInputStream());
     
    10411042                    }
    10421043                    newRequest.append("Connection: close\r\n\r\n");
     1044                    s.setSoTimeout(0);
    10431045                    break;
    10441046                } else {
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClientBase.java

    r2a279582 r6cd5f1d8  
    1414import java.io.Writer;
    1515import java.net.Socket;
     16import java.net.SocketTimeoutException;
    1617import java.net.URI;
    1718import java.net.URISyntaxException;
     
    6263    /** @since 0.9.11, moved to Base in 0.9.29 */
    6364    public static final String PROP_USE_OUTPROXY_PLUGIN = "i2ptunnel.useLocalOutproxy";
     65    /**
     66     *  This is a standard soTimeout, not a total timeout.
     67     *  We have no slowloris protection on the client side.
     68     *  See I2PTunnelHTTPServer or SAM's ReadLine if we need that.
     69     *  @since 0.9.33
     70     */
     71    protected static final int INITIAL_SO_TIMEOUT = 15*1000;
    6472
    6573    private static final String ERR_AUTH1 =
     
    611619            return;
    612620        String header;
    613         if (usingWWWProxy)
     621        if (ex instanceof SocketTimeoutException)
     622            header = I2PTunnelHTTPServer.ERR_REQUEST_TIMEOUT;
     623        else if (usingWWWProxy)
    614624            header = getErrorPage(I2PAppContext.getGlobalContext(), "dnfp", ERR_DESTINATION_UNKNOWN);
    615625        else
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java

    r2a279582 r6cd5f1d8  
    157157         "</body></html>";
    158158
    159     private final static String ERR_REQUEST_TIMEOUT =
     159    /** @since protected since 0.9.33 for I2PTunnelHTTPClientBase, was private */
     160    protected final static String ERR_REQUEST_TIMEOUT =
    160161         "HTTP/1.1 408 Request timeout\r\n"+
    161162         "Content-Type: text/html; charset=iso-8859-1\r\n"+
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/I2PSOCKSIRCTunnel.java

    r2a279582 r6cd5f1d8  
    88
    99import java.net.Socket;
     10import java.net.SocketException;
    1011import java.util.concurrent.atomic.AtomicInteger;
    1112
     
    4950        try {
    5051            //_log.error("SOCKS IRC Tunnel Start");
     52            try {
     53                s.setSoTimeout(INITIAL_SO_TIMEOUT);
     54            } catch (SocketException ioe) {}
    5155            SOCKSServer serv = SOCKSServerFactory.createSOCKSServer(_context, s, getTunnel().getClientOptions());
    5256            Socket clientSock = serv.getClientSocket();
     57            try {
     58                s.setSoTimeout(0);
     59            } catch (SocketException ioe) {}
    5360            I2PSocket destSock = serv.getDestinationI2PSocket(this);
    5461            StringBuffer expectedPong = new StringBuffer();
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/I2PSOCKSTunnel.java

    r2a279582 r6cd5f1d8  
    88
    99import java.net.Socket;
     10import java.net.SocketException;
    1011import java.util.ArrayList;
    1112import java.util.HashMap;
     
    2728
    2829public class I2PSOCKSTunnel extends I2PTunnelClientBase {
     30
     31    /**
     32     *  This is a standard soTimeout, not a total timeout.
     33     *  We have no slowloris protection on the client side.
     34     *  See I2PTunnelHTTPServer or SAM's ReadLine if we need that.
     35     *  @since 0.9.33
     36     */
     37    protected static final int INITIAL_SO_TIMEOUT = 15*1000;
    2938
    3039    private HashMap<String, List<String>> proxies = null;  // port# + "" or "default" -> hostname list
     
    5059    protected void clientConnectionRun(Socket s) {
    5160        try {
     61            try {
     62                s.setSoTimeout(INITIAL_SO_TIMEOUT);
     63            } catch (SocketException ioe) {}
    5264            SOCKSServer serv = SOCKSServerFactory.createSOCKSServer(_context, s, getTunnel().getClientOptions());
    5365            Socket clientSock = serv.getClientSocket();
     66            try {
     67                s.setSoTimeout(0);
     68            } catch (SocketException ioe) {}
    5469            I2PSocket destSock = serv.getDestinationI2PSocket(this);
    5570            Thread t = new I2PTunnelRunner(clientSock, destSock, sockLock, null, null, mySockets,
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS4aServer.java

    r2a279582 r6cd5f1d8  
    7272            manageRequest(in, out);
    7373        } catch (IOException e) {
    74             throw new SOCKSException("Connection error (" + e.getMessage() + ")");
     74            throw new SOCKSException("Connection error", e);
    7575        }
    7676
     
    151151            sendRequestReply(Reply.SUCCEEDED, InetAddress.getByName("127.0.0.1"), 1, out);
    152152        } catch (IOException e) {
    153             throw new SOCKSException("Connection error (" + e.getMessage() + ")");
     153            throw new SOCKSException("Connection error", e);
    154154        }
    155155    }
     
    202202            out = new DataOutputStream(clientSock.getOutputStream());
    203203        } catch (IOException e) {
    204             throw new SOCKSException("Connection error (" + e.getMessage() + ")");
     204            throw new SOCKSException("Connection error", e);
    205205        }
    206206
     
    287287                sendRequestReply(Reply.CONNECTION_REFUSED, InetAddress.getByName("127.0.0.1"), 0, out);
    288288            } catch (IOException ioe) {}
    289             throw new SOCKSException("Error in destination format");
     289            throw new SOCKSException("Error in destination format", e);
    290290        } catch (IOException e) {
    291291            try {
    292292                sendRequestReply(Reply.CONNECTION_REFUSED, InetAddress.getByName("127.0.0.1"), 0, out);
    293293            } catch (IOException ioe) {}
    294             throw new SOCKSException("Error connecting ("
    295                                      + e.getMessage() + ")");
     294            throw new SOCKSException("Error connecting", e);
    296295        } catch (I2PException e) {
    297296            try {
    298297                sendRequestReply(Reply.CONNECTION_REFUSED, InetAddress.getByName("127.0.0.1"), 0, out);
    299298            } catch (IOException ioe) {}
    300             throw new SOCKSException("Error connecting ("
    301                                      + e.getMessage() + ")");
     299            throw new SOCKSException("Error connecting", e);
    302300        }
    303301
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS5Server.java

    r2a279582 r6cd5f1d8  
    8888                handleUDP(in, out);
    8989        } catch (IOException e) {
    90             throw new SOCKSException("Connection error: " + e);
     90            throw new SOCKSException("Connection error", e);
    9191        }
    9292
     
    268268            sendRequestReply(Reply.SUCCEEDED, AddressType.IPV4, InetAddress.getByName("127.0.0.1"), null, 1, out);
    269269        } catch (IOException e) {
    270             throw new SOCKSException("Connection error: " + e);
     270            throw new SOCKSException("Connection error", e);
    271271        }
    272272    }
     
    361361            out = new DataOutputStream(clientSock.getOutputStream());
    362362        } catch (IOException e) {
    363             throw new SOCKSException("Connection error: " + e);
     363            throw new SOCKSException("Connection error", e);
    364364        }
    365365
     
    458458                sendRequestReply(Reply.HOST_UNREACHABLE, AddressType.DOMAINNAME, null, "0.0.0.0", 0, out);
    459459            } catch (IOException ioe) {}
    460             throw new SOCKSException("Error connecting: " + e);
     460            throw new SOCKSException("Connection error", e);
    461461        } catch (I2PException e) {
    462462            if (_log.shouldLog(Log.WARN))
     
    465465                sendRequestReply(Reply.HOST_UNREACHABLE, AddressType.DOMAINNAME, null, "0.0.0.0", 0, out);
    466466            } catch (IOException ioe) {}
    467             throw new SOCKSException("Error connecting: " + e);
     467            throw new SOCKSException("Connection error", e);
    468468        }
    469469
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKSServerFactory.java

    r2a279582 r6cd5f1d8  
    7474        } catch (IOException e) {
    7575            //_log.debug("error reading SOCKS protocol version");
    76             throw new SOCKSException("Connection error (" + e.getMessage() + ")");
     76            throw new SOCKSException("Connection error", e);
    7777        }
    7878
Note: See TracChangeset for help on using the changeset viewer.