Changeset f7170aa


Ignore:
Timestamp:
Jan 23, 2009 4:02:53 PM (12 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
e5d76a5
Parents:
c02711c
Message:

Move getDestinationI2PSocket from SocksServer? to Socks5Server
so we can do better error handling

Location:
apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks
Files:
2 edited

Legend:

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

    rc02711c rf7170aa  
    1313import java.net.InetAddress;
    1414import java.net.Socket;
    15 
     15import java.net.SocketException;
     16
     17import net.i2p.I2PException;
     18import net.i2p.client.streaming.I2PSocket;
     19import net.i2p.data.DataFormatException;
     20import net.i2p.i2ptunnel.I2PTunnel;
    1621import net.i2p.util.HexDump;
    1722import net.i2p.util.Log;
     
    127132        default:
    128133            _log.debug("unknown command in request (" + Integer.toHexString(command) + ")");
     134            sendRequestReply(Reply.COMMAND_NOT_SUPPORTED, AddressType.DOMAINNAME, null, "0.0.0.0", 0, out);
    129135            throw new SOCKSException("Invalid command in request");
    130136        }
     
    167173        default:
    168174            _log.debug("unknown address type in request (" + Integer.toHexString(command) + ")");
     175            sendRequestReply(Reply.ADDRESS_TYPE_NOT_SUPPORTED, AddressType.DOMAINNAME, null, "0.0.0.0", 0, out);
    169176            throw new SOCKSException("Invalid addresses type in request");
    170177        }
     
    173180        if (connPort == 0) {
    174181            _log.debug("trying to connect to TCP port 0?  Dropping!");
     182            sendRequestReply(Reply.CONNECTION_NOT_ALLOWED_BY_RULESET, AddressType.DOMAINNAME, null, "0.0.0.0", 0, out);
    175183            throw new SOCKSException("Invalid port number in request");
    176184        }
     
    247255
    248256        out.write(reply);
     257    }
     258
     259    /**
     260     * Get an I2PSocket that can be used to send/receive 8-bit clean data
     261     * to/from the destination of the SOCKS connection.
     262     *
     263     * @return an I2PSocket connected with the destination
     264     */
     265    public I2PSocket getDestinationI2PSocket(I2PSOCKSTunnel t) throws SOCKSException {
     266        setupServer();
     267
     268        if (connHostName == null) {
     269            _log.error("BUG: destination host name has not been initialized!");
     270            throw new SOCKSException("BUG! See the logs!");
     271        }
     272        if (connPort == 0) {
     273            _log.error("BUG: destination port has not been initialized!");
     274            throw new SOCKSException("BUG! See the logs!");
     275        }
     276
     277        // FIXME: here we should read our config file, select an
     278        // outproxy, and instantiate the proper socket class that
     279        // handles the outproxy itself (SOCKS4a, SOCKS5, HTTP CONNECT...).
     280        I2PSocket destSock;
     281
     282        try {
     283            if (connHostName.toLowerCase().endsWith(".i2p")) {
     284                _log.debug("connecting to " + connHostName + "...");
     285                // Let's not due a new Dest for every request, huh?
     286                //I2PSocketManager sm = I2PSocketManagerFactory.createManager();
     287                //destSock = sm.connect(I2PTunnel.destFromName(connHostName), null);
     288                // TODO get the streaming lib options in there
     289                destSock = t.createI2PSocket(I2PTunnel.destFromName(connHostName));
     290                confirmConnection();
     291                _log.debug("connection confirmed - exchanging data...");
     292            } else {
     293                // if (connPort == 80) ...
     294                _log.error("We don't support outproxies (yet)");
     295                throw new SOCKSException("Ouproxies not supported (yet)");
     296            }
     297        } catch (DataFormatException e) {
     298            throw new SOCKSException("Error in destination format");
     299        } catch (SocketException e) {
     300            throw new SOCKSException("Error connecting ("
     301                                     + e.getMessage() + ")");
     302        } catch (IOException e) {
     303            throw new SOCKSException("Error connecting ("
     304                                     + e.getMessage() + ")");
     305        } catch (I2PException e) {
     306            throw new SOCKSException("Error connecting ("
     307                                     + e.getMessage() + ")");
     308        }
     309
     310        return destSock;
    249311    }
    250312
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKSServer.java

    rc02711c rf7170aa  
    77package net.i2p.i2ptunnel.socks;
    88
    9 import java.io.IOException;
    109import java.net.Socket;
    11 import java.net.SocketException;
    1210
    13 import net.i2p.I2PException;
    1411import net.i2p.client.streaming.I2PSocket;
    15 import net.i2p.client.streaming.I2PSocketManager;
    16 import net.i2p.client.streaming.I2PSocketManagerFactory;
    17 import net.i2p.data.DataFormatException;
    1812import net.i2p.i2ptunnel.I2PTunnel;
    1913import net.i2p.util.Log;
     
    3024    protected String connHostName = null;
    3125    protected int connPort = 0;
    32 
    33     I2PSocket destSocket = null;
    34 
    35     Object FIXME = new Object();
    3626
    3727    /**
     
    6050     * @return an I2PSocket connected with the destination
    6151     */
    62     public I2PSocket getDestinationI2PSocket(I2PSOCKSTunnel t) throws SOCKSException {
    63         setupServer();
     52    public abstract I2PSocket getDestinationI2PSocket(I2PSOCKSTunnel t) throws SOCKSException;
    6453
    65         if (connHostName == null) {
    66             _log.error("BUG: destination host name has not been initialized!");
    67             throw new SOCKSException("BUG! See the logs!");
    68         }
    69         if (connPort == 0) {
    70             _log.error("BUG: destination port has not been initialized!");
    71             throw new SOCKSException("BUG! See the logs!");
    72         }
    73 
    74         // FIXME: here we should read our config file, select an
    75         // outproxy, and instantiate the proper socket class that
    76         // handles the outproxy itself (SOCKS4a, SOCKS5, HTTP CONNECT...).
    77         I2PSocket destSock;
    78 
    79         try {
    80             if (connHostName.toLowerCase().endsWith(".i2p")) {
    81                 _log.debug("connecting to " + connHostName + "...");
    82                 // Let's not due a new Dest for every request, huh?
    83                 //I2PSocketManager sm = I2PSocketManagerFactory.createManager();
    84                 //destSock = sm.connect(I2PTunnel.destFromName(connHostName), null);
    85                 // TODO get the streaming lib options in there
    86                 destSock = t.createI2PSocket(I2PTunnel.destFromName(connHostName));
    87                 confirmConnection();
    88                 _log.debug("connection confirmed - exchanging data...");
    89             } else {
    90                 _log.error("We don't support outproxies (yet)");
    91                 throw new SOCKSException("Ouproxies not supported (yet)");
    92             }
    93         } catch (DataFormatException e) {
    94             throw new SOCKSException("Error in destination format");
    95         } catch (SocketException e) {
    96             throw new SOCKSException("Error connecting ("
    97                                      + e.getMessage() + ")");
    98         } catch (IOException e) {
    99             throw new SOCKSException("Error connecting ("
    100                                      + e.getMessage() + ")");
    101         } catch (I2PException e) {
    102             throw new SOCKSException("Error connecting ("
    103                                      + e.getMessage() + ")");
    104         }
    105 
    106         return destSock;
    107     }
    10854}
Note: See TracChangeset for help on using the changeset viewer.