From 84337244520be02f877494a66cfafd49895b80e0 Mon Sep 17 00:00:00 2001 From: zzz Date: Sat, 21 Nov 2009 13:50:39 +0000 Subject: [PATCH] * Netdb Floodfill rework part 4 of N: Search closest-to-the-key --- .../src/net/i2p/data/RoutingKeyGenerator.java | 8 +++++- history.txt | 11 ++++++++ .../src/net/i2p/router/RouterVersion.java | 2 +- .../kademlia/FloodOnlySearchJob.java | 26 ++++++++++++++++--- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/core/java/src/net/i2p/data/RoutingKeyGenerator.java b/core/java/src/net/i2p/data/RoutingKeyGenerator.java index 5589d589e..94bb7135f 100644 --- a/core/java/src/net/i2p/data/RoutingKeyGenerator.java +++ b/core/java/src/net/i2p/data/RoutingKeyGenerator.java @@ -52,6 +52,7 @@ public class RoutingKeyGenerator { } private byte _currentModData[]; + private long _lastChanged; private final static Calendar _cal = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT")); private final static SimpleDateFormat _fmt = new SimpleDateFormat("yyyyMMdd"); @@ -60,8 +61,13 @@ public class RoutingKeyGenerator { return _currentModData; } + public long getLastChanged() { + return _lastChanged; + } + public void setModData(byte modData[]) { _currentModData = modData; + _lastChanged = _context.clock().now(); } /** @@ -131,4 +137,4 @@ public class RoutingKeyGenerator { } catch (Throwable t) { // nop } } -} \ No newline at end of file +} diff --git a/history.txt b/history.txt index 45ede2a7d..66c39bf3d 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,14 @@ +2009-11-21 zzz + * Netdb Floodfill rework part 4 of N: + - Search closest-to-the-key + - Put closest-to-the-key in explore don't-include-list + - Use facade's peer selector for exploration rather than + instantiating a new one + - Adjust response time limit + * netdb.jsp: Add popups on flags + * Routerconsole build: rename include files so they aren't + compiled and bundled separately (~15KB) + 2009-11-18 zzz * Build: Don't update the po files by default, add new target "poupdate" to do that. diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 40028c0e0..67b9de3fe 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -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 = 19; + public final static long BUILD = 20; /** for example "-test" */ public final static String EXTRA = ""; public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA; diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/FloodOnlySearchJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/FloodOnlySearchJob.java index 0aa8d5099..70388012b 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodOnlySearchJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodOnlySearchJob.java @@ -68,12 +68,29 @@ class FloodOnlySearchJob extends FloodSearchJob { public long getCreated() { return _created; } public boolean shouldProcessDSRM() { return _shouldProcessDSRM; } private static final int CONCURRENT_SEARCHES = 2; + private static final int MIN_FOR_NO_DSRM = 4; + @Override public void runJob() { // pick some floodfill peers and send out the searches - List floodfillPeers = _facade.getFloodfillPeers(); - if (floodfillPeers.size() <= 3) - _shouldProcessDSRM = true; + // old + //List floodfillPeers = _facade.getFloodfillPeers(); + // new + List floodfillPeers; + KBucketSet ks = _facade.getKBuckets(); + if (ks != null) { + Hash rkey = getContext().routingKeyGenerator().getRoutingKey(_key); + floodfillPeers = ((FloodfillPeerSelector)_facade.getPeerSelector()).selectFloodfillParticipants(rkey, MIN_FOR_NO_DSRM, ks); + } else { + floodfillPeers = Collections.EMPTY_LIST; + } + + // If we dont know enough floodfills, + // or the global network routing key just changed (which is set at statrtup, + // so this includes the first few minutes of uptime) + _shouldProcessDSRM = floodfillPeers.size() < MIN_FOR_NO_DSRM || + getContext().routingKeyGenerator().getLastChanged() > getContext().clock().now() - 30*60*1000; + if (floodfillPeers.size() <= 0) { // ask anybody, they may not return the answer but they will return a few ff peers we can go look up, // so this situation should be temporary @@ -86,10 +103,12 @@ class FloodOnlySearchJob extends FloodSearchJob { failed(); return; } + Collections.shuffle(floodfillPeers, getContext().random()); } OutNetMessage out = getContext().messageRegistry().registerPending(_replySelector, _onReply, _onTimeout, _timeoutMs); synchronized (_out) { _out.add(out); } +/******** // We need to randomize our ff selection, else we stay with the same ones since // getFloodfillPeers() is sorted by closest distance. Always using the same // ones didn't help reliability. @@ -124,6 +143,7 @@ class FloodOnlySearchJob extends FloodSearchJob { } else { _shouldProcessDSRM = true; } +********/ int count = 0; // keep a separate count since _lookupsRemaining could be decremented elsewhere for (int i = 0; _lookupsRemaining < CONCURRENT_SEARCHES && i < floodfillPeers.size(); i++) {