Changeset fa85c0c for router


Ignore:
Timestamp:
Mar 10, 2018 12:30:17 PM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
fe808a8
Parents:
4bcb1d2
Message:

NetDB: Wake up FloodfillMonitor? when ff setting changes,
so it will take effect immediately, and log in event log.
Don't queue multiple FloodJobs? after changes

Location:
router/java/src/net/i2p/router/networkdb/kademlia
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillMonitorJob.java

    r4bcb1d2 rfa85c0c  
    3232    private final FloodfillNetworkDatabaseFacade _facade;
    3333    private long _lastChanged;
     34    private boolean _deferredFlood;
    3435   
    3536    private static final int REQUEUE_DELAY = 60*60*1000;
     
    4950    public String getName() { return "Monitor the floodfill pool"; }
    5051
    51     public void runJob() {
     52    public synchronized void runJob() {
    5253        boolean wasFF = _facade.floodfillEnabled();
    5354        boolean ff = shouldBeFloodfill();
    54         _facade.setFloodfillEnabled(ff);
     55        _facade.setFloodfillEnabledFromMonitor(ff);
    5556        if (ff != wasFF) {
    5657            if (ff) {
     
    6162            getContext().router().rebuildRouterInfo(true);
    6263            Job routerInfoFlood = new FloodfillRouterInfoFloodJob(getContext(), _facade);
    63             if(getContext().router().getUptime() < 5*60*1000) {
    64                 // Needed to prevent race if router.floodfillParticipant=true (not auto)
    65                 routerInfoFlood.getTiming().setStartAfter(getContext().clock().now() + 5*60*1000);
    66                 getContext().jobQueue().addJob(routerInfoFlood);
    67                 if(_log.shouldLog(Log.DEBUG)) {
    68                     _log.logAlways(Log.DEBUG, "Deferring our FloodfillRouterInfoFloodJob run because of low uptime.");
     64            if (getContext().router().getUptime() < 5*60*1000) {
     65                if (!_deferredFlood) {
     66                    // Needed to prevent race if router.floodfillParticipant=true (not auto)
     67                    // Don't queue multiples
     68                    _deferredFlood = true;
     69                    routerInfoFlood.getTiming().setStartAfter(getContext().clock().now() + 5*60*1000);
     70                    getContext().jobQueue().addJob(routerInfoFlood);
     71                    if (_log.shouldLog(Log.DEBUG))
     72                        _log.logAlways(Log.DEBUG, "Deferring our FloodfillRouterInfoFloodJob run because of low uptime.");
    6973                }
    7074            } else {
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java

    r4bcb1d2 rfa85c0c  
    3434    private FloodThrottler _floodThrottler;
    3535    private LookupThrottler _lookupThrottler;
     36    private final Job _ffMonitor;
    3637
    3738    /**
     
    6970        // for ISJ
    7071        _context.statManager().createRateStat("netDb.RILookupDirect", "Was an iterative RI lookup sent directly?", "NetworkDatabase", new long[] { 60*60*1000 });
     72        _ffMonitor = new FloodfillMonitorJob(_context, this);
    7173    }
    7274
     
    7476    public synchronized void startup() {
    7577        super.startup();
    76         _context.jobQueue().addJob(new FloodfillMonitorJob(_context, this));
     78        _context.jobQueue().addJob(_ffMonitor);
    7779        _lookupThrottler = new LookupThrottler();
    7880
     
    115117            }
    116118        }
     119        _context.jobQueue().removeJob(_ffMonitor);
    117120        super.shutdown();
    118121    }
     
    279282    protected PeerSelector createPeerSelector() { return new FloodfillPeerSelector(_context); }
    280283   
     284    /**
     285     *  Public, called from console. This wakes up the floodfill monitor,
     286     *  which will rebuild the RI and log in the event log,
     287     *  and call setFloodfillEnabledFromMonitor which really sets it.
     288     */
    281289    public synchronized void setFloodfillEnabled(boolean yes) {
     290        if (yes != _floodfillEnabled) {
     291            _context.jobQueue().removeJob(_ffMonitor);
     292            _ffMonitor.getTiming().setStartAfter(_context.clock().now() + 1000);
     293            _context.jobQueue().addJob(_ffMonitor);
     294        }
     295    }
     296   
     297    /**
     298     *  Package private, called from FloodfillMonitorJob. This does not wake up the floodfill monitor.
     299     *  @since 0.9.34
     300     */
     301    synchronized void setFloodfillEnabledFromMonitor(boolean yes) {
    282302        _floodfillEnabled = yes;
    283303        if (yes && _floodThrottler == null) {
Note: See TracChangeset for help on using the changeset viewer.