Changeset 8efefee


Ignore:
Timestamp:
Dec 14, 2010 2:27:35 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
c44c222
Parents:
59af763
Message:
  • I2CP over SSL, enable with i2cp.SSL=true
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/client/I2PSessionImpl.java

    r59af763 r8efefee  
    132132    private boolean _isReduced;
    133133
     134    /** SSL interface (only) @since 0.8.3 */
     135    protected static final String PROP_ENABLE_SSL = "i2cp.SSL";
     136
    134137    void dateUpdated() {
    135138        _dateReceived = true;
     
    182185        _options = new Properties();
    183186        _options.putAll(filter(options));
    184         if (!_context.isRouterContext()) {
     187        if (_context.isRouterContext()) {
     188            // just for logging
     189            _hostname = "[internal connection]";
     190        } else {
    185191            _hostname = _options.getProperty(I2PClient.PROP_TCP_HOST, "127.0.0.1");
    186192            String portNum = _options.getProperty(I2PClient.PROP_TCP_PORT, LISTEN_PORT + "");
     
    196202
    197203        // auto-add auth if required, not set in the options, and we are in the same JVM
     204        // TODO bypass this on router side for internal connections
    198205        if (_context.isRouterContext() &&
    199206            Boolean.valueOf(_context.getProperty("i2cp.auth")).booleanValue() &&
     
    303310                _reader = new QueuedI2CPMessageReader(_queue, this);
    304311            } else {
    305                 _socket = new Socket(_hostname, _portNum);
     312                if (Boolean.valueOf(_options.getProperty(PROP_ENABLE_SSL)).booleanValue())
     313                    _socket = I2CPSSLSocketFactory.createSocket(_context, _hostname, _portNum);
     314                else
     315                    _socket = new Socket(_hostname, _portNum);
    306316                // _socket.setSoTimeout(1000000); // Uhmmm we could really-really use a real timeout, and handle it.
    307317                _out = _socket.getOutputStream();
  • core/java/src/net/i2p/client/I2PSimpleSession.java

    r59af763 r8efefee  
    2424import net.i2p.internal.QueuedI2CPMessageReader;
    2525import net.i2p.util.I2PAppThread;
    26 import net.i2p.util.InternalSocket;
    2726
    2827/**
     
    8180                _reader = new QueuedI2CPMessageReader(_queue, this);
    8281            } else {
    83                 _socket = new Socket(_hostname, _portNum);
     82                if (Boolean.valueOf(getOptions().getProperty(PROP_ENABLE_SSL)).booleanValue())
     83                    _socket = I2CPSSLSocketFactory.createSocket(_context, _hostname, _portNum);
     84                else
     85                    _socket = new Socket(_hostname, _portNum);
    8486                _out = _socket.getOutputStream();
    8587                synchronized (_out) {
  • router/java/src/net/i2p/router/client/ClientListenerRunner.java

    r59af763 r8efefee  
    2626 */
    2727class ClientListenerRunner implements Runnable {
    28     protected Log _log;
    29     protected RouterContext _context;
    30     protected ClientManager _manager;
     28    protected final Log _log;
     29    protected final RouterContext _context;
     30    protected final ClientManager _manager;
    3131    protected ServerSocket _socket;
    32     protected int _port;
    33     private boolean _bindAllInterfaces;
     32    protected final int _port;
     33    protected final boolean _bindAllInterfaces;
    3434    protected boolean _running;
    3535    protected boolean _listening;
     
    3939    public ClientListenerRunner(RouterContext context, ClientManager manager, int port) {
    4040        _context = context;
    41         _log = _context.logManager().getLog(ClientListenerRunner.class);
     41        _log = _context.logManager().getLog(getClass());
    4242        _manager = manager;
    4343        _port = port;
    44        
    45         String val = context.getProperty(BIND_ALL_INTERFACES);
    46         _bindAllInterfaces = Boolean.valueOf(val).booleanValue();
     44        _bindAllInterfaces = context.getBooleanProperty(BIND_ALL_INTERFACES);
    4745    }
    4846   
    49     public void setPort(int port) { _port = port; }
    50     public int getPort() { return _port; }
    5147    public boolean isListening() { return _running && _listening; }
    5248   
     49    /**
     50     * Get a ServerSocket.
     51     * Split out so it can be overridden for SSL.
     52     * @since 0.8.3
     53     */
     54    protected ServerSocket getServerSocket() throws IOException {
     55        if (_bindAllInterfaces) {
     56            if (_log.shouldLog(Log.INFO))
     57                _log.info("Listening on port " + _port + " on all interfaces");
     58            return new ServerSocket(_port);
     59        } else {
     60            String listenInterface = _context.getProperty(ClientManagerFacadeImpl.PROP_CLIENT_HOST,
     61                                                          ClientManagerFacadeImpl.DEFAULT_HOST);
     62            if (_log.shouldLog(Log.INFO))
     63                _log.info("Listening on port " + _port + " of the specific interface: " + listenInterface);
     64            return new ServerSocket(_port, 0, InetAddress.getByName(listenInterface));
     65        }
     66    }
     67               
    5368    /**
    5469     * Start up the socket listener, listens for connections, and
     
    6378        while (_running) {
    6479            try {
    65                 if (_bindAllInterfaces) {
    66                     if (_log.shouldLog(Log.INFO))
    67                         _log.info("Listening on port " + _port + " on all interfaces");
    68                     _socket = new ServerSocket(_port);
    69                 } else {
    70                     String listenInterface = _context.getProperty(ClientManagerFacadeImpl.PROP_CLIENT_HOST,
    71                                                                   ClientManagerFacadeImpl.DEFAULT_HOST);
    72                     if (_log.shouldLog(Log.INFO))
    73                         _log.info("Listening on port " + _port + " of the specific interface: " + listenInterface);
    74                     _socket = new ServerSocket(_port, 0, InetAddress.getByName(listenInterface));
    75                 }
    76                
     80                _socket = getServerSocket();
    7781               
    7882                if (_log.shouldLog(Log.DEBUG))
     
    132136   
    133137    /** give the i2cp client 5 seconds to show that they're really i2cp clients */
    134     private final static int CONNECT_TIMEOUT = 5*1000;
     138    protected final static int CONNECT_TIMEOUT = 5*1000;
     139    private final static int LOOP_DELAY = 250;
    135140
    136141    /**
     
    142147        try {
    143148            InputStream is = socket.getInputStream();
    144             for (int i = 0; i < 20; i++) {
     149            for (int i = 0; i < CONNECT_TIMEOUT / LOOP_DELAY; i++) {
    145150                if (is.available() > 0)
    146151                    return is.read() == I2PClient.PROTOCOL_BYTE;
    147                 try { Thread.sleep(250); } catch (InterruptedException ie) {}
     152                try { Thread.sleep(LOOP_DELAY); } catch (InterruptedException ie) {}
    148153            }
    149154        } catch (IOException ioe) {}
     
    152157        return false;
    153158    }
     159
    154160    /**
    155161     * Handle the connection by passing it off to a {@link ClientConnectionRunner ClientConnectionRunner}
  • router/java/src/net/i2p/router/client/ClientManager.java

    r59af763 r8efefee  
    5454    /** Disable external interface, allow internal clients only @since 0.8.3 */
    5555    private static final String PROP_DISABLE_EXTERNAL = "i2cp.disableInterface";
     56    /** SSL interface (only) @since 0.8.3 */
     57    private static final String PROP_ENABLE_SSL = "i2cp.SSL";
    5658
    5759    /** ms to wait before rechecking for inbound messages to deliver to clients */
     
    6163        _ctx = context;
    6264        _log = context.logManager().getLog(ClientManager.class);
    63         _ctx.statManager().createRateStat("client.receiveMessageSize",
    64                                               "How large are messages received by the client?",
    65                                               "ClientMessages",
    66                                               new long[] { 60*1000l, 60*60*1000l, 24*60*60*1000l });
     65        //_ctx.statManager().createRateStat("client.receiveMessageSize",
     66        //                                      "How large are messages received by the client?",
     67        //                                      "ClientMessages",
     68        //                                      new long[] { 60*1000l, 60*60*1000l, 24*60*60*1000l });
    6769        _runners = new HashMap();
    6870        _pendingRunners = new HashSet();
     
    7375    private void startListeners(int port) {
    7476        if (!_ctx.getBooleanProperty(PROP_DISABLE_EXTERNAL)) {
    75             _listener = new ClientListenerRunner(_ctx, this, port);
     77            // there's no option to start both an SSL and non-SSL listener
     78            if (_ctx.getBooleanProperty(PROP_ENABLE_SSL))
     79                _listener = new SSLClientListenerRunner(_ctx, this, port);
     80            else
     81                _listener = new ClientListenerRunner(_ctx, this, port);
    7682            Thread t = new I2PThread(_listener, "ClientListener:" + port, true);
    7783            t.start();
     
    495501
    496502            if (runner != null) {
    497                 _ctx.statManager().addRateData("client.receiveMessageSize",
    498                                                    _msg.getPayload().getSize(), 0);
     503                //_ctx.statManager().addRateData("client.receiveMessageSize",
     504                //                                   _msg.getPayload().getSize(), 0);
    499505                runner.receiveMessage(_msg.getDestination(), null, _msg.getPayload());
    500506            } else {
Note: See TracChangeset for help on using the changeset viewer.