enforce max leaseset publish frequency
This commit is contained in:
@ -456,6 +456,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
|
||||
}
|
||||
}
|
||||
|
||||
private static final long PUBLISH_DELAY = 3*1000;
|
||||
public void publish(LeaseSet localLeaseSet) {
|
||||
if (!_initialized) return;
|
||||
Hash h = localLeaseSet.getDestination().calculateHash();
|
||||
@ -476,7 +477,10 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
|
||||
_publishingLeaseSets.put(h, j);
|
||||
}
|
||||
}
|
||||
j.getTiming().setStartAfter(_context.clock().now());
|
||||
// Don't spam the floodfills. In addition, always delay a few seconds since there may
|
||||
// be another leaseset change coming along momentarily.
|
||||
long nextTime = Math.max(j.lastPublished() + j.REPUBLISH_LEASESET_TIMEOUT, _context.clock().now() + PUBLISH_DELAY);
|
||||
j.getTiming().setStartAfter(nextTime);
|
||||
_context.jobQueue().addJob(j);
|
||||
}
|
||||
|
||||
|
@ -23,15 +23,18 @@ import net.i2p.util.Log;
|
||||
public class RepublishLeaseSetJob extends JobImpl {
|
||||
private Log _log;
|
||||
private final static long REPUBLISH_LEASESET_DELAY = 5*60*1000;
|
||||
private final static long REPUBLISH_LEASESET_TIMEOUT = 60*1000;
|
||||
public final static long REPUBLISH_LEASESET_TIMEOUT = 60*1000;
|
||||
private Hash _dest;
|
||||
private KademliaNetworkDatabaseFacade _facade;
|
||||
/** this is actually last attempted publish */
|
||||
private long _lastPublished;
|
||||
|
||||
public RepublishLeaseSetJob(RouterContext ctx, KademliaNetworkDatabaseFacade facade, Hash destHash) {
|
||||
super(ctx);
|
||||
_log = ctx.logManager().getLog(RepublishLeaseSetJob.class);
|
||||
_facade = facade;
|
||||
_dest = destHash;
|
||||
_lastPublished = 0;
|
||||
//getTiming().setStartAfter(ctx.clock().now()+REPUBLISH_LEASESET_DELAY);
|
||||
getContext().statManager().createRateStat("netDb.republishLeaseSetCount", "How often we republish a leaseSet?", "NetworkDatabase", new long[] { 5*60*1000l, 60*60*1000l, 24*60*60*1000l });
|
||||
}
|
||||
@ -52,6 +55,7 @@ public class RepublishLeaseSetJob extends JobImpl {
|
||||
} else {
|
||||
getContext().statManager().addRateData("netDb.republishLeaseSetCount", 1, 0);
|
||||
_facade.sendStore(_dest, ls, new OnRepublishSuccess(getContext()), new OnRepublishFailure(getContext(), this), REPUBLISH_LEASESET_TIMEOUT, null);
|
||||
_lastPublished = getContext().clock().now();
|
||||
//getContext().jobQueue().addJob(new StoreJob(getContext(), _facade, _dest, ls, new OnSuccess(getContext()), new OnFailure(getContext()), REPUBLISH_LEASESET_TIMEOUT));
|
||||
}
|
||||
} else {
|
||||
@ -82,6 +86,10 @@ public class RepublishLeaseSetJob extends JobImpl {
|
||||
requeue(getContext().random().nextInt(60*1000));
|
||||
}
|
||||
|
||||
public long lastPublished() {
|
||||
return _lastPublished;
|
||||
}
|
||||
|
||||
class OnRepublishSuccess extends JobImpl {
|
||||
public OnRepublishSuccess(RouterContext ctx) { super(ctx); }
|
||||
public String getName() { return "Publish leaseSet successful"; }
|
||||
|
Reference in New Issue
Block a user