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

karsten at torproject.org karsten at torproject.org
Mon Jan 13 09:32:18 UTC 2014


commit 786db5dae3641bf9d13896b9e84f59a54643c143
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Mon Jan 13 10:30:48 2014 +0100

    Add recommended_version field to details documents.
    
    Implements #10619.
---
 src/org/torproject/onionoo/NodeDataWriter.java |   20 ++++++++++++++++++--
 src/org/torproject/onionoo/NodeStatus.java     |   19 +++++++++++++++++--
 web/index.html                                 |   15 ++++++++++++++-
 3 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/src/org/torproject/onionoo/NodeDataWriter.java b/src/org/torproject/onionoo/NodeDataWriter.java
index 290802c..7623e16 100644
--- a/src/org/torproject/onionoo/NodeDataWriter.java
+++ b/src/org/torproject/onionoo/NodeDataWriter.java
@@ -136,6 +136,14 @@ public class NodeDataWriter implements DataWriter, DescriptorListener {
     if (validAfterMillis > this.relaysLastValidAfterMillis) {
       this.relaysLastValidAfterMillis = validAfterMillis;
     }
+    Set<String> recommendedVersions = null;
+    if (consensus.getRecommendedServerVersions() != null) {
+      recommendedVersions = new HashSet<String>();
+      for (String recommendedVersion :
+          consensus.getRecommendedServerVersions()) {
+        recommendedVersions.add("Tor " + recommendedVersion);
+      }
+    }
     for (NetworkStatusEntry entry :
         consensus.getStatusEntries().values()) {
       String nickname = entry.getNickname();
@@ -149,11 +157,14 @@ public class NodeDataWriter implements DataWriter, DescriptorListener {
       long consensusWeight = entry.getBandwidth();
       String defaultPolicy = entry.getDefaultPolicy();
       String portList = entry.getPortList();
+      Boolean recommendedVersion = (recommendedVersions == null ||
+          entry.getVersion() == null) ? null :
+          recommendedVersions.contains(entry.getVersion());
       NodeStatus newNodeStatus = new NodeStatus(true, nickname,
           fingerprint, address, orAddressesAndPorts, null,
           validAfterMillis, orPort, dirPort, relayFlags, consensusWeight,
           null, null, -1L, defaultPolicy, portList, validAfterMillis,
-          validAfterMillis, null, null);
+          validAfterMillis, null, null, recommendedVersion);
       if (this.knownNodes.containsKey(fingerprint)) {
         this.knownNodes.get(fingerprint).update(newNodeStatus);
       } else {
@@ -183,7 +194,7 @@ public class NodeDataWriter implements DataWriter, DescriptorListener {
       NodeStatus newNodeStatus = new NodeStatus(false, nickname,
           fingerprint, address, orAddressesAndPorts, null,
           publishedMillis, orPort, dirPort, relayFlags, -1L, "??", null,
-          -1L, null, null, publishedMillis, -1L, null, null);
+          -1L, null, null, publishedMillis, -1L, null, null, null);
       if (this.knownNodes.containsKey(fingerprint)) {
         this.knownNodes.get(fingerprint).update(newNodeStatus);
       } else {
@@ -697,6 +708,7 @@ public class NodeDataWriter implements DataWriter, DescriptorListener {
       double exitProbability = entry.getExitProbability();
       String defaultPolicy = entry.getDefaultPolicy();
       String portList = entry.getPortList();
+      Boolean recommendedVersion = entry.getRecommendedVersion();
       StringBuilder sb = new StringBuilder();
       sb.append("{\"version\":1,\n"
           + "\"nickname\":\"" + nickname + "\",\n"
@@ -790,6 +802,10 @@ public class NodeDataWriter implements DataWriter, DescriptorListener {
         }
         sb.append("]}");
       }
+      if (recommendedVersion != null) {
+        sb.append(",\n\"recommended_version\":" + (recommendedVersion ?
+            "true" : "false"));
+      }
 
       /* Add exit addresses if at least one of them is distinct from the
        * onion-routing addresses. */
diff --git a/src/org/torproject/onionoo/NodeStatus.java b/src/org/torproject/onionoo/NodeStatus.java
index e549336..30e1ed4 100644
--- a/src/org/torproject/onionoo/NodeStatus.java
+++ b/src/org/torproject/onionoo/NodeStatus.java
@@ -56,13 +56,15 @@ public class NodeStatus extends Document {
   private String portList;
   private SortedMap<Long, Set<String>> lastAddresses;
   private String contact;
+  private Boolean recommendedVersion;
   public NodeStatus(boolean isRelay, String nickname, String fingerprint,
       String address, SortedSet<String> orAddressesAndPorts,
       SortedSet<String> exitAddresses, long lastSeenMillis, int orPort,
       int dirPort, SortedSet<String> relayFlags, long consensusWeight,
       String countryCode, String hostName, long lastRdnsLookup,
       String defaultPolicy, String portList, long firstSeenMillis,
-      long lastChangedAddresses, String aSNumber, String contact) {
+      long lastChangedAddresses, String aSNumber, String contact,
+      Boolean recommendedVersion) {
     this.isRelay = isRelay;
     this.nickname = nickname;
     this.fingerprint = fingerprint;
@@ -108,6 +110,7 @@ public class NodeStatus extends Document {
     this.lastAddresses.put(lastChangedAddresses, addresses);
     this.aSNumber = aSNumber;
     this.contact = contact;
+    this.recommendedVersion = recommendedVersion;
   }
 
   public static NodeStatus fromString(String documentString) {
@@ -121,6 +124,7 @@ public class NodeStatus extends Document {
         lastRdnsLookup = -1L, firstSeenMillis = -1L,
         lastChangedAddresses = -1L;
     int orPort = -1, dirPort = -1;
+    Boolean recommendedVersion = null;
     try {
       SimpleDateFormat dateTimeFormat = new SimpleDateFormat(
           "yyyy-MM-dd HH:mm:ss");
@@ -199,6 +203,10 @@ public class NodeStatus extends Document {
       if (parts.length > 20) {
         contact = parts[20];
       }
+      if (parts.length > 21) {
+        recommendedVersion = parts[21].equals("null") ? null :
+            parts[21].equals("true");
+      }
     } catch (NumberFormatException e) {
       System.err.println("Number format exception while parsing node "
           + "status line '" + documentString + "': " + e.getMessage()
@@ -221,7 +229,8 @@ public class NodeStatus extends Document {
         fingerprint, address, orAddressesAndPorts, exitAddresses,
         lastSeenMillis, orPort, dirPort, relayFlags, consensusWeight,
         countryCode, hostName, lastRdnsLookup, defaultPolicy, portList,
-        firstSeenMillis, lastChangedAddresses, aSNumber, contact);
+        firstSeenMillis, lastChangedAddresses, aSNumber, contact,
+        recommendedVersion);
     return newNodeStatus;
   }
 
@@ -241,6 +250,7 @@ public class NodeStatus extends Document {
       this.portList = newNodeStatus.portList;
       this.aSNumber = newNodeStatus.aSNumber;
       this.contact = newNodeStatus.contact;
+      this.recommendedVersion = newNodeStatus.recommendedVersion;
     }
     if (this.isRelay && newNodeStatus.isRelay) {
       this.lastAddresses.putAll(newNodeStatus.lastAddresses);
@@ -298,6 +308,8 @@ public class NodeStatus extends Document {
       sb.append("\tnull\tnull\tnull");
     }
     sb.append("\t" + (this.contact != null ? this.contact : ""));
+    sb.append("\t" + (this.recommendedVersion == null ? "null" :
+        this.recommendedVersion ? "true" : "false"));
     return sb.toString();
   }
 
@@ -508,5 +520,8 @@ public class NodeStatus extends Document {
   public String getContact() {
     return this.contact;
   }
+  public Boolean getRecommendedVersion() {
+    return this.recommendedVersion;
+  }
 }
 
diff --git a/web/index.html b/web/index.html
index f59a433..d270c60 100644
--- a/web/index.html
+++ b/web/index.html
@@ -945,7 +945,7 @@ If there is an "accept" ("reject") element, the relay accepts (rejects)
 all TCP ports or port ranges in the given list for most IP addresses and
 rejects (accepts) all other ports.
 Missing if the relay rejects all connections to IPv6 addresses.
-<font color="blue">Added on January 6, 2013.</font>
+<font color="blue">Added on January 6, 2014.</font>
 </p>
 </li>
 
@@ -973,6 +973,19 @@ found.
 </li>
 
 <li>
+<font color="blue"><b>recommended_version</b></font>
+<code class="typeof">boolean</code>
+<span class="required-false">optional</span>
+<p>
+Boolean field saying whether the Tor software version of this relay is
+recommended by the directory authorities or not.
+Omitted if either the directory authorities did not recommend versions, or
+the relay did not report which version it runs.
+<font color="blue">Added on January 13, 2014.</font>
+</p>
+</li>
+
+<li>
 <b>family</b>
 <code class="typeof">array of strings</code>
 <span class="required-false">optional</span>



More information about the tor-commits mailing list