[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [metrics-lib/master] Parse Unmeasured=1 in w lines of consensuses.



commit 5b2104481930132b8ef7b2343e161a83cee1a89d
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Tue Apr 9 08:36:53 2013 +0200

    Parse Unmeasured=1 in w lines of consensuses.
    
    Pointed out by atagar.
---
 .../torproject/descriptor/NetworkStatusEntry.java  |    6 ++++
 .../descriptor/impl/NetworkStatusEntryImpl.java    |    8 ++++++
 .../impl/RelayNetworkStatusConsensusImplTest.java  |   25 ++++++++++++++++++++
 3 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/src/org/torproject/descriptor/NetworkStatusEntry.java b/src/org/torproject/descriptor/NetworkStatusEntry.java
index 3bda176..2f0bb89 100644
--- a/src/org/torproject/descriptor/NetworkStatusEntry.java
+++ b/src/org/torproject/descriptor/NetworkStatusEntry.java
@@ -55,6 +55,12 @@ public interface NetworkStatusEntry {
    * bandwidth line. */
   public long getMeasured();
 
+  /* Return whether the status entry contained an Unmeasured=1 entry in
+   * its bandwidth line, meaning that the bandwidth authorities didn't
+   * measure this relay yet.  Only included in consensuses using method
+   * 17 or higher. */
+  public boolean getUnmeasured();
+
   /* Return the default policy of the port summary or null if the status
    * entry didn't contain a port summary line. */
   public String getDefaultPolicy();
diff --git a/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java b/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
index 901e17e..337484e 100644
--- a/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
+++ b/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
@@ -160,6 +160,9 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
     if (pairs.containsKey("Measured")) {
       this.measured = pairs.remove("Measured");
     }
+    if (pairs.containsKey("Unmeasured")) {
+      this.unmeasured = pairs.remove("Unmeasured") == 1L;
+    }
     if (!pairs.isEmpty()) {
       /* Ignore unknown key-value pair. */
     }
@@ -255,6 +258,11 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
     return this.measured;
   }
 
+  private boolean unmeasured = false;
+  public boolean getUnmeasured() {
+    return this.unmeasured;
+  }
+
   private String defaultPolicy;
   public String getDefaultPolicy() {
     return this.defaultPolicy;
diff --git a/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java b/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
index e5a20e3..ca7ea7f 100644
--- a/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
+++ b/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
@@ -13,6 +13,7 @@ import java.util.List;
 
 
 import org.junit.Test;
+import org.torproject.descriptor.NetworkStatusEntry;
 import org.torproject.descriptor.RelayNetworkStatusConsensus;
 
 /* TODO Add test cases for all lines starting with "opt ". */
@@ -940,6 +941,30 @@ public class RelayNetworkStatusConsensusImplTest {
     new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
   }
 
+  @Test()
+  public void testWLineUnmeasured() throws DescriptorParseException {
+    StatusEntryBuilder sb = new StatusEntryBuilder();
+    sb.wLine = "w Bandwidth=42424242 Unmeasured=1";
+    ConsensusBuilder cb = new ConsensusBuilder();
+    cb.statusEntries.add(sb.buildStatusEntry());
+    RelayNetworkStatusConsensus consensus =
+        new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
+    for (NetworkStatusEntry s : consensus.getStatusEntries().values()) {
+      if (s.getBandwidth() == 42424242L) {
+        assertTrue(s.getUnmeasured());
+      }
+    }
+  }
+
+  @Test()
+  public void testWLineNotUnmeasured() throws DescriptorParseException {
+    RelayNetworkStatusConsensus consensus =
+        StatusEntryBuilder.createWithWLine("w Bandwidth=20");
+    for (NetworkStatusEntry s : consensus.getStatusEntries().values()) {
+      assertFalse(s.getUnmeasured());
+    }
+  }
+
   @Test(expected = DescriptorParseException.class)
   public void testPLineNoPolicy() throws DescriptorParseException {
     StatusEntryBuilder.createWithPLine("p 80");

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits