Changeset 6d41aad


Ignore:
Timestamp:
Dec 12, 2010 10:06:30 PM (10 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
a5354f6
Parents:
9a993c0
Message:
  • I2CP:
    • New option i2cp.disableInterface to turn off external I2CP port (7654) and allow internal clients only
    • Disallow internal connect when shut down
File:
1 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/client/ClientManager.java

    r9a993c0 r6d41aad  
    4444 * @author jrandom
    4545 */
    46 public class ClientManager {
    47     private Log _log;
     46class ClientManager {
     47    private final Log _log;
    4848    private ClientListenerRunner _listener;
    4949    private final HashMap<Destination, ClientConnectionRunner>  _runners;        // Destination --> ClientConnectionRunner
    5050    private final Set<ClientConnectionRunner> _pendingRunners; // ClientConnectionRunner for clients w/out a Dest yet
    51     private RouterContext _ctx;
     51    private final RouterContext _ctx;
     52    private boolean _isStarted;
     53
     54    /** Disable external interface, allow internal clients only @since 0.8.3 */
     55    private static final String PROP_DISABLE_EXTERNAL = "i2cp.disableInterface";
    5256
    5357    /** ms to wait before rechecking for inbound messages to deliver to clients */
     
    6872    /** Todo: Start a 3rd listener for IPV6? */
    6973    private void startListeners(int port) {
    70         _listener = new ClientListenerRunner(_ctx, this, port);
    71         Thread t = new I2PThread(_listener);
    72         t.setName("ClientListener:" + port);
    73         t.setDaemon(true);
    74         t.start();
     74        if (!_ctx.getBooleanProperty(PROP_DISABLE_EXTERNAL)) {
     75            _listener = new ClientListenerRunner(_ctx, this, port);
     76            Thread t = new I2PThread(_listener, "ClientListener:" + port, true);
     77            t.start();
     78        }
     79        _isStarted = true;
    7580    }
    7681   
     
    9499   
    95100    public void shutdown() {
     101        _isStarted = false;
    96102        _log.info("Shutting down the ClientManager");
    97         _listener.stopListening();
     103        if (_listener != null)
     104            _listener.stopListening();
    98105        Set<ClientConnectionRunner> runners = new HashSet();
    99106        synchronized (_runners) {
     
    118125     *  The InternalClientManager interface.
    119126     *  Connects to the router, receiving a message queue to talk to the router with.
    120      *  Might throw I2PSessionException if the router isn't ready, someday.
     127     *  @throws I2PSessionException if the router isn't ready
    121128     *  @since 0.8.3
    122129     */
    123     public I2CPMessageQueue internalConnect() {
     130    public I2CPMessageQueue internalConnect() throws I2PSessionException {
     131        if (!_isStarted)
     132            throw new I2PSessionException("Router client manager is shut down");
    124133        // for now we make these unlimited size
    125134        LinkedBlockingQueue<I2CPMessage> in = new LinkedBlockingQueue();
     
    132141    }
    133142
    134     public boolean isAlive() { return _listener.isListening(); }
     143    public boolean isAlive() {
     144        return _isStarted && (_listener == null || _listener.isListening());
     145    }
    135146
    136147    public void registerConnection(ClientConnectionRunner runner) {
Note: See TracChangeset for help on using the changeset viewer.