Search in sources :

Example 1 with I2PTunnel

use of net.i2p.i2ptunnel.I2PTunnel in project i2p.i2p by i2p.

the class SOCKS5Server method handleUDP.

/**
 * We got a UDP associate command.
 * Loop here looking for more, never return normally,
 * or else I2PSocksTunnel will create a streaming lib connection.
 *
 * Do UDP Socks clients actually send more than one Associate request?
 * RFC 1928 isn't clear... maybe not.
 */
private void handleUDP(DataInputStream in, DataOutputStream out) throws SOCKSException {
    List<Integer> ports = new ArrayList<Integer>(1);
    synchronized (_startLock) {
        if (_tunnel == null) {
            // tunnel options?
            _tunnel = new SOCKSUDPTunnel(new I2PTunnel());
            _tunnel.startRunning();
        }
    }
    while (true) {
        // Set it up. connHostName and connPort are the client's info.
        InetAddress ia = null;
        try {
            ia = InetAddress.getByAddress(connHostName, dummyIP);
        }// won't happen, no resolving done here
         catch (UnknownHostException uhe) {
        }
        int myPort = _tunnel.add(ia, connPort);
        ports.add(Integer.valueOf(myPort));
        try {
            sendRequestReply(Reply.SUCCEEDED, AddressType.IPV4, InetAddress.getByName("127.0.0.1"), null, myPort, out);
        } catch (IOException ioe) {
            break;
        }
        // wait for more ???
        try {
            int command = manageRequest(in, out);
            // don't do this...
            if (command != Command.UDP_ASSOCIATE)
                break;
        } catch (IOException ioe) {
            break;
        }
    }
    for (Integer i : ports) _tunnel.remove(i);
    // 
    throw new SOCKSException("End of UDP Processing");
}
Also used : I2PTunnel(net.i2p.i2ptunnel.I2PTunnel) UnknownHostException(java.net.UnknownHostException) SOCKSException(net.i2p.socks.SOCKSException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) InetAddress(java.net.InetAddress)

Aggregations

IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 I2PTunnel (net.i2p.i2ptunnel.I2PTunnel)1 SOCKSException (net.i2p.socks.SOCKSException)1