commit bd5b45a79cc71410c66b776c44d52f7f2e84a117
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Sat Nov 18 17:32:27 2017 +0100
Add "version" field to details documents.
Add a "version" field to relay details documents with the Tor software
version listed in the consensus and similarly to bridge details
documents with the Tor software version found in the server
descriptor.
Implements #22488.
---
CHANGELOG.md | 9 +++++++++
.../org/torproject/onionoo/docs/DetailsDocument.java | 10 ++++++++++
.../org/torproject/onionoo/docs/DetailsStatus.java | 10 ++++++++++
.../java/org/torproject/onionoo/docs/NodeStatus.java | 3 +--
.../torproject/onionoo/server/ResponseBuilder.java | 2 ++
.../onionoo/updater/NodeDetailsStatusUpdater.java | 19 ++++++++++++++++++-
.../onionoo/writer/DetailsDocumentWriter.java | 2 ++
7 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index eef02a8..3adcdd4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,12 @@
+# Changes in version 4.4-1.8.0 - 2017-??-??
+
+ * Medium changes
+ - Add a "version" field to relay details documents with the Tor
+ software version listed in the consensus and similarly to bridge
+ details documents with the Tor software version found in the
+ server descriptor.
+
+
# Changes in version 4.3-1.7.1 - 2017-11-17
* Minor changes
diff --git a/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java b/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java
index bde3cae..911a978 100644
--- a/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java
+++ b/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java
@@ -346,6 +346,16 @@ public class DetailsDocument extends Document {
return unescapeJson(this.platform);
}
+ private String version;
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getVersion() {
+ return this.version;
+ }
+
private SortedSet<String> alleged_family;
public void setAllegedFamily(SortedSet<String> allegedFamily) {
diff --git a/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java b/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java
index 77ff75f..9ed8658 100644
--- a/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java
+++ b/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java
@@ -540,5 +540,15 @@ public class DetailsStatus extends Document {
public List<String> getAdvertisedOrAddresses() {
return this.advertised_or_addresses;
}
+
+ private String version;
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getVersion() {
+ return this.version;
+ }
}
diff --git a/src/main/java/org/torproject/onionoo/docs/NodeStatus.java b/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
index 3271ccc..7a8510e 100644
--- a/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
+++ b/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
@@ -324,8 +324,7 @@ public class NodeStatus extends Document {
private String version;
public void setVersion(String version) {
- this.version = null == version ? null
- : version.substring(version.lastIndexOf(" ") + 1);
+ this.version = version;
}
public String getVersion() {
diff --git a/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java b/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java
index 58b66ce..a83234b 100644
--- a/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java
+++ b/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java
@@ -342,6 +342,8 @@ public class ResponseBuilder {
} else if (field.equals("unreachable_or_addresses")) {
dd.setUnreachableOrAddresses(
detailsDocument.getUnreachableOrAddresses());
+ } else if (field.equals("version")) {
+ dd.setVersion(detailsDocument.getVersion());
}
}
/* Don't escape HTML characters, like < and >, contained in
diff --git a/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java b/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
index fa3f3af..7792764 100644
--- a/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
+++ b/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
@@ -291,7 +291,12 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
nodeStatus.setRecommendedVersion((recommendedVersions == null
|| entry.getVersion() == null) ? null :
recommendedVersions.contains(entry.getVersion()));
- nodeStatus.setVersion(entry.getVersion());
+ String version = null;
+ if (null != entry.getVersion()
+ && entry.getVersion().startsWith("Tor ")) {
+ version = entry.getVersion().split(" ")[1];
+ }
+ nodeStatus.setVersion(version);
}
if (entry.getUnmeasured()) {
if (!this.lastSeenUnmeasured.containsKey(fingerprint)
@@ -784,6 +789,17 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
nodeStatus.setContact(detailsStatus.getContact());
+ /* Extract tor software version for bridges from their "platform" line.
+ * (We already know this for relays from "v" lines in the consensus.) */
+ if (!nodeStatus.isRelay()) {
+ String version = null;
+ if (null != detailsStatus.getPlatform()
+ && detailsStatus.getPlatform().startsWith("Tor ")) {
+ version = detailsStatus.getPlatform().split(" ")[1];
+ }
+ nodeStatus.setVersion(version);
+ }
+
Map<String, Long> exitAddresses = new HashMap<>();
if (detailsStatus.getExitAddresses() != null) {
for (Map.Entry<String, Long> e :
@@ -890,6 +906,7 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
nodeStatus.getRecommendedVersion());
detailsStatus.setLastChangedOrAddressOrPort(
nodeStatus.getLastChangedOrAddressOrPort());
+ detailsStatus.setVersion(nodeStatus.getVersion());
this.documentStore.store(detailsStatus, fingerprint);
this.documentStore.store(nodeStatus, fingerprint);
diff --git a/src/main/java/org/torproject/onionoo/writer/DetailsDocumentWriter.java b/src/main/java/org/torproject/onionoo/writer/DetailsDocumentWriter.java
index 9538cba..5eaa950 100644
--- a/src/main/java/org/torproject/onionoo/writer/DetailsDocumentWriter.java
+++ b/src/main/java/org/torproject/onionoo/writer/DetailsDocumentWriter.java
@@ -165,6 +165,7 @@ public class DetailsDocumentWriter implements DocumentWriter {
if (!unreachableOrAddresses.isEmpty()) {
detailsDocument.setUnreachableOrAddresses(unreachableOrAddresses);
}
+ detailsDocument.setVersion(detailsStatus.getVersion());
this.documentStore.store(detailsDocument, fingerprint);
}
@@ -193,6 +194,7 @@ public class DetailsDocumentWriter implements DocumentWriter {
detailsStatus.getAdvertisedBandwidth());
detailsDocument.setPlatform(detailsStatus.getPlatform());
detailsDocument.setTransports(detailsStatus.getTransports());
+ detailsDocument.setVersion(detailsStatus.getVersion());
this.documentStore.store(detailsDocument, fingerprint);
}