I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 042a08b9 authored by zzz's avatar zzz
Browse files

* NetDb:

      - 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()
parent 235058ea
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,9 @@ package net.i2p.router.networkdb.kademlia; ...@@ -8,7 +8,9 @@ package net.i2p.router.networkdb.kademlia;
* *
*/ */
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import net.i2p.data.Hash; import net.i2p.data.Hash;
import net.i2p.data.TunnelId; import net.i2p.data.TunnelId;
...@@ -96,7 +98,13 @@ class ExploreJob extends SearchJob { ...@@ -96,7 +98,13 @@ class ExploreJob extends SearchJob {
available = MAX_CLOSEST - msg.getDontIncludePeers().size(); available = MAX_CLOSEST - msg.getDontIncludePeers().size();
if (available > 0) { 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); msg.getDontIncludePeers().addAll(peers);
} }
...@@ -106,17 +114,6 @@ class ExploreJob extends SearchJob { ...@@ -106,17 +114,6 @@ class ExploreJob extends SearchJob {
return msg; 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 */ /** max # of concurrent searches */
@Override @Override
protected int getBredth() { return EXPLORE_BREDTH; } protected int getBredth() { return EXPLORE_BREDTH; }
......
...@@ -44,7 +44,7 @@ class FloodfillPeerSelector extends PeerSelector { ...@@ -44,7 +44,7 @@ class FloodfillPeerSelector extends PeerSelector {
public List selectNearestExplicitThin(Hash key, int maxNumRouters, Set peersToIgnore, KBucketSet kbuckets, boolean preferConnected) { public List selectNearestExplicitThin(Hash key, int maxNumRouters, Set peersToIgnore, KBucketSet kbuckets, boolean preferConnected) {
if (peersToIgnore == null) if (peersToIgnore == null)
peersToIgnore = new HashSet(1); peersToIgnore = new HashSet(1);
peersToIgnore.add(_context.router().getRouterInfo().getIdentity().getHash()); peersToIgnore.add(_context.routerHash());
FloodfillSelectionCollector matches = new FloodfillSelectionCollector(key, peersToIgnore, maxNumRouters); FloodfillSelectionCollector matches = new FloodfillSelectionCollector(key, peersToIgnore, maxNumRouters);
if (kbuckets == null) return new ArrayList(); if (kbuckets == null) return new ArrayList();
kbuckets.getAll(matches); kbuckets.getAll(matches);
......
...@@ -61,7 +61,7 @@ public class PeerSelector { ...@@ -61,7 +61,7 @@ public class PeerSelector {
if (peersToIgnore == null) if (peersToIgnore == null)
peersToIgnore = new HashSet(1); peersToIgnore = new HashSet(1);
peersToIgnore.add(_context.router().getRouterInfo().getIdentity().getHash()); peersToIgnore.add(_context.routerHash());
Set allHashes = kbuckets.getAll(peersToIgnore); Set allHashes = kbuckets.getAll(peersToIgnore);
removeFailingPeers(allHashes); removeFailingPeers(allHashes);
Map diffMap = new HashMap(allHashes.size()); Map diffMap = new HashMap(allHashes.size());
...@@ -94,7 +94,7 @@ public class PeerSelector { ...@@ -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 public List selectNearestExplicitThin(Hash key, int maxNumRouters, Set peersToIgnore, KBucketSet kbuckets) { // LINT -- Exporting non-public type through public API
if (peersToIgnore == null) if (peersToIgnore == null)
peersToIgnore = new HashSet(1); peersToIgnore = new HashSet(1);
peersToIgnore.add(_context.router().getRouterInfo().getIdentity().getHash()); peersToIgnore.add(_context.routerHash());
MatchSelectionCollector matches = new MatchSelectionCollector(key, peersToIgnore); MatchSelectionCollector matches = new MatchSelectionCollector(key, peersToIgnore);
kbuckets.getAll(matches); kbuckets.getAll(matches);
List rv = matches.get(maxNumRouters); List rv = matches.get(maxNumRouters);
......
...@@ -106,8 +106,10 @@ class PersistentDataStore extends TransientDataStore { ...@@ -106,8 +106,10 @@ class PersistentDataStore extends TransientDataStore {
*/ */
@Override @Override
public DataStructure remove(Hash key, boolean persist) { public DataStructure remove(Hash key, boolean persist) {
if (persist) if (persist) {
_writer.remove(key);
_context.jobQueue().addJob(new RemoveJob(key)); _context.jobQueue().addJob(new RemoveJob(key));
}
return super.remove(key); return super.remove(key);
} }
...@@ -183,6 +185,10 @@ class PersistentDataStore extends TransientDataStore { ...@@ -183,6 +185,10 @@ class PersistentDataStore extends TransientDataStore {
return _keys.get(key); return _keys.get(key);
} }
public void remove(Hash key) {
_keys.remove(key);
}
public void run() { public void run() {
_quit = false; _quit = false;
Hash key = null; Hash key = null;
......
...@@ -452,6 +452,7 @@ class SearchJob extends JobImpl { ...@@ -452,6 +452,7 @@ class SearchJob extends JobImpl {
} }
/** we're searching for a router, so we can just send direct */ /** we're searching for a router, so we can just send direct */
/******* always send through the lease
protected void sendRouterSearch(RouterInfo router) { protected void sendRouterSearch(RouterInfo router) {
int timeout = _facade.getPeerTimeout(router.getIdentity().getHash()); int timeout = _facade.getPeerTimeout(router.getIdentity().getHash());
long expiration = getContext().clock().now() + timeout; long expiration = getContext().clock().now() + timeout;
...@@ -471,6 +472,7 @@ class SearchJob extends JobImpl { ...@@ -471,6 +472,7 @@ class SearchJob extends JobImpl {
j.runJob(); j.runJob();
//getContext().jobQueue().addJob(j); //getContext().jobQueue().addJob(j);
} }
**********/
/** /**
* what tunnel will we send the search out through? * what tunnel will we send the search out through?
...@@ -513,6 +515,7 @@ class SearchJob extends JobImpl { ...@@ -513,6 +515,7 @@ class SearchJob extends JobImpl {
* replies sent back to us directly) * replies sent back to us directly)
* *
*/ */
/******* always send through the lease
protected DatabaseLookupMessage buildMessage(long expiration) { protected DatabaseLookupMessage buildMessage(long expiration) {
DatabaseLookupMessage msg = new DatabaseLookupMessage(getContext(), true); DatabaseLookupMessage msg = new DatabaseLookupMessage(getContext(), true);
msg.setSearchKey(_state.getTarget()); msg.setSearchKey(_state.getTarget());
...@@ -522,6 +525,7 @@ class SearchJob extends JobImpl { ...@@ -522,6 +525,7 @@ class SearchJob extends JobImpl {
msg.setReplyTunnel(null); msg.setReplyTunnel(null);
return msg; return msg;
} }
*********/
void replyFound(DatabaseSearchReplyMessage message, Hash peer) { void replyFound(DatabaseSearchReplyMessage message, Hash peer) {
long duration = _state.replyFound(peer); long duration = _state.replyFound(peer);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment