Changeset 56d8b72


Ignore:
Timestamp:
Jul 19, 2011 8:54:22 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
164f6603, 3834403
Parents:
c78719b
Message:
  • Tunnel TestJob?:
    • Don't continue testing after the pool is dead
    • Tweak test intervals
  • TunnelPool?: Make more methods package private
Location:
router/java/src/net/i2p/router/tunnel/pool
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/tunnel/pool/TestJob.java

    rc78719b r56d8b72  
    2424import net.i2p.util.Log;
    2525
     26/**
     27 *  Repeatedly test a single tunnel for its entire lifetime,
     28 *  or until the pool is shut down or removed from the client manager.
     29 */
    2630class TestJob extends JobImpl {
    2731    private final Log _log;
     
    3640   
    3741    /** base to randomize the test delay on */
    38     private static final int TEST_DELAY = 30*1000;
     42    private static final int TEST_DELAY = 40*1000;
    3943   
    4044    public TestJob(RouterContext ctx, PooledTunnelCreatorConfig cfg, TunnelPool pool) {
     
    5559
    5660    public void runJob() {
    57         if (_pool == null)
     61        if (_pool == null || !_pool.isAlive())
    5862            return;
    5963        long lag = getContext().jobQueue().getMaxLag();
     
    156160   
    157161    public void testSuccessful(int ms) {
     162        if (_pool == null || !_pool.isAlive())
     163            return;
    158164        getContext().statManager().addRateData("tunnel.testSuccessLength", _cfg.getLength(), 0);
    159165        getContext().statManager().addRateData("tunnel.testSuccessTime", ms, 0);
     
    183189   
    184190    private void testFailed(long timeToFail) {
     191        if (_pool == null || !_pool.isAlive())
     192            return;
    185193        if (_found) {
    186194            // ok, not really a /success/, but we did find it, even though slowly
     
    209217   
    210218    /** randomized time we should wait before testing */
    211     private int getDelay() { return TEST_DELAY + getContext().random().nextInt(TEST_DELAY); }
     219    private int getDelay() { return TEST_DELAY + getContext().random().nextInt(TEST_DELAY / 3); }
    212220
    213221    /** how long we allow tests to run for before failing them */
     
    235243    private void scheduleRetest() { scheduleRetest(false); }
    236244    private void scheduleRetest(boolean asap) {
     245        if (_pool == null || !_pool.isAlive())
     246            return;
    237247        if (asap) {
    238             requeue(getContext().random().nextInt(TEST_DELAY));
     248            if (_cfg.getExpiration() > getContext().clock().now() + (60 * 1000))
     249                requeue((TEST_DELAY / 4) + getContext().random().nextInt(TEST_DELAY / 4));
    239250        } else {
    240251            int delay = getDelay();
  • router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java

    rc78719b r56d8b72  
    2424/**
    2525 *  A group of tunnels for the router or a particular client, in a single direction.
     26 *  Public only for TunnelRenderer in router console.
    2627 */
    2728public class TunnelPool {
     
    4445    private static final int TUNNEL_LIFETIME = 10*60*1000;
    4546   
    46     public TunnelPool(RouterContext ctx, TunnelPoolManager mgr, TunnelPoolSettings settings, TunnelPeerSelector sel) {
     47    TunnelPool(RouterContext ctx, TunnelPoolManager mgr, TunnelPoolSettings settings, TunnelPeerSelector sel) {
    4748        _context = ctx;
    4849        _log = ctx.logManager().getLog(TunnelPool.class);
     
    6061    }
    6162   
    62     public void startup() {
     63    /**
     64     *  Warning, this may be called more than once
     65     *  (without an intervening shutdown()) if the
     66     *  tunnel is stopped and then restarted by the client manager with the same
     67     *  Destination (i.e. for servers or clients w/ persistent key)
     68     */
     69    void startup() {
    6370        synchronized (_inProgress) {
    6471            _inProgress.clear();
    6572        }
     73        if (_log.shouldLog(Log.WARN))
     74            _log.warn(toString() + ": Startup() called, was already alive? " + _alive, new Exception());
    6675        _alive = true;
    6776        _started = System.currentTimeMillis();
     
    8594    }
    8695   
    87     public void shutdown() {
     96    void shutdown() {
     97        if (_log.shouldLog(Log.WARN))
     98            _log.warn(toString() + ": Shutdown called", new Exception());
    8899        _alive = false;
    89100        _lastSelectionPeriod = 0;
     
    133144     *
    134145     */
    135     public TunnelInfo selectTunnel() { return selectTunnel(true); }
     146    TunnelInfo selectTunnel() { return selectTunnel(true); }
     147
    136148    private TunnelInfo selectTunnel(boolean allowRecurseOnFail) {
    137149        boolean avoidZeroHop = ((getSettings().getLength() + getSettings().getLengthVariance()) > 0);
     
    240252     * Used to prevent a zillion of them
    241253     */
    242     public boolean needFallback() {
     254    boolean needFallback() {
    243255        int needed = _settings.getBackupQuantity() + _settings.getQuantity();
    244256        int fallbacks = 0;
     
    260272   
    261273    public TunnelPoolSettings getSettings() { return _settings; }
    262     public void setSettings(TunnelPoolSettings settings) {
     274
     275    void setSettings(TunnelPoolSettings settings) {
    263276        _settings = settings;
    264277        if (_settings != null) {
     
    268281        }
    269282    }
    270     public TunnelPeerSelector getSelector() { return _peerSelector; }
    271     public boolean isAlive() { return _alive; }
     283
     284    /**
     285     *  Is this pool running AND either exploratory, or tracked by the client manager?
     286     *  A pool will be alive but not tracked after the client manager removes it
     287     *  but before all the tunnels have expired.
     288     */
     289    public boolean isAlive() {
     290        return _alive &&
     291               (_settings.isExploratory() ||
     292                (_settings.getDestination() != null &&
     293                 _context.clientManager().isLocal(_settings.getDestination())));
     294    }
     295
    272296    /** duplicate of getTunnelCount(), let's pick one */
    273297    public int size() {
     
    337361        }
    338362   
    339         boolean connected = true;
    340         if ( (_settings.getDestination() != null) && (!_context.clientManager().isLocal(_settings.getDestination())) )
    341             connected = false;
    342         if ( (getTunnelCount() <= 0) && (!connected) ) {
     363        if (getTunnelCount() <= 0 && !isAlive()) {
     364            // this calls both our shutdown() and the other one (inbound/outbound)
    343365            _manager.removeTunnels(_settings.getDestination());
    344             return;
    345366        }
    346367    }
    347368
    348369    /** This may be called multiple times from TestJob */
    349     public void tunnelFailed(PooledTunnelCreatorConfig cfg) {
     370    void tunnelFailed(PooledTunnelCreatorConfig cfg) {
    350371        if (_log.shouldLog(Log.WARN))
    351372            _log.warn(toString() + ": Tunnel failed: " + cfg);
     
    575596     *
    576597     */
    577     public int countHowManyToBuild() {
    578         if (_settings.getDestination() != null) {
    579             if (!_context.clientManager().isLocal(_settings.getDestination()))
     598    int countHowManyToBuild() {
     599        if (!isAlive()) {
    580600                return 0;
    581601        }
  • router/java/src/net/i2p/router/tunnel/pool/TunnelPoolManager.java

    rc78719b r56d8b72  
    277277     */
    278278    public void buildTunnels(Destination client, ClientTunnelSettings settings) {
     279        Hash dest = client.calculateHash();
    279280        if (_log.shouldLog(Log.DEBUG))
    280             _log.debug("Building tunnels for the client " + client.calculateHash().toBase64() + ": " + settings);
    281         Hash dest = client.calculateHash();
     281            _log.debug("Building tunnels for the client " + dest + ": " + settings);
    282282        settings.getInboundSettings().setDestination(dest);
    283283        settings.getOutboundSettings().setDestination(dest);
     
    312312   
    313313    private static class DelayedStartup implements SimpleTimer.TimedEvent {
    314         private TunnelPool pool;
     314        private final TunnelPool pool;
    315315
    316316        public DelayedStartup(TunnelPool p) {
     
    323323    }
    324324
    325     /** synch with buildTunnels() above */
     325    /**
     326     *  This will be called twice, once by the inbound and once by the outbound pool.
     327     *  Synched with buildTunnels() above.
     328     */
    326329    public synchronized void removeTunnels(Hash destination) {
    327330        if (destination == null) return;
     331        if (_log.shouldLog(Log.DEBUG))
     332            _log.debug("Removing tunnels for the client " + destination);
    328333        if (_context.clientManager().isLocal(destination)) {
    329334            if (_log.shouldLog(Log.CRIT))
Note: See TracChangeset for help on using the changeset viewer.