Changeset 7e1e3c3


Ignore:
Timestamp:
Jun 4, 2009 3:14:41 PM (11 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
6c349d0
Parents:
ce23d76
Message:
  • I2PTunnel:
    • Fix bug where delayed-open and close-on-idle tunnels would use a different tunnel pool instead of building their own
Location:
apps/i2ptunnel/java/src/net/i2p/i2ptunnel
Files:
4 edited

Legend:

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

    rce23d76 r7e1e3c3  
    4545    protected I2PSocketManager sockMgr; // should be final and use a factory. LINT
    4646    protected List mySockets = new ArrayList();
     47    protected boolean _ownDest;
    4748
    4849    protected Destination dest = null;
     
    115116        this.handlerName = handlerName + _clientId;
    116117        this.privKeyFile = pkf;
     118        _ownDest = ownDest; // == ! shared client
    117119
    118120
     
    130132        if (openNow) {
    131133            while (sockMgr == null) {
    132                 synchronized (sockLock) {
    133                     if (ownDest) {
    134                         sockMgr = buildSocketManager();
    135                     } else {
    136                         sockMgr = getSocketManager();
    137                     }
    138                 }
     134                verifySocketManager();
    139135                if (sockMgr == null) {
    140136                    _log.log(Log.CRIT, "Unable to create socket manager (our own? " + ownDest + ")");
     
    210206    }
    211207
     208    /**
     209     * Sets the this.sockMgr field if it is null, or if we want a new one
     210     *
     211     * We need a socket manager before getDefaultOptions() and most other things
     212     */
     213    protected void verifySocketManager() {
     214        synchronized(sockLock) {
     215            boolean newManager = false;
     216            if (this.sockMgr == null) {
     217                newManager = true;
     218            } else {
     219                I2PSession sess = sockMgr.getSession();
     220                if (sess == null) {
     221                    newManager = true;
     222                } else if (sess.isClosed() &&
     223                           Boolean.valueOf(getTunnel().getClientOptions().getProperty("i2cp.closeOnIdle")).booleanValue() &&
     224                           Boolean.valueOf(getTunnel().getClientOptions().getProperty("i2cp.newDestOnResume")).booleanValue()) {
     225                    // build a new socket manager and a new dest if the session is closed.
     226                    getTunnel().removeSession(sess);
     227                    if (_log.shouldLog(Log.WARN))
     228                        _log.warn(getTunnel().getClientOptions().getProperty("inbound.nickname") + ": Built a new destination on resume");
     229                    newManager = true;
     230                }  // else the old socket manager will reconnect the old session if necessary
     231            }
     232            if (newManager) {
     233                if (_ownDest)
     234                    this.sockMgr = buildSocketManager();
     235                else
     236                    this.sockMgr = getSocketManager();
     237            }
     238        }
     239    }
     240
     241    /** this is ONLY for shared clients */
    212242    private static I2PSocketManager socketManager;
    213243
     244    /** this is ONLY for shared clients */
    214245    protected synchronized I2PSocketManager getSocketManager() {
    215246        return getSocketManager(getTunnel(), this.privKeyFile);
    216247    }
     248    /** this is ONLY for shared clients */
    217249    protected static synchronized I2PSocketManager getSocketManager(I2PTunnel tunnel) {
    218250        return getSocketManager(tunnel, null);
    219251    }
     252    /** this is ONLY for shared clients */
    220253    protected static synchronized I2PSocketManager getSocketManager(I2PTunnel tunnel, String pkf) {
    221254        if (socketManager != null) {
    222255            I2PSession s = socketManager.getSession();
    223256            if ( (s == null) || (s.isClosed()) ) {
    224                 _log.info("Building a new socket manager since the old one closed [s=" + s + "]");
     257                if (_log.shouldLog(Log.INFO))
     258                    _log.info(tunnel.getClientOptions().getProperty("inbound.nickname") + ": Building a new socket manager since the old one closed [s=" + s + "]");
    225259                if (s != null)
    226260                    tunnel.removeSession(s);
    227261                socketManager = buildSocketManager(tunnel, pkf);
    228262            } else {
    229                 _log.info("Not building a new socket manager since the old one is open [s=" + s + "]");
     263                if (_log.shouldLog(Log.INFO))
     264                    _log.info(tunnel.getClientOptions().getProperty("inbound.nickname") + ": Not building a new socket manager since the old one is open [s=" + s + "]");
    230265            }
    231266        } else {
    232             _log.info("Building a new socket manager since there is no other one");
     267            if (_log.shouldLog(Log.INFO))
     268                _log.info(tunnel.getClientOptions().getProperty("inbound.nickname") + ": Building a new socket manager since there is no other one");
    233269            socketManager = buildSocketManager(tunnel, pkf);
    234270        }
     
    279315        }
    280316        sockManager.setName("Client");
     317        if (_log.shouldLog(Log.INFO))
     318            _log.info(tunnel.getClientOptions().getProperty("inbound.nickname") + ": Built a new socket manager [s=" + sockManager.getSession() + "]");
    281319        tunnel.addSession(sockManager.getSession());
    282320        return sockManager;
     
    344382     */
    345383    public I2PSocket createI2PSocket(Destination dest) throws I2PException, ConnectException, NoRouteToHostException, InterruptedIOException {
    346         if (sockMgr == null) {
    347             // we need this before getDefaultOptions()
    348             synchronized(sockLock) {
    349                 sockMgr = getSocketManager();
    350             }
    351         }
     384        verifySocketManager();
    352385        return createI2PSocket(dest, getDefaultOptions());
    353386    }
     
    370403        I2PSocket i2ps;
    371404
    372         if (sockMgr == null) {
    373             // delayed open - call get instead of build because the locking is up there
    374             synchronized(sockLock) {
    375                 sockMgr = getSocketManager();
    376             }
    377         } else if (Boolean.valueOf(getTunnel().getClientOptions().getProperty("i2cp.closeOnIdle")).booleanValue() &&
    378                    Boolean.valueOf(getTunnel().getClientOptions().getProperty("i2cp.newDestOnResume")).booleanValue()) {
    379             synchronized(sockLock) {
    380                 I2PSocketManager oldSockMgr = sockMgr;
    381                 // This will build a new socket manager and a new dest if the session is closed.
    382                 sockMgr = getSocketManager();
    383                 if (oldSockMgr != sockMgr) {
    384                     _log.warn("Built a new destination on resume");
    385                 }
    386             }
    387         }  // else the old socket manager will reconnect the old session if necessary
     405        verifySocketManager();
    388406        i2ps = sockMgr.connect(dest, opt);
    389407        synchronized (sockLock) {
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java

    rce23d76 r7e1e3c3  
    158158            defaultOpts.setProperty("i2p.streaming.inactivityTimeout", ""+DEFAULT_READ_TIMEOUT);
    159159        // delayed start
    160         if (sockMgr == null) {
    161             synchronized(sockLock) {
    162                 sockMgr = getSocketManager();
    163             }
    164         }
     160        verifySocketManager();
    165161        I2PSocketOptions opts = sockMgr.buildOptions(defaultOpts);
    166162        if (!defaultOpts.containsKey(I2PSocketOptions.PROP_CONNECT_TIMEOUT))
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java

    rce23d76 r7e1e3c3  
    212212            defaultOpts.setProperty("i2p.streaming.inactivityTimeout", ""+DEFAULT_READ_TIMEOUT);
    213213        // delayed start
    214         if (sockMgr == null) {
    215             synchronized(sockLock) {
    216                 sockMgr = getSocketManager();
    217             }
    218         }
     214        verifySocketManager();
    219215        I2PSocketOptions opts = sockMgr.buildOptions(defaultOpts);
    220216        if (!defaultOpts.containsKey(I2PSocketOptions.PROP_CONNECT_TIMEOUT))
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/IndexBean.java

    rce23d76 r7e1e3c3  
    779779            else
    780780                config.setProperty("interface", _reachableBy);
    781             config.setProperty("option.inbound.nickname", CLIENT_NICKNAME);
    782             config.setProperty("option.outbound.nickname", CLIENT_NICKNAME);
    783             if (_name != null && !_sharedClient) {
    784                  config.setProperty("option.inbound.nickname", _name);
    785                  config.setProperty("option.outbound.nickname", _name);
    786             }
    787781            config.setProperty("sharedClient", _sharedClient + "");
    788782            for (String p : _booleanClientOpts)
     
    897891        else
    898892            config.setProperty("option.i2p.streaming.connectDelay", "0");
    899         if (_name != null) {
    900             if ( (!isClient(_type)) || (!_sharedClient) ) {
    901                 config.setProperty("option.inbound.nickname", _name);
    902                 config.setProperty("option.outbound.nickname", _name);
    903             } else {
    904                 config.setProperty("option.inbound.nickname", CLIENT_NICKNAME);
    905                 config.setProperty("option.outbound.nickname", CLIENT_NICKNAME);
    906             }
     893        if (isClient(_type) && _sharedClient) {
     894            config.setProperty("option.inbound.nickname", CLIENT_NICKNAME);
     895            config.setProperty("option.outbound.nickname", CLIENT_NICKNAME);
     896        } else if (_name != null) {
     897            config.setProperty("option.inbound.nickname", _name);
     898            config.setProperty("option.outbound.nickname", _name);
    907899        }
    908900        if ("interactive".equals(_profile))
Note: See TracChangeset for help on using the changeset viewer.