[or-cvs] [metrics-web/master 5/5] Display relay search results ordered by fingerprint.

karsten at torproject.org karsten at torproject.org
Fri Dec 10 10:45:49 UTC 2010


Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Fri, 10 Dec 2010 10:41:54 +0100
Subject: Display relay search results ordered by fingerprint.
Commit: 13bf2531b087844058f7b43447a3060bc49a6442

---
 .../torproject/ernie/web/RelaySearchServlet.java   |   65 ++++++++++----------
 1 files changed, 32 insertions(+), 33 deletions(-)

diff --git a/src/org/torproject/ernie/web/RelaySearchServlet.java b/src/org/torproject/ernie/web/RelaySearchServlet.java
index 01efc2e..6e056f5 100644
--- a/src/org/torproject/ernie/web/RelaySearchServlet.java
+++ b/src/org/torproject/ernie/web/RelaySearchServlet.java
@@ -336,9 +336,9 @@ public class RelaySearchServlet extends HttpServlet {
       addAnd = true;
     }
     StringBuilder queryBuilder = new StringBuilder();
-    queryBuilder.append("SELECT validafter, descriptor, rawdesc "
-        + "FROM statusentry WHERE validafter IN (SELECT validafter "
-        + "FROM statusentry WHERE ");
+    queryBuilder.append("SELECT validafter, fingerprint, descriptor, "
+        + "rawdesc FROM statusentry WHERE validafter IN (SELECT "
+        + "validafter FROM statusentry WHERE ");
     queryBuilder.append(conditionBuilder.toString());
     if (searchDayTimestamps.size() > 0 ||
         searchMonthTimestamps.size() > 0) {
@@ -370,7 +370,6 @@ public class RelaySearchServlet extends HttpServlet {
     }
     queryBuilder.append("ORDER BY validafter DESC LIMIT 31) AND ");
     queryBuilder.append(conditionBuilder.toString());
-    queryBuilder.append("ORDER BY validafter DESC, fingerprint");
     String query = queryBuilder.toString();
     request.setAttribute("query", query);
 
@@ -391,46 +390,46 @@ public class RelaySearchServlet extends HttpServlet {
         matches++;
         String validAfter = rs.getTimestamp(1).toString().
             substring(0, 19);
-        String descriptor = rs.getString(2);
+        String fingerprint = rs.getString(2);
+        String descriptor = rs.getString(3);
         if (!foundDescriptors.containsKey(validAfter)) {
           foundDescriptors.put(validAfter, new TreeSet<String>());
         }
-        foundDescriptors.get(validAfter).add(descriptor);
+        foundDescriptors.get(validAfter).add(validAfter + " "
+            + fingerprint);
         if (!rawValidAfterLines.containsKey(validAfter)) {
           rawValidAfterLines.put(validAfter, "<tt>valid-after "
               + "<a href=\"consensus?valid-after="
               + validAfter.replaceAll(":", "-").replaceAll(" ", "-")
               + "\" target=\"_blank\">" + validAfter + "</a></tt><br>");
         }
-        if (!rawStatusEntries.containsKey(descriptor)) {
-          byte[] rawStatusEntry = rs.getBytes(3);
-          String statusEntryLines = null;
-          try {
-            statusEntryLines = new String(rawStatusEntry, "US-ASCII");
-          } catch (UnsupportedEncodingException e) {
-            /* This shouldn't happen, because we know that ASCII is
-             * supported. */
-          }
-          StringBuilder rawStatusEntryBuilder = new StringBuilder();
-          String[] lines = statusEntryLines.split("\n");
-          for (String line : lines) {
-            if (line.startsWith("r ")) {
-              String[] parts = line.split(" ");
-              String descriptorBase64 = String.format("%040x",
-                  new BigInteger(1, Base64.decodeBase64(parts[3]
-                  + "==")));
-              rawStatusEntryBuilder.append("<tt>r " + parts[1] + " "
-                  + parts[2] + " <a href=\"descriptor.html?desc-id="
-                  + descriptorBase64 + "\" target=\"_blank\">" + parts[3]
-                  + "</a> " + parts[4] + " " + parts[5] + " " + parts[6]
-                  + " " + parts[7] + " " + parts[8] + "</tt><br>");
-            } else {
-              rawStatusEntryBuilder.append("<tt>" + line + "</tt><br>");
-            }
-            rawStatusEntries.put(descriptor,
-                rawStatusEntryBuilder.toString());
+        byte[] rawStatusEntry = rs.getBytes(4);
+        String statusEntryLines = null;
+        try {
+          statusEntryLines = new String(rawStatusEntry, "US-ASCII");
+        } catch (UnsupportedEncodingException e) {
+          /* This shouldn't happen, because we know that ASCII is
+           * supported. */
+        }
+        StringBuilder rawStatusEntryBuilder = new StringBuilder();
+        String[] lines = statusEntryLines.split("\n");
+        for (String line : lines) {
+          if (line.startsWith("r ")) {
+            String[] parts = line.split(" ");
+            String descriptorBase64 = String.format("%040x",
+                new BigInteger(1, Base64.decodeBase64(parts[3]
+                + "==")));
+            rawStatusEntryBuilder.append("<tt>r " + parts[1] + " "
+                + parts[2] + " <a href=\"descriptor.html?desc-id="
+                + descriptorBase64 + "\" target=\"_blank\">" + parts[3]
+                + "</a> " + parts[4] + " " + parts[5] + " " + parts[6]
+                + " " + parts[7] + " " + parts[8] + "</tt><br>");
+          } else {
+            rawStatusEntryBuilder.append("<tt>" + line + "</tt><br>");
           }
         }
+        rawStatusEntries.put(validAfter + " " + fingerprint,
+              rawStatusEntryBuilder.toString());
       }
       rs.close();
       statement.close();
-- 
1.7.1



More information about the tor-commits mailing list