[tor-commits] [onionoo/master] Include bridge nicknames in documents.

karsten at torproject.org karsten at torproject.org
Thu Jun 14 11:37:45 UTC 2012


commit 3f73fb13b9dbdd23f77e7274965aa2f6eea71d06
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Thu Jun 14 12:53:27 2012 +0200

    Include bridge nicknames in documents.
---
 src/org/torproject/onionoo/CurrentNodes.java      |   19 +++++++++++--------
 src/org/torproject/onionoo/DetailDataWriter.java  |    2 ++
 src/org/torproject/onionoo/ResourceServlet.java   |    2 +-
 src/org/torproject/onionoo/SummaryDataWriter.java |    3 +++
 web/index.html                                    |   11 +++++++++--
 5 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/src/org/torproject/onionoo/CurrentNodes.java b/src/org/torproject/onionoo/CurrentNodes.java
index 5732cb9..c2a91ec 100644
--- a/src/org/torproject/onionoo/CurrentNodes.java
+++ b/src/org/torproject/onionoo/CurrentNodes.java
@@ -82,6 +82,7 @@ public class CurrentNodes {
                   + " is invalid.  Exiting.");
               System.exit(1);
             }
+            String nickname = parts[1];
             String hashedFingerprint = parts[2];
             String address = parts[3];
             long publishedMillis = dateTimeFormat.parse(parts[4] + " "
@@ -90,8 +91,8 @@ public class CurrentNodes {
             int dirPort = Integer.parseInt(parts[7]);
             SortedSet<String> relayFlags = new TreeSet<String>(
                 Arrays.asList(parts[8].split(",")));
-            this.addBridge(hashedFingerprint, address, publishedMillis,
-                orPort, dirPort, relayFlags);
+            this.addBridge(nickname, hashedFingerprint, address,
+                publishedMillis, orPort, dirPort, relayFlags);
           }
         }
         br.close();
