[tor-commits] [metrics-lib/master] Enable bridge descriptor parsing.

karsten at torproject.org karsten at torproject.org
Thu Jan 12 09:23:03 UTC 2012


commit ad10cd9ac88dac0de65c336448b5b639292ee6d0
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Thu Jan 12 10:21:16 2012 +0100

    Enable bridge descriptor parsing.
---
 .../torproject/descriptor/impl/DescriptorImpl.java |   10 ++++------
 .../descriptor/impl/ExtraInfoDescriptorImpl.java   |   20 +++++++++++++++++---
 .../descriptor/impl/ServerDescriptorImpl.java      |    9 ++++-----
 .../impl/RelayNetworkStatusVoteImplTest.java       |    2 +-
 .../descriptor/impl/ServerDescriptorImplTest.java  |   16 ----------------
 5 files changed, 26 insertions(+), 31 deletions(-)

diff --git a/src/org/torproject/descriptor/impl/DescriptorImpl.java b/src/org/torproject/descriptor/impl/DescriptorImpl.java
index 259a1de..233b2df 100644
--- a/src/org/torproject/descriptor/impl/DescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/DescriptorImpl.java
@@ -65,14 +65,12 @@ public abstract class DescriptorImpl implements Descriptor {
           rawDescriptorBytes, fileName));
     } else if (firstLines.startsWith("router ") ||
         firstLines.contains("\nrouter ")) {
-      /* TODO Implement me.
-      parsedDescriptors.addAll(BridgeServerDescriptorImpl.
-          parseDescriptors(rawDescriptorBytes)); */
+      parsedDescriptors.addAll(ServerDescriptorImpl.
+          parseDescriptors(rawDescriptorBytes));
     } else if (firstLines.startsWith("extra-info ") ||
         firstLines.contains("\nextra-info ")) {
-      /* TODO Implement me.
-      parsedDescriptors.addAll(BridgeExtraInfoDescriptorImpl.
-          parseDescriptors(rawDescriptorBytes)); */
+      parsedDescriptors.addAll(ExtraInfoDescriptorImpl.
+          parseDescriptors(rawDescriptorBytes));
     } else {
       throw new DescriptorParseException("Could not detect bridge "
           + "descriptor type in descriptor starting with '" + firstLines
diff --git a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
index 6dae9eb..dc9f521 100644
--- a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
@@ -46,7 +46,7 @@ public class ExtraInfoDescriptorImpl extends DescriptorImpl
     super(descriptorBytes);
     this.parseDescriptorBytes();
     Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList((
-        "extra-info,published,router-signature").split(",")));
+        "extra-info,published").split(",")));
     this.checkExactlyOnceKeywords(exactlyOnceKeywords);
     Set<String> atMostOnceKeywords = new HashSet<String>(Arrays.asList((
         "read-history,write-history,geoip-db-digest,dirreq-stats-end,"
@@ -58,12 +58,12 @@ public class ExtraInfoDescriptorImpl extends DescriptorImpl
         + "cell-processed-cells,cell-queued-cells,cell-time-in-queue,"
         + "cell-circuits-per-decile,conn-bi-direct,exit-stats-end,"
         + "exit-kibibytes-written,exit-kibibytes-read,"
-        + "exit-streams-opened").split(",")));
+        + "exit-streams-opened,bridge-stats-end,bridge-stats-ips,"
+        + "router-signature").split(",")));
     this.checkAtMostOnceKeywords(atMostOnceKeywords);
     /* TODO Add more checks to see that only statistics details lines are
      * included with corresponding statistics interval lines. */
     this.checkFirstKeyword("extra-info");
-    this.checkLastKeyword("router-signature");
     return;
   }
 
@@ -147,6 +147,10 @@ public class ExtraInfoDescriptorImpl extends DescriptorImpl
           this.parseExitKibibytesReadLine(line, lineNoOpt, partsNoOpt);
         } else if (keyword.equals("exit-streams-opened")) {
           this.parseExitStreamsOpenedLine(line, lineNoOpt, partsNoOpt);
+        } else if (keyword.equals("bridge-stats-end")) {
+          this.parseBridgeStatsEndLine(line, lineNoOpt, partsNoOpt);
+        } else if (keyword.equals("bridge-ips")) {
+          this.parseBridgeStatsIpsLine(line, lineNoOpt, partsNoOpt);
         } else if (keyword.equals("router-signature")) {
           this.parseRouterSignatureLine(line, lineNoOpt, partsNoOpt);
         } else if (line.startsWith("-----BEGIN")) {
@@ -353,6 +357,16 @@ public class ExtraInfoDescriptorImpl extends DescriptorImpl
     /* TODO Implement me. */
   }
 
