- Don't send our own hash in the don't-include list when exploring
      - Remove any pending write when removing a RouterInfo
      - Cleanup to use routerHash()
This commit is contained in:
zzz
2009-05-25 16:34:26 +00:00
parent 235058eab1
commit 042a08b90e
5 changed files with 23 additions and 16 deletions

View File

@ -8,7 +8,9 @@ package net.i2p.router.networkdb.kademlia;
*
*/
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.i2p.data.Hash;
import net.i2p.data.TunnelId;
@ -96,7 +98,13 @@ class ExploreJob extends SearchJob {
available = MAX_CLOSEST - msg.getDontIncludePeers().size();
if (available > 0) {
List peers = _peerSelector.selectNearestExplicit(getState().getTarget(), available, msg.getDontIncludePeers(), getFacade().getKBuckets());
// selectNearestExplicit adds our hash to the dontInclude set (3rd param) ...
// And we end up with MAX_CLOSEST+1 entries.
// We don't want our hash in the message's don't-include list though.
// We're just exploring, but this could give things away, and tie our exploratory tunnels to our router,
// so let's not put our hash in there.
Set dontInclude = new HashSet(msg.getDontIncludePeers());
List peers = _peerSelector.selectNearestExplicit(getState().getTarget(), available, dontInclude, getFacade().getKBuckets());
msg.getDontIncludePeers().addAll(peers);
}
@ -106,17 +114,6 @@ class ExploreJob extends SearchJob {
return msg;
}
/**
* We're looking for a router, so lets build the lookup message (no need to tunnel route either, so just have
* replies sent back to us directly). This uses the similar overrides as the other buildMessage above.
*
*/
@Override
protected DatabaseLookupMessage buildMessage(long expiration) {
return buildMessage(null, getContext().router().getRouterInfo().getIdentity().getHash(), expiration);
}
/** max # of concurrent searches */
@Override
protected int getBredth() { return EXPLORE_BREDTH; }

View File

@ -44,7 +44,7 @@ class FloodfillPeerSelector extends PeerSelector {
public List selectNearestExplicitThin(Hash key, int maxNumRouters, Set peersToIgnore, KBucketSet kbuckets, boolean preferConnected) {
if (peersToIgnore == null)
peersToIgnore = new HashSet(1);
peersToIgnore.add(_context.router().getRouterInfo().getIdentity().getHash());
peersToIgnore.add(_context.routerHash());
FloodfillSelectionCollector matches = new FloodfillSelectionCollector(key, peersToIgnore, maxNumRouters);
if (kbuckets == null) return new ArrayList();
kbuckets.getAll(matches);

View File

@ -61,7 +61,7 @@ public class PeerSelector {
if (peersToIgnore == null)
peersToIgnore = new HashSet(1);
peersToIgnore.add(_context.router().getRouterInfo().getIdentity().getHash());
peersToIgnore.add(_context.routerHash());
Set allHashes = kbuckets.getAll(peersToIgnore);
removeFailingPeers(allHashes);
Map diffMap = new HashMap(allHashes.size());
@ -94,7 +94,7 @@ public class PeerSelector {
public List selectNearestExplicitThin(Hash key, int maxNumRouters, Set peersToIgnore, KBucketSet kbuckets) { // LINT -- Exporting non-public type through public API
if (peersToIgnore == null)
peersToIgnore = new HashSet(1);
peersToIgnore.add(_context.router().getRouterInfo().getIdentity().getHash());
peersToIgnore.add(_context.routerHash());
MatchSelectionCollector matches = new MatchSelectionCollector(key, peersToIgnore);
kbuckets.getAll(matches);
List rv = matches.get(maxNumRouters);

View File

@ -106,8 +106,10 @@ class PersistentDataStore extends TransientDataStore {
*/
@Override
public DataStructure remove(Hash key, boolean persist) {
if (persist)
if (persist) {
_writer.remove(key);
_context.jobQueue().addJob(new RemoveJob(key));
}
return super.remove(key);
}
@ -183,6 +185,10 @@ class PersistentDataStore extends TransientDataStore {
return _keys.get(key);
}
public void remove(Hash key) {
_keys.remove(key);
}
public void run() {
_quit = false;
Hash key = null;

View File

@ -452,6 +452,7 @@ class SearchJob extends JobImpl {
}
/** we're searching for a router, so we can just send direct */
/******* always send through the lease
protected void sendRouterSearch(RouterInfo router) {
int timeout = _facade.getPeerTimeout(router.getIdentity().getHash());
long expiration = getContext().clock().now() + timeout;
@ -471,6 +472,7 @@ class SearchJob extends JobImpl {
j.runJob();
//getContext().jobQueue().addJob(j);
}
**********/
/**
* what tunnel will we send the search out through?
@ -513,6 +515,7 @@ class SearchJob extends JobImpl {
* replies sent back to us directly)
*
*/
/******* always send through the lease
protected DatabaseLookupMessage buildMessage(long expiration) {
DatabaseLookupMessage msg = new DatabaseLookupMessage(getContext(), true);
msg.setSearchKey(_state.getTarget());
@ -522,6 +525,7 @@ class SearchJob extends JobImpl {
msg.setReplyTunnel(null);
return msg;
}
*********/
void replyFound(DatabaseSearchReplyMessage message, Hash peer) {
long duration = _state.replyFound(peer);