Changeset 7db602d


Ignore:
Timestamp:
Mar 11, 2019 8:00:04 PM (17 months ago)
Author:
zab2 <zab2@…>
Branches:
master
Children:
9d17066
Parents:
7e6fd01
Message:

Make I2pTunnel wait for router to reach RUNNING state (ticket #2377)

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • history.txt

    r7e6fd01 r7db602d  
     12019-03-11 zab
     2 * Startup: make negative client app delay value mean waiting
     3   for router to be RUNNING (ticket #2377)
     4 * I2PTunnel: make I2PTunnel default to negative startup delay value
     5   (ticket #2377)
     6
    172019-03-11 zzz
    28 * Console: New home page icons
  • installer/resources/clients.config

    r7e6fd01 r7db602d  
    4343clientApp.2.name=Application tunnels
    4444clientApp.2.args=i2ptunnel.config
    45 clientApp.2.delay=35
     45clientApp.2.delay=-1
    4646clientApp.2.startOnLoad=true
    4747
  • router/java/src/net/i2p/router/Router.java

    r7e6fd01 r7db602d  
    824824
    825825    /**
     826     * @return true if router is RUNNING, i.e NetDB and Expl. tunnels are ready.
     827     * @since 0.9.39
     828     */
     829    public boolean isRunning() {
     830        synchronized(_stateLock) {
     831            return _state == State.RUNNING;
     832        }
     833    }
     834
     835    /**
    826836     *  Only for Restarter, after soft restart is complete.
    827837     *  Not for external use.
  • router/java/src/net/i2p/router/startup/ClientAppConfig.java

    r7e6fd01 r7db602d  
    6868    private final static long DEFAULT_STARTUP_DELAY = 2*60*1000;
    6969    /** speed up i2ptunnel without rewriting clients.config */
    70     private final static long I2PTUNNEL_STARTUP_DELAY = 35*1000;
     70    private final static long I2PTUNNEL_STARTUP_DELAY = -1000;
    7171   
    7272    private static final String PROP_CLIENT_CONFIG_FILENAME = "router.clientConfigFile";
     
    186186                onStartup = "true".equals(onBoot) || "yes".equals(onBoot);
    187187
    188             // speed up the start of i2ptunnel for everybody without rewriting clients.config
    189             long delay = onStartup ? 0 :
    190                                    (className.equals("net.i2p.i2ptunnel.TunnelControllerGroup") ?
    191                                     I2PTUNNEL_STARTUP_DELAY : DEFAULT_STARTUP_DELAY);
    192             if (delayStr != null && !onStartup)
    193                 try { delay = 1000*Integer.parseInt(delayStr); } catch (NumberFormatException nfe) {}
    194 
     188            long delay;
     189            if (onStartup) {
     190                delay = 0;
     191            } else if (className.equals("net.i2p.i2ptunnel.TunnelControllerGroup")) {
     192                // speed up the start of i2ptunnel for everybody without rewriting clients.config
     193                delay = I2PTUNNEL_STARTUP_DELAY;
     194            } else {
     195                delay = DEFAULT_STARTUP_DELAY;
     196                if (delayStr != null)
     197                    try { delay = 1000*Integer.parseInt(delayStr); } catch (NumberFormatException nfe) {}
     198            }
    195199            rv.add(new ClientAppConfig(className, clientName, args, delay, dis,
    196200                   classpath, stopargs, uninstallargs));
  • router/java/src/net/i2p/router/startup/LoadClientAppsJob.java

    r7e6fd01 r7db602d  
    5757            }
    5858            String argVal[] = parseArgs(app.args);
    59             if (app.delay <= 0) {
     59            if (app.delay == 0) {
    6060                // run this guy now
    6161                runClient(app.className, app.clientName, argVal, getContext(), _log);
    62             } else {
     62            } else if (app.delay > 0) {
    6363                // wait before firing it up
    6464                DelayedRunClient drc = new DelayedRunClient(getContext().simpleTimer2(), getContext(), app.className,
    6565                                                            app.clientName, argVal);
    6666                drc.schedule(app.delay);
     67            } else {
     68                WaitForRunningClient wfrc = new WaitForRunningClient(getContext().simpleTimer2(), getContext(),
     69                                                                app.className, app.clientName, argVal);
     70                wfrc.schedule(1000);
    6771            }
    6872        }
     
    7377     */
    7478    public static class DelayedRunClient extends SimpleTimer2.TimedEvent {
    75         private final RouterContext _ctx;
     79        protected final RouterContext _ctx;
    7680        private final String _className;
    7781        private final String _clientName;
     
    102106        public void timeReached() {
    103107            runClient(_className, _clientName, _args, _ctx, _log, _threadGroup, _cl);
     108        }
     109    }
     110
     111    private static class WaitForRunningClient extends DelayedRunClient {
     112        WaitForRunningClient(SimpleTimer2 pool, RouterContext enclosingContext, String className, String clientName,
     113                             String args[]) {
     114            super(pool, enclosingContext, className, clientName, args, null, null);
     115        }
     116
     117        public void timeReached() {
     118            if (!_ctx.router().isRunning()) {
     119                 reschedule(1000);
     120                 return;
     121            }
     122            super.timeReached();
    104123        }
    105124    }
Note: See TracChangeset for help on using the changeset viewer.