[tor-commits] [onionoo/master] Add support to search for nickname substrings.

karsten at torproject.org karsten at torproject.org
Thu Apr 11 08:05:04 UTC 2013


commit c5e23ddc3e30c44364813388938bc511f89bfdcf
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Thu Apr 11 10:04:36 2013 +0200

    Add support to search for nickname substrings.
    
    Implements #8678.
---
 src/org/torproject/onionoo/ResourceServlet.java |   24 +++++++++++-----------
 web/index.html                                  |    8 ++++--
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/org/torproject/onionoo/ResourceServlet.java b/src/org/torproject/onionoo/ResourceServlet.java
index 03e129b..5854cb7 100644
--- a/src/org/torproject/onionoo/ResourceServlet.java
+++ b/src/org/torproject/onionoo/ResourceServlet.java
@@ -624,6 +624,11 @@ public class ResourceServlet extends HttpServlet {
     for (Map.Entry<String, String> e : filteredRelays.entrySet()) {
       String line = e.getValue();
       boolean lineMatches = false;
+      String nickname = "unnamed";
+      if (line.contains("\"n\":\"")) {
+        nickname = line.substring(line.indexOf("\"n\":\"") + 5).
+            split("\"")[0].toLowerCase();
+      }
       if (searchTerm.startsWith("$")) {
         /* Search is for $-prefixed fingerprint. */
         if (line.contains("\"f\":\""
@@ -631,14 +636,9 @@ public class ResourceServlet extends HttpServlet {
           /* $-prefixed fingerprint matches. */
           lineMatches = true;
         }
-      } else if (line.toLowerCase().contains("\"n\":\""
-          + searchTerm.toLowerCase())) {
+      } else if (nickname.contains(searchTerm.toLowerCase())) {
         /* Nickname matches. */
         lineMatches = true;
-      } else if ("unnamed".startsWith(searchTerm.toLowerCase()) &&
-          line.startsWith("{\"f\":")) {
-        /* Nickname "Unnamed" matches. */
-        lineMatches = true;
       } else if (line.contains("\"f\":\"" + searchTerm.toUpperCase())) {
         /* Non-$-prefixed fingerprint matches. */
         lineMatches = true;
@@ -658,6 +658,11 @@ public class ResourceServlet extends HttpServlet {
     for (Map.Entry<String, String> e : filteredBridges.entrySet()) {
       String line = e.getValue();
       boolean lineMatches = false;
+      String nickname = "unnamed";
+      if (line.contains("\"n\":\"")) {
+        nickname = line.substring(line.indexOf("\"n\":\"") + 5).
+            split("\"")[0].toLowerCase();
+      }
       if (searchTerm.startsWith("$")) {
         /* Search is for $-prefixed hashed fingerprint. */
         if (line.contains("\"h\":\""
@@ -665,14 +670,9 @@ public class ResourceServlet extends HttpServlet {
           /* $-prefixed hashed fingerprint matches. */
           lineMatches = true;
         }
-      } else if (line.toLowerCase().contains("\"n\":\""
-          + searchTerm.toLowerCase())) {
+      } else if (nickname.contains(searchTerm.toLowerCase())) {
         /* Nickname matches. */
         lineMatches = true;
-      } else if ("unnamed".startsWith(searchTerm.toLowerCase()) &&
-          line.startsWith("{\"h\":")) {
-        /* Nickname "Unnamed" matches. */
-        lineMatches = true;
       } else if (line.contains("\"h\":\"" + searchTerm.toUpperCase())) {
         /* Non-$-prefixed hashed fingerprint matches. */
         lineMatches = true;
diff --git a/web/index.html b/web/index.html
index 9651160..cdd3f32 100755
--- a/web/index.html
+++ b/web/index.html
@@ -635,15 +635,17 @@ parameter value is considered.
 <b>false</b>).
 </td></tr>
 <tr><td><b>search</b></td><td>Return only relays with the parameter value
-matching the beginning of a nickname, (possibly $-prefixed) beginning of a
-fingerprint, or beginning of an IP address, and bridges with the beginning
-of a nickname or (possibly $-prefixed) beginning of a hashed fingerprint.
+matching (part of a) nickname, (possibly $-prefixed) beginning of a
+fingerprint, or beginning of an IP address, and bridges with (part of a)
+nickname or (possibly $-prefixed) beginning of a hashed fingerprint.
 Searches are case-insensitive.
 If multiple search terms are given, separated by spaces, the intersection
 of all relays and bridges matching all search terms will be returned.
 Full fingerprints should always be hashed using SHA-1, regardless of
 searching for a relay or a bridge, in order to not accidentally leak
 non-hashed bridge fingerprints in the URL.
+<font color="blue">Added support to search for nickname substrings on
+April 11.</font>
 </td></tr>
 <tr><td><b>lookup</b></td><td>Return only the relay with the parameter
 value matching the fingerprint or the bridge with the parameter value



More information about the tor-commits mailing list