[tor-commits] [onionoo/master] Extend "version" parameter to bridges.
karsten at torproject.org
karsten at torproject.org
Mon Nov 27 09:20:58 UTC 2017
commit 919d5ff967ecaa401b8a0a91885fbe7b84c9807c
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Sat Nov 18 17:35:30 2017 +0100
Extend "version" parameter to bridges.
Extend the "version" parameter to also return bridges with the given
version or version prefix.
Implements #23962.
---
CHANGELOG.md | 2 ++
.../org/torproject/onionoo/server/NodeIndex.java | 10 ++++++++
.../org/torproject/onionoo/server/NodeIndexer.java | 10 ++++++++
.../torproject/onionoo/server/RequestHandler.java | 9 ++++++-
.../onionoo/server/ResourceServletTest.java | 29 +++++++++++++---------
5 files changed, 47 insertions(+), 13 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3adcdd4..918a1ae 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,8 @@
software version listed in the consensus and similarly to bridge
details documents with the Tor software version found in the
server descriptor.
+ - Extend the "version" parameter to also return bridges with the
+ given version or version prefix.
# Changes in version 4.3-1.7.1 - 2017-11-17
diff --git a/src/main/java/org/torproject/onionoo/server/NodeIndex.java b/src/main/java/org/torproject/onionoo/server/NodeIndex.java
index 126cd5c..c41dd7a 100644
--- a/src/main/java/org/torproject/onionoo/server/NodeIndex.java
+++ b/src/main/java/org/torproject/onionoo/server/NodeIndex.java
@@ -180,6 +180,16 @@ class NodeIndex {
return this.relaysByVersion;
}
+ private Map<String, Set<String>> bridgesByVersion;
+
+ public void setBridgesByVersion(Map<String, Set<String>> bridgesByVersion) {
+ this.bridgesByVersion = bridgesByVersion;
+ }
+
+ public Map<String, Set<String>> getBridgesByVersion() {
+ return this.bridgesByVersion;
+ }
+
private Map<String, Set<String>> relaysByHostName;
public void setRelaysByHostName(Map<String, Set<String>> relaysByHostName) {
diff --git a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
index d609f63..585d33f 100644
--- a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
+++ b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
@@ -154,6 +154,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
Map<String, Set<String>> newRelaysByContact = new HashMap<>();
Map<String, Set<String>> newRelaysByFamily = new HashMap<>();
Map<String, Set<String>> newRelaysByVersion = new HashMap<>();
+ Map<String, Set<String>> newBridgesByVersion = new HashMap<>();
Map<String, Set<String>> newRelaysByHostName = new HashMap<>();
SortedMap<Integer, Set<String>> newRelaysByFirstSeenDays = new TreeMap<>();
SortedMap<Integer, Set<String>> newBridgesByFirstSeenDays = new TreeMap<>();
@@ -323,6 +324,14 @@ public class NodeIndexer implements ServletContextListener, Runnable {
hashedFingerprint);
newBridgesByLastSeenDays.get(daysSinceLastSeen).add(
hashedHashedFingerprint);
+ String version = entry.getVersion();
+ if (null != version) {
+ if (!newBridgesByVersion.containsKey(version)) {
+ newBridgesByVersion.put(version, new HashSet<>());
+ }
+ newBridgesByVersion.get(version).add(hashedFingerprint);
+ newBridgesByVersion.get(version).add(hashedHashedFingerprint);
+ }
}
NodeIndex newNodeIndex = new NodeIndex();
newNodeIndex.setRelayFingerprintSummaryLines(
@@ -342,6 +351,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
newNodeIndex.setRelaysPublishedMillis(relaysLastValidAfterMillis);
newNodeIndex.setBridgesPublishedMillis(bridgesLastPublishedMillis);
newNodeIndex.setRelaysByVersion(newRelaysByVersion);
+ newNodeIndex.setBridgesByVersion(newBridgesByVersion);
newNodeIndex.setRelaysByHostName(newRelaysByHostName);
synchronized (this) {
this.lastIndexed = updateStatusMillis;
diff --git a/src/main/java/org/torproject/onionoo/server/RequestHandler.java b/src/main/java/org/torproject/onionoo/server/RequestHandler.java
index 23af60b..067a738 100644
--- a/src/main/java/org/torproject/onionoo/server/RequestHandler.java
+++ b/src/main/java/org/torproject/onionoo/server/RequestHandler.java
@@ -541,7 +541,14 @@ public class RequestHandler {
}
}
this.filteredRelays.keySet().retainAll(keepRelays);
- this.filteredBridges.clear();
+ Set<String> keepBridges = new HashSet<>();
+ for (Map.Entry<String, Set<String>> e
+ : this.nodeIndex.getBridgesByVersion().entrySet()) {
+ if (e.getKey().startsWith(this.version)) {
+ keepBridges.addAll(e.getValue());
+ }
+ }
+ this.filteredBridges.keySet().retainAll(keepBridges);
}
private void filterByHostName() {
diff --git a/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java b/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
index 2720f7a..d763988 100644
--- a/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
+++ b/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
@@ -129,6 +129,7 @@ public class ResourceServletTest {
@SuppressWarnings("JavadocMethod")
@Before
public void createSampleRelaysAndBridges() {
+ this.relays = new TreeMap<>();
org.torproject.onionoo.docs.SummaryDocument relayTorkaZ =
new org.torproject.onionoo.docs.SummaryDocument(true, "TorkaZ",
"000C5F55BD4814B917CC474BD537F1A3B33CCE2A", Arrays.asList(
@@ -144,6 +145,8 @@ public class ResourceServletTest {
new TreeSet<>(Arrays.asList(
new String[] { "001C13B3A55A71B977CA65EC85539D79C653A3FC" })),
"0.2.3.25", "ppp-62-216-201-221.dynamic.mnet-online.de");
+ this.relays.put("000C5F55BD4814B917CC474BD537F1A3B33CCE2A",
+ relayTorkaZ);
org.torproject.onionoo.docs.SummaryDocument relayFerrari458 =
new org.torproject.onionoo.docs.SummaryDocument(true, "Ferrari458",
"001C13B3A55A71B977CA65EC85539D79C653A3FC", Arrays.asList(
@@ -157,9 +160,6 @@ public class ResourceServletTest {
new TreeSet<>(Arrays.asList(new String[] {
"000C5F55BD4814B917CC474BD537F1A3B33CCE2A" })), null,
"c-68-38-171-200.hsd1.in.comcast.net");
- this.relays = new TreeMap<>();
- this.relays.put("000C5F55BD4814B917CC474BD537F1A3B33CCE2A",
- relayTorkaZ);
this.relays.put("001C13B3A55A71B977CA65EC85539D79C653A3FC",
relayFerrari458);
org.torproject.onionoo.docs.SummaryDocument relayTimMayTribute =
@@ -172,7 +172,7 @@ public class ResourceServletTest {
DateTimeHelper.parse("2013-04-16 18:00:00"), "AS6830",
"1024d/51e2a1c7 \"steven j. murdoch\" "
+ "<tor+steven.murdoch at cl.cam.ac.uk> <fb-token:5sr_k_zs2wm=>",
- new TreeSet<String>(), new TreeSet<String>(), "0.2.3.25", null);
+ new TreeSet<String>(), new TreeSet<String>(), "0.2.3.24-rc-dev", null);
this.relays.put("0025C136C1F3A9EEFE2AE3F918F03BFA21B5070B",
relayTimMayTribute);
this.bridges = new TreeMap<>();
@@ -183,7 +183,7 @@ public class ResourceServletTest {
DateTimeHelper.parse("2013-04-21 18:07:03"), false,
new TreeSet<>(Arrays.asList(new String[] { "Valid" })), -1L,
null, DateTimeHelper.parse("2013-04-20 15:37:04"), null, null,
- null, null, null, null);
+ null, null, "0.2.2.39", null);
this.bridges.put("0000831B236DFF73D409AD17B40E2A728A53994F",
bridgeec2bridgercc7f31fe);
org.torproject.onionoo.docs.SummaryDocument bridgeUnnamed =
@@ -204,7 +204,7 @@ public class ResourceServletTest {
new TreeSet<>(Arrays.asList(new String[] { "Running",
"Valid" })), -1L, null,
DateTimeHelper.parse("2013-01-16 21:07:04"), null, null, null,
- null, null, null);
+ null, "0.2.4.4-alpha-dev", null);
this.bridges.put("1FEDE50ED8DBA1DD9F9165F78C8131E4A44AB756",
bridgegummy);
}
@@ -1571,14 +1571,19 @@ public class ResourceServletTest {
@Test
public void testVersion02325() {
- this.assertSummaryDocument("/summary?version=0.2.3.25", 2,
- new String[] { "TorkaZ", "TimMayTribute" }, 0, null);
+ this.assertSummaryDocument("/summary?version=0.2.3.25", 1,
+ new String[] { "TorkaZ" }, 0, null);
}
@Test
public void testVersion02324() {
- this.assertSummaryDocument("/summary?version=0.2.3.24-rc-dev", 0,
- new String[] { "Ferrari458" }, 0, null);
+ this.assertSummaryDocument("/summary?version=0.2.3.24-rc-dev", 1,
+ new String[] { "TimMayTribute" }, 0, null);
+ }
+
+ @Test
+ public void testVersion02326() {
+ this.assertSummaryDocument("/summary?version=0.2.3.26", 0, null, 0, null);
}
@Test
@@ -1594,12 +1599,12 @@ public class ResourceServletTest {
@Test
public void testVersion0() {
- this.assertSummaryDocument("/summary?version=0", 2, null, 0, null);
+ this.assertSummaryDocument("/summary?version=0", 2, null, 2, null);
}
@Test
public void testVersion02() {
- this.assertSummaryDocument("/summary?version=0.2", 2, null, 0, null);
+ this.assertSummaryDocument("/summary?version=0.2", 2, null, 2, null);
}
@Test
More information about the tor-commits
mailing list