- Just before midnight, flood to new location too so lookups
   don't fail after keyspace rotation (ticket #510)
 - Refactor RoutingKeyGenerator and UpdateRoutingKeyModifierJob
   in support of the above
 - Display next key on LS debug page
This commit is contained in:
zzz
2013-12-14 14:38:00 +00:00
parent 6e2583ad92
commit efff25a87c
7 changed files with 134 additions and 50 deletions

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 2;
public final static long BUILD = 3;
/** for example "-test" */
public final static String EXTRA = "";

View File

@ -43,6 +43,9 @@ public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacad
private static final int FLOOD_PRIORITY = OutNetMessage.PRIORITY_NETDB_FLOOD;
private static final int FLOOD_TIMEOUT = 30*1000;
private static final long NEXT_RKEY_RI_ADVANCE_TIME = 45*60*1000;
private static final long NEXT_RKEY_LS_ADVANCE_TIME = 10*60*1000;
private static final int NEXT_FLOOD_QTY = 2;
public FloodfillNetworkDatabaseFacade(RouterContext context) {
super(context);
@ -197,6 +200,23 @@ public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacad
Hash rkey = _context.routingKeyGenerator().getRoutingKey(key);
FloodfillPeerSelector sel = (FloodfillPeerSelector)getPeerSelector();
List<Hash> peers = sel.selectFloodfillParticipants(rkey, MAX_TO_FLOOD, getKBuckets());
long until = _context.routingKeyGenerator().getTimeTillMidnight();
if (until < NEXT_RKEY_LS_ADVANCE_TIME ||
(ds.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO && until < NEXT_RKEY_RI_ADVANCE_TIME)) {
// to avoid lookup failures after midnight, also flood to some closest to the
// next routing key for a period of time before midnight.
Hash nkey = _context.routingKeyGenerator().getNextRoutingKey(key);
List<Hash> nextPeers = sel.selectFloodfillParticipants(nkey, NEXT_FLOOD_QTY, getKBuckets());
int i = 0;
for (Hash h : nextPeers) {
if (!peers.contains(h)) {
peers.add(h);
i++;
}
}
if (i > 0 && _log.shouldLog(Log.INFO))
_log.info("Flooding the entry for " + key + " to " + i + " more, just before midnight");
}
int flooded = 0;
for (int i = 0; i < peers.size(); i++) {
Hash peer = peers.get(i);

View File

@ -8,11 +8,7 @@ package net.i2p.router.tasks;
*
*/
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import net.i2p.data.RoutingKeyGenerator;
import net.i2p.router.JobImpl;
import net.i2p.router.RouterContext;
import net.i2p.util.Log;
@ -26,7 +22,6 @@ import net.i2p.util.Log;
*/
public class UpdateRoutingKeyModifierJob extends JobImpl {
private final Log _log;
private final Calendar _cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
// Run every 15 minutes in case of time zone change, clock skew, etc.
private static final long MAX_DELAY_FAILSAFE = 15*60*1000;
@ -38,29 +33,11 @@ public class UpdateRoutingKeyModifierJob extends JobImpl {
public String getName() { return "Update Routing Key Modifier"; }
public void runJob() {
RoutingKeyGenerator gen = getContext().routingKeyGenerator();
// make sure we requeue quickly if just before midnight
long delay = Math.min(MAX_DELAY_FAILSAFE, getTimeTillMidnight());
long delay = Math.max(5, Math.min(MAX_DELAY_FAILSAFE, gen.getTimeTillMidnight()));
// TODO tell netdb if mod data changed?
getContext().routingKeyGenerator().generateDateBasedModData();
gen.generateDateBasedModData();
requeue(delay);
}
private long getTimeTillMidnight() {
long now = getContext().clock().now();
_cal.setTime(new Date(now));
_cal.set(Calendar.YEAR, _cal.get(Calendar.YEAR)); // gcj <= 4.0 workaround
_cal.set(Calendar.DAY_OF_YEAR, _cal.get(Calendar.DAY_OF_YEAR)); // gcj <= 4.0 workaround
_cal.add(Calendar.DATE, 1);
_cal.set(Calendar.HOUR_OF_DAY, 0);
_cal.set(Calendar.MINUTE, 0);
_cal.set(Calendar.SECOND, 0);
_cal.set(Calendar.MILLISECOND, 0);
long then = _cal.getTime().getTime();
long howLong = then - now;
if (howLong < 0) // hi kaffe
howLong = 24*60*60*1000l + howLong;
if (_log.shouldLog(Log.DEBUG))
_log.debug("Time till midnight: " + howLong + "ms");
return howLong;
}
}