From 5ef325408ce2bd1d33cddf8f902afa2fe2d59b6e Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Fri, 7 Mar 2008 14:31:36 +0000
Subject: [PATCH] Optimize naming lookups for a destkey

---
 .../src/net/i2p/client/naming/EepGetNamingService.java |  9 +++++----
 .../src/net/i2p/client/naming/ExecNamingService.java   |  9 +++++----
 .../net/i2p/client/naming/HostsTxtNamingService.java   | 10 ++++++----
 3 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/core/java/src/net/i2p/client/naming/EepGetNamingService.java b/core/java/src/net/i2p/client/naming/EepGetNamingService.java
index 99aae007c8..057f3d4f68 100644
--- a/core/java/src/net/i2p/client/naming/EepGetNamingService.java
+++ b/core/java/src/net/i2p/client/naming/EepGetNamingService.java
@@ -63,6 +63,10 @@ public class EepGetNamingService extends NamingService {
     }
         
     public Destination lookup(String hostname) {
+        // If it's long, assume it's a key.
+        if (hostname.length() >= DEST_SIZE)
+            return lookupBase64(hostname);
+
         hostname = hostname.toLowerCase();
 
         // check the cache
@@ -95,10 +99,7 @@ public class EepGetNamingService extends NamingService {
                 return lookupBase64(key);
             }
         }
-
-        // If we can't find name,
-        // assume it's a key.
-        return lookupBase64(hostname);
+        return null;
     }
 
     private static final int DEST_SIZE = 516;                    // Std. Base64 length (no certificate)
diff --git a/core/java/src/net/i2p/client/naming/ExecNamingService.java b/core/java/src/net/i2p/client/naming/ExecNamingService.java
index 19e94dfca6..8d76f50fd8 100644
--- a/core/java/src/net/i2p/client/naming/ExecNamingService.java
+++ b/core/java/src/net/i2p/client/naming/ExecNamingService.java
@@ -64,6 +64,10 @@ public class ExecNamingService extends NamingService {
     }
         
     public Destination lookup(String hostname) {
+        // If it's long, assume it's a key.
+        if (hostname.length() >= DEST_SIZE)
+            return lookupBase64(hostname);
+
         hostname = hostname.toLowerCase();
 
         // check the cache
@@ -80,10 +84,7 @@ public class ExecNamingService extends NamingService {
             _hosts.setProperty(hostname, key);  // cache
             return lookupBase64(key);
         }
-
-        // If we can't find name, 
-        // assume it's a key.
-        return lookupBase64(hostname);
+        return null;
     }
 
     private static final int DEST_SIZE = 516;                    // Std. Base64 length (no certificate)
diff --git a/core/java/src/net/i2p/client/naming/HostsTxtNamingService.java b/core/java/src/net/i2p/client/naming/HostsTxtNamingService.java
index 20a59121e1..696fe1479b 100644
--- a/core/java/src/net/i2p/client/naming/HostsTxtNamingService.java
+++ b/core/java/src/net/i2p/client/naming/HostsTxtNamingService.java
@@ -54,6 +54,10 @@ public class HostsTxtNamingService extends NamingService {
     }
         
     public Destination lookup(String hostname) {
+        // If it's long, assume it's a key.
+        if (hostname.length() >= 516)
+            return lookupBase64(hostname);
+
         // check the list each time, reloading the file on each
         // lookup
         
@@ -79,12 +83,10 @@ public class HostsTxtNamingService extends NamingService {
             }
             // not found, continue to the next file
         }
-        // If we can't find name in any of the hosts files, 
-        // assume it's a key.
-        return lookupBase64(hostname);
+        return null;
     }
 
     public String reverseLookup(Destination dest) {
         return null;
     }
-}
\ No newline at end of file
+}
-- 
GitLab