+  private void parseBridgeStatsEndLine(String line, String lineNoOpt,
+      String[] partsNoOpt) throws DescriptorParseException {
+    /* TODO Implement me. */
+  }
+
+  private void parseBridgeStatsIpsLine(String line, String lineNoOpt,
+      String[] partsNoOpt) throws DescriptorParseException {
+    /* TODO Implement me. */
+  }
+
   private void parseRouterSignatureLine(String line, String lineNoOpt,
       String[] partsNoOpt) throws DescriptorParseException {
     if (!lineNoOpt.equals("router-signature")) {
diff --git a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
index 878955e..411e8c9 100644
--- a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
@@ -42,18 +42,17 @@ public class ServerDescriptorImpl extends DescriptorImpl
       throws DescriptorParseException {
     super(descriptorBytes);
     this.parseDescriptorBytes();
-    Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList((
-        "router,bandwidth,published,onion-key,signing-key,"
-        + "router-signature").split(",")));
+    Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList(
+        "router,bandwidth,published".split(",")));
     this.checkExactlyOnceKeywords(exactlyOnceKeywords);
     Set<String> atMostOnceKeywords = new HashSet<String>(Arrays.asList((
         "platform,fingerprint,hibernating,uptime,contact,family,"
         + "read-history,write-history,eventdns,caches-extra-info,"
         + "extra-info-digest,hidden-service-dir,protocols,"
-        + "allow-single-hop-exits").split(",")));
+        + "allow-single-hop-exits,onion-key,signing-key,"
+        + "router-signature").split(",")));
     this.checkAtMostOnceKeywords(atMostOnceKeywords);
     this.checkFirstKeyword("router");
-    this.checkLastKeyword("router-signature");
     if (this.getKeywordCount("accept") == 0 &&
         this.getKeywordCount("reject") == 0) {
       throw new DescriptorParseException("Either keyword 'accept' or "
diff --git a/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java b/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
index 7618fff..ffacc9f 100644
--- a/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
+++ b/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
@@ -687,7 +687,7 @@ public class RelayNetworkStatusVoteImplTest {
         + "208.83.223.34 443 80");
   }
 
-  @Test(expected = DescriptorParseException.class)
+  @Test()
   public void testFingerprintLowerCase() throws DescriptorParseException {
     VoteBuilder.createWithDirSourceLine("dir-source urras "
         + "80550987e1d626e3eba5e5e75a458de0626d088c 208.83.223.34 "
diff --git a/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java b/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
index c0721f5..f699694 100644
--- a/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
+++ b/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
@@ -609,11 +609,6 @@ public class ServerDescriptorImplTest {
     assertNull(descriptor.getExtraInfoDigest());
   }
 
-  @Test(expected = DescriptorParseException.class)
-  public void testOnionKeyMissing() throws DescriptorParseException {
-    DescriptorBuilder.createWithOnionKeyLines(null);
-  }
-
   @Test()
   public void testOnionKeyOpt() throws DescriptorParseException {
     ServerDescriptor descriptor = DescriptorBuilder.
@@ -626,11 +621,6 @@ public class ServerDescriptorImplTest {
         + "-----END RSA PUBLIC KEY-----");
   }
 
-  @Test(expected = DescriptorParseException.class)
-  public void testSigningKeyMissing() throws DescriptorParseException {
-    DescriptorBuilder.createWithSigningKeyLines(null);
-  }
-
   @Test()
   public void testSigningKeyOpt() throws DescriptorParseException {
     ServerDescriptor descriptor = DescriptorBuilder.
@@ -749,12 +739,6 @@ public class ServerDescriptorImplTest {
     DescriptorBuilder.createWithExitPolicyLines(null);
   }
 
-  @Test(expected = DescriptorParseException.class)
-  public void testRouterSignatureMissing()
-      throws DescriptorParseException {
-    DescriptorBuilder.createWithRouterSignatureLines(null);
-  }
-
   @Test()
   public void testRouterSignatureOpt()
       throws DescriptorParseException {



More information about the tor-commits mailing list