[tor-commits] [onionoo/master] Add "recommended_version" field to bridge details documents.

karsten at torproject.org karsten at torproject.org
Mon Nov 27 09:20:58 UTC 2017


commit edc796cd890fdc656947dd11c6832a5d99ee0ae6
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Sat Nov 18 17:37:46 2017 +0100

    Add "recommended_version" field to bridge details documents.
    
    Add a "recommended_version" field to bridge details documents based on
    whether the directory authorities recommend the bridge's version.
    
    Implements #21827.
---
 CHANGELOG.md                                       |  3 +++
 .../onionoo/updater/NodeDetailsStatusUpdater.java  | 24 ++++++++++++----------
 .../onionoo/writer/DetailsDocumentWriter.java      |  2 ++
 3 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 918a1ae..5a84259 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,9 @@
      server descriptor.
    - Extend the "version" parameter to also return bridges with the
      given version or version prefix.
+   - Add a "recommended_version" field to bridge details documents
+     based on whether the directory authorities recommend the bridge's
+     version.
 
 
 # Changes in version 4.3-1.7.1 - 2017-11-17
diff --git a/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java b/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
index 7792764..0a5a93d 100644
--- a/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
+++ b/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
@@ -89,6 +89,8 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
 
   private SortedMap<String, Integer> lastBandwidthWeights = null;
 
+  private Set<String> lastRecommendedServerVersions = null;
+
   private int relayConsensusesProcessed = 0;
 
   private int bridgeStatusesProcessed = 0;
@@ -248,14 +250,6 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
     if (validAfterMillis > this.relaysLastValidAfterMillis) {
       this.relaysLastValidAfterMillis = validAfterMillis;
     }
-    Set<String> recommendedVersions = null;
-    if (consensus.getRecommendedServerVersions() != null) {
-      recommendedVersions = new HashSet<>();
-      for (String recommendedVersion :
-          consensus.getRecommendedServerVersions()) {
-        recommendedVersions.add("Tor " + recommendedVersion);
-      }
-    }
     for (Map.Entry<String, NetworkStatusEntry> e :
         consensus.getStatusEntries().entrySet()) {
       String fingerprint = e.getKey();
@@ -288,9 +282,6 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
         nodeStatus.setConsensusWeight(entry.getBandwidth());
         nodeStatus.setDefaultPolicy(entry.getDefaultPolicy());
         nodeStatus.setPortList(entry.getPortList());
-        nodeStatus.setRecommendedVersion((recommendedVersions == null
-            || entry.getVersion() == null) ? null :
-            recommendedVersions.contains(entry.getVersion()));
         String version = null;
         if (null != entry.getVersion()
             && entry.getVersion().startsWith("Tor ")) {
@@ -315,6 +306,8 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
     this.relayConsensusesProcessed++;
     if (this.relaysLastValidAfterMillis == validAfterMillis) {
       this.lastBandwidthWeights = consensus.getBandwidthWeights();
+      this.lastRecommendedServerVersions
+          = new HashSet<>(consensus.getRecommendedServerVersions());
     }
   }
 
@@ -800,6 +793,15 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
         nodeStatus.setVersion(version);
       }
 
+      /* Compare tor software version (for relays and bridges) with the
+       * recommended-server-versions line in the last known consensus and set
+       * the recommended_version field accordingly. */
+      if (null != this.lastRecommendedServerVersions
+          && null != nodeStatus.getVersion()) {
+        nodeStatus.setRecommendedVersion(this.lastRecommendedServerVersions
+            .contains(nodeStatus.getVersion()));
+      }
+
       Map<String, Long> exitAddresses = new HashMap<>();
       if (detailsStatus.getExitAddresses() != null) {
         for (Map.Entry<String, Long> e :
diff --git a/src/main/java/org/torproject/onionoo/writer/DetailsDocumentWriter.java b/src/main/java/org/torproject/onionoo/writer/DetailsDocumentWriter.java
index 5eaa950..1b53ffe 100644
--- a/src/main/java/org/torproject/onionoo/writer/DetailsDocumentWriter.java
+++ b/src/main/java/org/torproject/onionoo/writer/DetailsDocumentWriter.java
@@ -189,6 +189,8 @@ public class DetailsDocumentWriter implements DocumentWriter {
     detailsDocument.setFirstSeen(detailsStatus.getFirstSeenMillis());
     detailsDocument.setRunning(detailsStatus.isRunning());
     detailsDocument.setFlags(detailsStatus.getRelayFlags());
+    detailsDocument.setRecommendedVersion(
+        detailsStatus.getRecommendedVersion());
     detailsDocument.setLastRestarted(detailsStatus.getLastRestarted());
     detailsDocument.setAdvertisedBandwidth(
         detailsStatus.getAdvertisedBandwidth());





More information about the tor-commits mailing list