NetDB: Fixes for ExpireRoutersJob

- Don't expire if too few routers
  - Don't expire if net is disconnected
  - Don't run in VMCommSystem
This commit is contained in:
zzz
2013-12-19 12:23:29 +00:00
parent ee1ed1bb82
commit 04a596899a
2 changed files with 13 additions and 6 deletions

View File

@ -13,6 +13,7 @@ import java.util.Set;
import net.i2p.data.DatabaseEntry;
import net.i2p.data.Hash;
import net.i2p.data.RouterInfo;
import net.i2p.router.CommSystemFacade;
import net.i2p.router.JobImpl;
import net.i2p.router.RouterContext;
import net.i2p.util.Log;
@ -42,9 +43,11 @@ class ExpireRoutersJob extends JobImpl {
public String getName() { return "Expire Routers Job"; }
public void runJob() {
int removed = expireKeys();
if (_log.shouldLog(Log.INFO))
_log.info("Routers expired: " + removed);
if (getContext().commSystem().getReachabilityStatus() != CommSystemFacade.STATUS_DISCONNECTED) {
int removed = expireKeys();
if (_log.shouldLog(Log.INFO))
_log.info("Routers expired: " + removed);
}
requeue(RERUN_DELAY_MS);
}
@ -59,6 +62,8 @@ class ExpireRoutersJob extends JobImpl {
private int expireKeys() {
Set<Hash> keys = _facade.getAllRouters();
keys.remove(getContext().routerHash());
if (keys.size() < 150)
return 0;
int removed = 0;
for (Hash key : keys) {
// Don't expire anybody we are connected to

View File

@ -275,9 +275,11 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
//// expire some routers
// Don't run until after RefreshRoutersJob has run, and after validate() will return invalid for old routers.
Job erj = new ExpireRoutersJob(_context, this);
erj.getTiming().setStartAfter(_context.clock().now() + ROUTER_INFO_EXPIRATION_FLOODFILL + 10*60*1000);
_context.jobQueue().addJob(erj);
if (!_context.commSystem().isDummy()) {
Job erj = new ExpireRoutersJob(_context, this);
erj.getTiming().setStartAfter(_context.clock().now() + ROUTER_INFO_EXPIRATION_FLOODFILL + 10*60*1000);
_context.jobQueue().addJob(erj);
}
if (!QUIET) {
// fill the search queue with random keys in buckets that are too small