From b32c8d5fa4cec3cc5cf617ef6e003aeceae04ee1 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Sat, 10 Oct 2015 12:29:52 +0000
Subject: [PATCH] NamingServices: Add support for lookups prefixed with "www."

---
 .../client/naming/BlockfileNamingService.java | 22 +++++++++++++++++++
 .../naming/SingleFileNamingService.java       |  4 ++++
 2 files changed, 26 insertions(+)

diff --git a/core/java/src/net/i2p/client/naming/BlockfileNamingService.java b/core/java/src/net/i2p/client/naming/BlockfileNamingService.java
index ec12eb792d..efa8b3e064 100644
--- a/core/java/src/net/i2p/client/naming/BlockfileNamingService.java
+++ b/core/java/src/net/i2p/client/naming/BlockfileNamingService.java
@@ -621,11 +621,33 @@ public class BlockfileNamingService extends DummyNamingService {
     ////////// Start NamingService API
 
     /*
+     *
+     * Will strip a "www." prefix and retry if lookup fails
+     *
+     * @param hostname upper/lower case ok
      * @param options If non-null and contains the key "list", lookup in
      *                that list only, otherwise all lists
      */
     @Override
     public Destination lookup(String hostname, Properties lookupOptions, Properties storedOptions) {
+        Destination rv = lookup2(hostname, lookupOptions, storedOptions);
+        if (rv == null) {
+            // if hostname starts with "www.", strip and try again
+            // but not for www.i2p
+            hostname = hostname.toLowerCase(Locale.US);
+            if (hostname.startsWith("www.") && hostname.length() > 7) {
+                hostname = hostname.substring(4);
+                rv = lookup2(hostname, lookupOptions, storedOptions);
+            }
+        }
+        return rv;
+    }
+
+    /*
+     * @param options If non-null and contains the key "list", lookup in
+     *                that list only, otherwise all lists
+     */
+    private Destination lookup2(String hostname, Properties lookupOptions, Properties storedOptions) {
         String listname = null;
         if (lookupOptions != null)
             listname = lookupOptions.getProperty("list");
diff --git a/core/java/src/net/i2p/client/naming/SingleFileNamingService.java b/core/java/src/net/i2p/client/naming/SingleFileNamingService.java
index c331fae01e..219c61bbc2 100644
--- a/core/java/src/net/i2p/client/naming/SingleFileNamingService.java
+++ b/core/java/src/net/i2p/client/naming/SingleFileNamingService.java
@@ -77,6 +77,8 @@ public class SingleFileNamingService extends NamingService {
     }
 
     /** 
+     *  Will strip a "www." prefix and retry if lookup fails
+     *
      *  @param hostname case-sensitive; caller should convert to lower case
      *  @param lookupOptions ignored
      *  @param storedOptions ignored
@@ -85,6 +87,8 @@ public class SingleFileNamingService extends NamingService {
     public Destination lookup(String hostname, Properties lookupOptions, Properties storedOptions) {
         try {
             String key = getKey(hostname);
+            if (key == null && hostname.startsWith("www.") && hostname.length() > 7)
+                key = getKey(hostname.substring(4));
             if (key != null)
                 return lookupBase64(key);
         } catch (Exception ioe) {
-- 
GitLab