commit e5eb41b5deb6a7ff32753d4cada03ca29745672e Author: Karsten Loesing karsten.loesing@gmx.net Date: Thu Aug 13 10:27:28 2015 +0200
Add "measured" field to details documents.
Implements #16020. --- build.xml | 2 +- .../torproject/onionoo/docs/DetailsDocument.java | 8 ++++++ .../org/torproject/onionoo/docs/DetailsStatus.java | 8 ++++++ .../torproject/onionoo/server/ResponseBuilder.java | 4 ++- .../onionoo/updater/NodeDetailsStatusUpdater.java | 30 ++++++++++++++++++++ .../onionoo/writer/DetailsDocumentWriter.java | 1 + web/protocol.html | 15 ++++++++++ 7 files changed, 66 insertions(+), 2 deletions(-)
diff --git a/build.xml b/build.xml index 75dfe1c..f82b49d 100644 --- a/build.xml +++ b/build.xml @@ -1,6 +1,6 @@ <project default="dist" name="onionoo" basedir=".">
- <property name="onionoo.protocol.version" value="2.4"/> + <property name="onionoo.protocol.version" value="2.5"/> <property name="release.version" value="${onionoo.protocol.version}.0"/> <property name="javasources" value="src/main/java"/> diff --git a/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java b/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java index 2b65e50..aa410d8 100644 --- a/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java +++ b/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java @@ -362,5 +362,13 @@ public class DetailsDocument extends Document { public List<String> getTransports() { return this.transports; } + + private Boolean measured; + public void setMeasured(Boolean measured) { + this.measured = measured; + } + public Boolean getMeasured() { + return this.measured; + } }
diff --git a/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java b/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java index 09f0824..0a97fd3 100644 --- a/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java +++ b/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java @@ -295,6 +295,14 @@ public class DetailsStatus extends Document { return this.recommended_version; }
+ private Boolean measured; + public void setMeasured(Boolean measured) { + this.measured = measured; + } + public Boolean getMeasured() { + return this.measured; + } + /* From exit lists: */
private Map<String, Long> exit_addresses; diff --git a/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java b/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java index c7bfd65..ffd6ddb 100644 --- a/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java +++ b/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java @@ -70,7 +70,7 @@ public class ResponseBuilder { return this.charsWritten; }
- private static final String PROTOCOL_VERSION = "2.4"; + private static final String PROTOCOL_VERSION = "2.5";
private static final String NEXT_MAJOR_VERSION_SCHEDULED = null;
@@ -269,6 +269,8 @@ public class ResponseBuilder { dd.setTransports(detailsDocument.getTransports()); } else if (field.equals("effective_family")) { dd.setEffectiveFamily(detailsDocument.getEffectiveFamily()); + } else if (field.equals("measured")) { + dd.setMeasured(detailsDocument.getMeasured()); } } /* 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 4fb0143..fdcd419 100644 --- a/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java +++ b/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java @@ -224,6 +224,10 @@ public class NodeDetailsStatusUpdater implements DescriptorListener, } }
+ private Map<String, Long> + lastSeenUnmeasured = new HashMap<String, Long>(), + lastSeenMeasured = new HashMap<String, Long>(); + private void processRelayNetworkStatusConsensus( RelayNetworkStatusConsensus consensus) { long validAfterMillis = consensus.getValidAfterMillis(); @@ -274,6 +278,17 @@ public class NodeDetailsStatusUpdater implements DescriptorListener, entry.getVersion() == null) ? null : recommendedVersions.contains(entry.getVersion())); } + if (entry.getUnmeasured()) { + if (!this.lastSeenUnmeasured.containsKey(fingerprint) || + this.lastSeenUnmeasured.get(fingerprint) < validAfterMillis) { + this.lastSeenUnmeasured.put(fingerprint, validAfterMillis); + } + } else if (consensus.getConsensusMethod() >= 17) { + if (!this.lastSeenMeasured.containsKey(fingerprint) || + this.lastSeenMeasured.get(fingerprint) < validAfterMillis) { + this.lastSeenMeasured.put(fingerprint, validAfterMillis); + } + } } this.relayConsensusesProcessed++; if (this.relaysLastValidAfterMillis == validAfterMillis) { @@ -799,6 +814,21 @@ public class NodeDetailsStatusUpdater implements DescriptorListener, nodeStatus.setLastRdnsLookup(this.startedRdnsLookups); }
+ if (detailsStatus.getLastSeenMillis() < + nodeStatus.getLastSeenMillis()) { + if (this.lastSeenMeasured.containsKey(fingerprint)) { + if (this.lastSeenUnmeasured.containsKey(fingerprint) && + this.lastSeenUnmeasured.get(fingerprint) > + this.lastSeenMeasured.get(fingerprint)) { + detailsStatus.setMeasured(false); + } else { + detailsStatus.setMeasured(true); + } + } else if (this.lastSeenUnmeasured.containsKey(fingerprint)) { + detailsStatus.setMeasured(false); + } + } + detailsStatus.setRelay(nodeStatus.isRelay()); detailsStatus.setRunning(nodeStatus.getLastSeenMillis() == (nodeStatus.isRelay() diff --git a/src/main/java/org/torproject/onionoo/writer/DetailsDocumentWriter.java b/src/main/java/org/torproject/onionoo/writer/DetailsDocumentWriter.java index 152b4cb..6f60958 100644 --- a/src/main/java/org/torproject/onionoo/writer/DetailsDocumentWriter.java +++ b/src/main/java/org/torproject/onionoo/writer/DetailsDocumentWriter.java @@ -131,6 +131,7 @@ public class DetailsDocumentWriter implements DocumentWriter { detailsDocument.setExitAddresses(new ArrayList<String>( exitAddressesWithoutOrAddresses)); } + detailsDocument.setMeasured(detailsStatus.getMeasured()); this.documentStore.store(detailsDocument, fingerprint); }
diff --git a/web/protocol.html b/web/protocol.html index 9f36e4d..6681faf 100644 --- a/web/protocol.html +++ b/web/protocol.html @@ -178,6 +178,8 @@ added "transports" field to bridge details documents on December 8, documents on March 22, 2015.</li> <li><strong>2.4</strong>: Added optional "effective_family" field to details documents on July 3, 2015.</li> +<li><strong>2.5</strong>: Added optional "measured" field to details +documents on August 13, 2015.</li> </ul>
</div> <!-- box --> @@ -1257,6 +1259,19 @@ bandwidth weights. </p> </li>
+<li> +<b>measured</b> +<code class="typeof">boolean</code> +<span class="required-false">optional</span> +<p> +Boolean field saying whether the consensus weight of this relay is based +on a threshold of 3 or more measurements by Tor bandwidth authorities. +Omitted if the network status consensus containing this relay does not +contain measurement information. +<font color="blue">Added on August 13, 2015.</font> +</p> +</li> + </ul>
<h4>Bridge details objects</h4>
tor-commits@lists.torproject.org