@@ -140,6 +141,7 @@ public class CurrentNodes {
             + " " + consensusWeight + "\n");
       }
       for (Node entry : this.currentBridges.values()) {
+        String nickname = entry.getNickname();
         String fingerprint = entry.getFingerprint();
         String published = dateTimeFormat.format(
             entry.getLastSeenMillis());
@@ -151,7 +153,7 @@ public class CurrentNodes {
           sb.append("," + relayFlag);
         }
         String relayFlags = sb.toString().substring(1);
-        bw.write("b Unnamed " + fingerprint + " " + address + " "
+        bw.write("b " + nickname + " " + fingerprint + " " + address + " "
             + published + " " + orPort + " " + dirPort + " " + relayFlags
             + " -1\n");
       }
@@ -312,24 +314,25 @@ public class CurrentNodes {
   private void updateBridgeNetworkStatus(BridgeNetworkStatus status) {
     long publishedMillis = status.getPublishedMillis();
     for (NetworkStatusEntry entry : status.getStatusEntries().values()) {
+      String nickname = entry.getNickname();
       String fingerprint = entry.getFingerprint();
       String address = entry.getAddress();
       int orPort = entry.getOrPort();
       int dirPort = entry.getDirPort();
       SortedSet<String> relayFlags = entry.getFlags();
-      this.addBridge(fingerprint, address, publishedMillis, orPort,
-         dirPort, relayFlags);
+      this.addBridge(nickname, fingerprint, address, publishedMillis,
+          orPort, dirPort, relayFlags);
     }
   }
 
-  public void addBridge(String fingerprint, String address,
-      long publishedMillis, int orPort, int dirPort,
+  public void addBridge(String nickname, String fingerprint,
+      String address, long publishedMillis, int orPort, int dirPort,
       SortedSet<String> relayFlags) {
     if (publishedMillis >= cutoff &&
         (!this.currentBridges.containsKey(fingerprint) ||
         this.currentBridges.get(fingerprint).getLastSeenMillis() <
         publishedMillis)) {
-      Node entry = new Node("Unnamed", fingerprint, address,
+      Node entry = new Node(nickname, fingerprint, address,
           publishedMillis, orPort, dirPort, relayFlags, -1L);
       this.currentBridges.put(fingerprint, entry);
       if (publishedMillis > this.lastPublishedMillis) {
diff --git a/src/org/torproject/onionoo/DetailDataWriter.java b/src/org/torproject/onionoo/DetailDataWriter.java
index cfae5ff..1e3be72 100644
--- a/src/org/torproject/onionoo/DetailDataWriter.java
+++ b/src/org/torproject/onionoo/DetailDataWriter.java
@@ -543,11 +543,13 @@ public class DetailDataWriter {
 
       /* Generate network-status-specific part. */
       Node entry = bridge.getValue();
+      String nickname = entry.getNickname();
       String running = entry.getRunning() ? "true" : "false";
       String address = entry.getAddress();
       int orPort = entry.getOrPort();
       StringBuilder sb = new StringBuilder();
       sb.append("{\"version\":1,\n"
+          + "\"nickname\":\"" + nickname + "\",\n"
           + "\"hashed_fingerprint\":\"" + fingerprint + "\",\n"
           + "\"or_addresses\":[\"" + address + ":" + orPort + "\"],\n"
           + "\"running\":" + running + ",");
diff --git a/src/org/torproject/onionoo/ResourceServlet.java b/src/org/torproject/onionoo/ResourceServlet.java
index a85f3ec..e4f5b9f 100644
--- a/src/org/torproject/onionoo/ResourceServlet.java
+++ b/src/org/torproject/onionoo/ResourceServlet.java
@@ -475,7 +475,7 @@ public class ResourceServlet extends HttpServlet {
         /* Nickname matches. */
         lineMatches = true;
       } else if ("unnamed".startsWith(searchTerm.toLowerCase()) &&
-          line.startsWith("{\"f\":")) {
+          (line.startsWith("{\"f\":") || line.startsWith("{\"h\":"))) {
         /* Nickname "Unnamed" matches. */
         lineMatches = true;
       } else if (line.contains("\"f\":\"" + searchTerm.toUpperCase())) {
diff --git a/src/org/torproject/onionoo/SummaryDataWriter.java b/src/org/torproject/onionoo/SummaryDataWriter.java
index c438692..1391c02 100644
--- a/src/org/torproject/onionoo/SummaryDataWriter.java
+++ b/src/org/torproject/onionoo/SummaryDataWriter.java
@@ -68,12 +68,15 @@ public class SummaryDataWriter {
           + "\",\n\"bridges\":[");
       written = 0;
       for (Node entry : this.currentBridges.values()) {
+        String nickname = !entry.getNickname().equals("Unnamed") ?
+            entry.getNickname() : null;
         String hashedFingerprint = entry.getFingerprint();
         String running = entry.getRunning() ? "true" : "false";
         if (written++ > 0) {
           bw.write(",");
         }
         bw.write("\n{"
+            + (nickname == null ? "" : "\"n\":\"" + nickname + "\",")
             + "\"h\":\"" + hashedFingerprint + "\","
             + "\"r\":" + running + "}");
       }
diff --git a/web/index.html b/web/index.html
index 93c798e..1539705 100755
--- a/web/index.html
+++ b/web/index.html
@@ -276,6 +276,11 @@ Required field.</li>
 Required field.
 Each array object contains the following key-value pairs:
 <ul>
+<li><b>"nickname":</b> Bridge nickname consisting of 1–19
+alphanumerical characters.
+Optional field.
+Omitted if the bridge nickname is <i>"Unnamed"</i>.
+<font color="blue">Added field on June 14, 2012.</font></li>
 <li><b>"hashed_fingerprint":</b> SHA-1 hash of the bridge fingerprint
 consisting of 40 upper-case hexadecimal characters.
 Required field.</li>
@@ -603,13 +608,15 @@ of relay and/or bridge documents to be included in the response.</p>
 </td></tr>
 <tr><td><b>search</b></td><td>Return only relays with the parameter value
 matching the beginning of a nickname, (possibly $-prefixed) fingerprint,
-or IP address, and bridges with the (possibly $-prefixed) hashed
-fingerprint.
+or IP address, and bridges with the nickname or (possibly $-prefixed)
+hashed fingerprint.
 Searches are case-insensitive.
 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">Parameter added on May 14, 2012.</font>
+<font color="blue">Extended search to bridge nicknames on June 14,
+2012.</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