commit 4316492e187a1f36ddc5eec2a377ab1674ad9d38
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Mon Nov 7 15:24:15 2011 +0100
Require $ prefix for fingerprints on relay-search.html.
Implements #4314 which suggests accepting fingerprints with the $ prefix,
but also requires the $ prefix for all fingerprints in order to
distinguish them from nicknames. Before this change we had to treat some
search parameters as "fingerprint or nickname" which complicated the
database query string a lot.
---
.../torproject/ernie/web/RelaySearchServlet.java | 66 ++++---------------
web/WEB-INF/relay-search.jsp | 9 ++-
2 files changed, 19 insertions(+), 56 deletions(-)
diff --git a/src/org/torproject/ernie/web/RelaySearchServlet.java b/src/org/torproject/ernie/web/RelaySearchServlet.java
index 4cb9694..05be5e8 100644
--- a/src/org/torproject/ernie/web/RelaySearchServlet.java
+++ b/src/org/torproject/ernie/web/RelaySearchServlet.java
@@ -23,21 +23,21 @@ import org.apache.commons.codec.binary.*;
* - gabelmoo
* - gabelmoo 2010-09
* - gabelmoo 2010-09-18
- * - gabelmoo F2044413DAC2E02E3D6BCF4735A19BCA1DE97281
+ * - gabelmoo $F2044413DAC2E02E3D6BCF4735A19BCA1DE97281
* - gabelmoo 80.190.246
- * - gabelmoo F2044413DAC2E02E3D6BCF4735A19BCA1DE97281 80.190.246
+ * - gabelmoo $F2044413DAC2E02E3D6BCF4735A19BCA1DE97281 80.190.246
* - 5898549205 dc737cc9dca16af6 79.212.74.45
* - 5898549205 dc737cc9dca16af6
* - 80.190.246.100
- * - F2044413DAC2E02E3D6BCF4735A19BCA1DE97281
- * - F2044413DAC2E02E3D6BCF4735A19BCA1DE97281 80.190.246
+ * - $F2044413DAC2E02E3D6BCF4735A19BCA1DE97281
+ * - $F2044413DAC2E02E3D6BCF4735A19BCA1DE97281 80.190.246
* - 58985492
* - 58985492 79.212.74.45
*/
public class RelaySearchServlet extends HttpServlet {
- private Pattern alphaNumDotDashSpacePattern =
- Pattern.compile("[A-Za-z0-9\\.\\- ]+");
+ private Pattern alphaNumDotDashDollarSpacePattern =
+ Pattern.compile("[A-Za-z0-9\\.\\-$ ]+");
private Pattern numPattern = Pattern.compile("[0-9]+");
@@ -97,7 +97,6 @@ public class RelaySearchServlet extends HttpServlet {
String searchNickname = "";
String searchFingerprint = "";
String searchIPAddress = "";
- SortedSet<String> searchFingerprintOrNickname = new TreeSet<String>();
SortedSet<String> searchDays = new TreeSet<String>();
SortedSet<String> searchMonths = new TreeSet<String>();
SortedSet<Long> searchDayTimestamps = new TreeSet<Long>();
@@ -106,7 +105,8 @@ public class RelaySearchServlet extends HttpServlet {
/* Only parse search parameter if it contains nothing else than
* alphanumeric characters, dots, and spaces. */
- if (alphaNumDotDashSpacePattern.matcher(searchParameter).matches()) {
+ if (alphaNumDotDashDollarSpacePattern.matcher(searchParameter).
+ matches()) {
SortedSet<String> searchTerms = new TreeSet<String>();
if (searchParameter.trim().contains(" ")) {
String[] split = searchParameter.trim().split(" ");
@@ -177,23 +177,16 @@ public class RelaySearchServlet extends HttpServlet {
}
}
- /* If the search term contains between 8 and 19 hex characters, it
- * could be either a nickname or a fingerprint. */
- else if (searchTerm.length() >= 8 && searchTerm.length() <= 19 &&
- hexPattern.matcher(searchTerm).matches()) {
- searchFingerprintOrNickname.add(searchTerm);
- validQuery = true;
- }
-
- /* If the search term contains between 20 and 40 hex characters,
- * it must be a fingerprint. */
- else if (searchTerm.length() >= 20 && searchTerm.length() <= 40 &&
- hexPattern.matcher(searchTerm).matches()) {
+ /* If the search term starts with a $ followed by 8 to 40 hex
+ * characters, it must be a fingerprint. */
+ else if (searchTerm.length() >= 9 && searchTerm.length() <= 41 &&
+ searchTerm.startsWith("$") &&
+ hexPattern.matcher(searchTerm.substring(1)).matches()) {
if (searchFingerprint.length() > 0) {
validQuery = false;
break;
}
- searchFingerprint = searchTerm;
+ searchFingerprint = searchTerm.substring(1);
validQuery = true;
}
@@ -217,27 +210,6 @@ public class RelaySearchServlet extends HttpServlet {
}
}
- /* We can only accept at most two search terms for nickname and
- * fingerprint. */
- int items = searchFingerprintOrNickname.size();
- items += searchFingerprint.length() > 0 ? 1 : 0;
- items += searchNickname.length() > 0 ? 1 : 0;
- if (items > 2) {
- validQuery = false;
- }
-
- /* If we have two candidates for fingerprint or nickname and we can
- * recognize what one of them is, then we can conclude what the other
- * one must be. */
- else if (items == 2 && searchFingerprintOrNickname.size() == 1) {
- if (searchFingerprint.length() == 0) {
- searchFingerprint = searchFingerprintOrNickname.first();
- } else {
- searchNickname = searchFingerprintOrNickname.first();
- }
- searchFingerprintOrNickname.clear();
- }
-
/* We only accept at most one month or three days, but not both, or
* people could accidentally keep the database busy. */
if (searchDays.size() > 3 || searchMonths.size() > 1 ||
@@ -262,10 +234,6 @@ public class RelaySearchServlet extends HttpServlet {
recognizedSearchTerms.add("fingerprint <b>" + searchFingerprint
+ "</b>");
}
- for (String searchTerm : searchFingerprintOrNickname) {
- recognizedSearchTerms.add("nickname or fingerprint <b>" + searchTerm
- + "</b>");
- }
if (searchIPAddress.length() > 0) {
recognizedSearchTerms.add("IP address <b>" + searchIPAddress
+ "</b>");
@@ -329,12 +297,6 @@ public class RelaySearchServlet extends HttpServlet {
+ "address LIKE '" + searchIPAddress + "%' ");
addAnd = true;
}
- for (String search : searchFingerprintOrNickname) {
- conditionBuilder.append((addAnd ? "AND " : "")
- + "(LOWER(nickname) LIKE '" + search.toLowerCase()
- + "%' OR fingerprint LIKE '" + search.toLowerCase() + "%') ");
- addAnd = true;
- }
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append("SELECT validafter, fingerprint, descriptor, "
+ "rawdesc FROM statusentry WHERE validafter IN (SELECT "
diff --git a/web/WEB-INF/relay-search.jsp b/web/WEB-INF/relay-search.jsp
index 0741aca..260b7dc 100644
--- a/web/WEB-INF/relay-search.jsp
+++ b/web/WEB-INF/relay-search.jsp
@@ -34,10 +34,10 @@
<c:if test="${not empty invalidQuery}">
<p>Sorry, I didn't understand your query. Please provide a
nickname (e.g., "gabelmoo"), at least the first 8 hex characters
- of a fingerprint (e.g., "F2044413"), or at least the first two
- octets of an IPv4 address in dotted-decimal notation (e.g.,
- "80.190"). You can also provide at most three months or days in
- ISO 8601 format (e.g., "2010-09" or "2010-09-17").</p>
+ of a fingerprint prefixed by $ (e.g., "$F2044413"), or at least
+ the first two octets of an IPv4 address in dotted-decimal notation
+ (e.g., "80.190"). You can also provide at most three months or
+ days in ISO 8601 format (e.g., "2010-09" or "2010-09-17").</p>
</c:if>
<c:if test="${not empty searchNotice}">
<p>${searchNotice}</p>
@@ -79,3 +79,4 @@
</div>
</body>
</html>
+