From 0c520de6e577ba0e715f4669fa8f1e651d329739 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Sun, 26 Oct 2008 18:05:51 +0000
Subject: [PATCH]     * HandleFloodfillDatabaseLookupMessageJob:        - Send
 back your routerinfo with the DSRM if not ff to          spread the word that
 you aren't ff anymore        - Fix behavior when router.isHidden=true

---
 .../HandleDatabaseLookupMessageJob.java       |  6 ++---
 ...ndleFloodfillDatabaseLookupMessageJob.java | 27 +++++++++++++++++++
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/router/java/src/net/i2p/router/networkdb/HandleDatabaseLookupMessageJob.java b/router/java/src/net/i2p/router/networkdb/HandleDatabaseLookupMessageJob.java
index a61de8c055..a953bd5959 100644
--- a/router/java/src/net/i2p/router/networkdb/HandleDatabaseLookupMessageJob.java
+++ b/router/java/src/net/i2p/router/networkdb/HandleDatabaseLookupMessageJob.java
@@ -82,7 +82,7 @@ public class HandleDatabaseLookupMessageJob extends JobImpl {
         }
 
         // If we are hidden we should not get queries, log and return
-        if (getContext().router().getRouterInfo().isHidden()) {
+        if (getContext().router().isHidden()) {
             if (_log.shouldLog(Log.ERROR)) {
                 _log.error("Uninvited dbLookup received with replies going to " + fromKey
                            + " (tunnel " + _message.getReplyTunnel() + ")");
@@ -211,7 +211,7 @@ public class HandleDatabaseLookupMessageJob extends JobImpl {
         sendMessage(msg, toPeer, replyTunnel);
     }
     
-    private void sendClosest(Hash key, Set routerInfoSet, Hash toPeer, TunnelId replyTunnel) {
+    protected void sendClosest(Hash key, Set routerInfoSet, Hash toPeer, TunnelId replyTunnel) {
         if (_log.shouldLog(Log.DEBUG))
             _log.debug("Sending closest routers to key " + key.toBase64() + ": # peers = " 
                        + routerInfoSet.size() + " tunnel " + replyTunnel);
@@ -228,7 +228,7 @@ public class HandleDatabaseLookupMessageJob extends JobImpl {
         sendMessage(msg, toPeer, replyTunnel); // should this go via garlic messages instead?
     }
     
-    private void sendMessage(I2NPMessage message, Hash toPeer, TunnelId replyTunnel) {
+    protected void sendMessage(I2NPMessage message, Hash toPeer, TunnelId replyTunnel) {
         if (replyTunnel != null) {
             sendThroughTunnel(message, toPeer, replyTunnel);
         } else {
diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/HandleFloodfillDatabaseLookupMessageJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/HandleFloodfillDatabaseLookupMessageJob.java
index 986dc2eddb..e3a6b6df9d 100644
--- a/router/java/src/net/i2p/router/networkdb/kademlia/HandleFloodfillDatabaseLookupMessageJob.java
+++ b/router/java/src/net/i2p/router/networkdb/kademlia/HandleFloodfillDatabaseLookupMessageJob.java
@@ -8,12 +8,18 @@ package net.i2p.router.networkdb.kademlia;
  *
  */
 
+import java.util.Set;
+
 import net.i2p.data.Hash;
 import net.i2p.data.RouterIdentity;
+import net.i2p.data.RouterInfo;
+import net.i2p.data.TunnelId;
+import net.i2p.data.i2np.DatabaseStoreMessage;
 import net.i2p.data.i2np.DatabaseLookupMessage;
 import net.i2p.router.RouterContext;
 import net.i2p.router.networkdb.HandleDatabaseLookupMessageJob;
 
+
 /**
  * Handle a lookup for a key received from a remote peer.  Needs to be implemented
  * to send back replies, etc
@@ -28,4 +34,25 @@ public class HandleFloodfillDatabaseLookupMessageJob extends HandleDatabaseLooku
         if (!FloodfillNetworkDatabaseFacade.floodfillEnabled(getContext())) return false;
         return FloodfillNetworkDatabaseFacade.isFloodfill(getContext().router().getRouterInfo());
     }
+
+    /**
+     * We extend this here to send our routerInfo back as well, if we are not floodfill.
+     * This gets the word out to routers that we are no longer floodfill, so they
+     * will stop bugging us.
+     */
+    protected void sendClosest(Hash key, Set routerInfoSet, Hash toPeer, TunnelId replyTunnel) {
+        super.sendClosest(key, routerInfoSet, toPeer, replyTunnel);
+
+        // go away, you got the wrong guy, send our RI back unsolicited
+        if (!FloodfillNetworkDatabaseFacade.floodfillEnabled(getContext())) {
+            // We could just call sendData(myhash, myri, toPeer, replyTunnel) but
+            // that would increment the netDb.lookupsHandled and netDb.lookupsMatched stats
+            DatabaseStoreMessage msg = new DatabaseStoreMessage(getContext());
+            RouterInfo me = getContext().router().getRouterInfo();
+            msg.setKey(me.getIdentity().getHash());
+            msg.setRouterInfo(me);
+            msg.setValueType(DatabaseStoreMessage.KEY_TYPE_ROUTERINFO);
+            sendMessage(msg, toPeer, replyTunnel);
+        }
+    }
 }
-- 
GitLab