Merge branch 'publish2' into 'master'

NetDB: RI Publish improvements part 2

See merge request i2p-hackers/i2p.i2p!226
This commit is contained in:
zzz
2025-01-28 17:10:32 +00:00
3 changed files with 19 additions and 30 deletions

View File

@@ -47,6 +47,7 @@ import net.i2p.data.router.RouterInfo;
import net.i2p.router.CommSystemFacade.Status;
import net.i2p.router.crypto.FamilyKeyCrypto;
import net.i2p.router.message.GarlicMessageHandler;
import net.i2p.router.networkdb.PublishLocalRouterInfoJob;
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
import net.i2p.router.startup.CreateRouterInfoJob;
import net.i2p.router.startup.PortableWorkingDir;
@@ -936,6 +937,11 @@ public class Router implements RouterClock.ClockShiftListener {
// so we probably don't need to throw it to the timer queue,
// but just to be safe
_context.simpleTimer2().addEvent(r, 0);
// periodically update our RI and republish it to the flooodfills
PublishLocalRouterInfoJob plrij = new PublishLocalRouterInfoJob(_context);
plrij.getTiming().setStartAfter(_context.clock().now() + plrij.getDelay());
_context.jobQueue().addJob(plrij);
}
if (changed) {
_context.commSystem().initGeoIP();

View File

@@ -58,7 +58,6 @@ public class PublishLocalRouterInfoJob extends JobImpl {
* in Router.setNetDbReady(), so we probably don't need this anymore
*/
private static final long FIRST_TIME_DELAY = 90*1000;
private volatile boolean _notFirstTime;
private final AtomicInteger _runCount = new AtomicInteger();
public PublishLocalRouterInfoJob(RouterContext ctx) {
@@ -92,7 +91,9 @@ public class PublishLocalRouterInfoJob extends JobImpl {
List<RouterAddress> newAddrs = getContext().commSystem().createAddresses();
int count = _runCount.incrementAndGet();
RouterInfo ri = new RouterInfo(oldRI);
if (_notFirstTime && (count % 4) != 0 && oldAddrs.size() == newAddrs.size()) {
if ((count % 4) != 0 &&
oldAddrs.size() == newAddrs.size() &&
getContext().random().nextInt(32) != 0) {
// 3 times out of 4, we don't republish if everything is the same...
// If something changed, including the cost, then publish,
// otherwise don't.
@@ -149,19 +150,15 @@ public class PublishLocalRouterInfoJob extends JobImpl {
} catch (DataFormatException dfe) {
_log.error("Error signing the updated local router info!", dfe);
}
if (_notFirstTime) {
requeue(getDelay());
} else {
// First publish after netdb ready is now done via state machine
// in Router.setNetDbReady(), so we probably don't need this anymore
// but leave it in for now, a router may have trouble publishing right away
requeue(FIRST_TIME_DELAY);
_notFirstTime = true;
}
_runCount.set(0);
requeue(getDelay());
}
private long getDelay() {
long rv = (PUBLISH_DELAY * 3 / 4) + getContext().random().nextLong(PUBLISH_DELAY / 4);
/**
* @since public since 0.9.65 for use by Router
*/
public long getDelay() {
long rv = (PUBLISH_DELAY * 2 / 3) + getContext().random().nextLong(PUBLISH_DELAY / 3);
// run 4x as often as usual publish time (see above)
rv /= 4;
return rv;

View File

@@ -429,23 +429,9 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
_log.warn("Operating in quiet mode - not exploring or pushing data proactively, simply reactively");
_log.warn("This should NOT be used in production");
}
if (!isClientDb()) {
// periodically update and resign the router's 'published date', which basically
// serves as a version
Job plrij = new PublishLocalRouterInfoJob(_context);
// do not delay this, as this creates the RI too, and we need a good local routerinfo right away
//plrij.getTiming().setStartAfter(_context.clock().now() + PUBLISH_JOB_DELAY);
_context.jobQueue().addJob(plrij);
// plrij calls publish() for us
//try {
// publish(ri);
//} catch (IllegalArgumentException iae) {
// _context.router().rebuildRouterInfo(true);
// //_log.log(Log.CRIT, "Our local router info is b0rked, clearing from scratch", iae);
// //_context.router().rebuildNewIdentity();
//}
}
//
// PublishLocalRouterInfoJob is now started from Router.setNetDbReady()
//
}
/** unused, see override */