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

[tor-commits] [metrics-lib/master] Parse hostnames from dir-source lines.



commit 783dad184bcda8b7305d9a741e2420d0a1e938e8
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Thu Dec 24 14:40:23 2015 +0100

    Parse hostnames from dir-source lines.
    
    Implements #17934.
---
 CHANGELOG.md                                                   |  2 ++
 src/org/torproject/descriptor/DirSourceEntry.java              |  3 +++
 src/org/torproject/descriptor/RelayNetworkStatusVote.java      |  3 +++
 src/org/torproject/descriptor/impl/DirSourceEntryImpl.java     | 10 ++++++++++
 .../torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java |  6 ++++++
 .../descriptor/impl/RelayNetworkStatusConsensusImplTest.java   |  8 ++++++++
 .../descriptor/impl/RelayNetworkStatusVoteImplTest.java        |  4 +++-
 7 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4daab24..b4b24d5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,8 @@
    - Support hidden-service statistics in extra-info descriptors.
    - Support onion-key and ntor-onion-key cross certificates in server
      descriptors.
+   - Include the hostname in directory source entries of consensuses
+     and votes.
 
  * Minor changes
    - Start using Java 7 features like the diamond operator and switch
diff --git a/src/org/torproject/descriptor/DirSourceEntry.java b/src/org/torproject/descriptor/DirSourceEntry.java
index 57a3967..da898d0 100644
--- a/src/org/torproject/descriptor/DirSourceEntry.java
+++ b/src/org/torproject/descriptor/DirSourceEntry.java
@@ -13,6 +13,9 @@ public interface DirSourceEntry {
   /* Return the identity fingerprint. */
   public String getIdentity();
 
+  /* Return the hostname. */
+  public String getHostname();
+
   /* Return the IP address. */
   public String getIp();
 
diff --git a/src/org/torproject/descriptor/RelayNetworkStatusVote.java b/src/org/torproject/descriptor/RelayNetworkStatusVote.java
index bf4ea6b..f4fad2a 100644
--- a/src/org/torproject/descriptor/RelayNetworkStatusVote.java
+++ b/src/org/torproject/descriptor/RelayNetworkStatusVote.java
@@ -100,6 +100,9 @@ public interface RelayNetworkStatusVote extends Descriptor {
   /* Return the directory identity. */
   public String getIdentity();
 
+  /* Return the hostname. */
+  public String getHostname();
+
   /* Return the IP address. */
   public String getAddress();
 
diff --git a/src/org/torproject/descriptor/impl/DirSourceEntryImpl.java b/src/org/torproject/descriptor/impl/DirSourceEntryImpl.java
index 3ea0179..5e39cfe 100644
--- a/src/org/torproject/descriptor/impl/DirSourceEntryImpl.java
+++ b/src/org/torproject/descriptor/impl/DirSourceEntryImpl.java
@@ -129,6 +129,11 @@ public class DirSourceEntryImpl implements DirSourceEntry {
     }
     this.nickname = ParseHelper.parseNickname(line, nickname);
     this.identity = ParseHelper.parseTwentyByteHexString(line, parts[2]);
+    if (parts[3].length() < 1) {
+      throw new DescriptorParseException("Illegal hostname in '" + line
+          + "'.");
+    }
+    this.hostname = parts[3];
     this.ip = ParseHelper.parseIpv4Address(line, parts[4]);
     this.dirPort = ParseHelper.parsePort(line, parts[5]);
     this.orPort = ParseHelper.parsePort(line, parts[6]);
@@ -170,6 +175,11 @@ public class DirSourceEntryImpl implements DirSourceEntry {
     return this.isLegacy;
   }
 
+  private String hostname;
+  public String getHostname() {
+    return this.hostname;
+  }
+
   private String ip;
   public String getIp() {
     return this.ip;
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
index c16a9f9..7d59282 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
@@ -343,6 +343,7 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
       throw new DescriptorParseException("Illegal hostname in '" + line
           + "'.");
     }
+    this.hostname = parts[3];
     this.address = ParseHelper.parseIpv4Address(line, parts[4]);
     this.dirPort = ParseHelper.parsePort(line, parts[5]);
     this.orPort = ParseHelper.parsePort(line, parts[6]);
@@ -441,6 +442,11 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
     return this.identity;
   }
 
+  private String hostname;
+  public String getHostname() {
+    return this.hostname;
+  }
+
   private String address;
   public String getAddress() {
     return this.address;
diff --git a/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java b/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
index 42feb8b..dbe6cd3 100644
--- a/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
+++ b/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
@@ -300,6 +300,8 @@ public class RelayNetworkStatusConsensusImplTest {
     assertEquals(30000, (int) consensus.getConsensusParams().get(
         "CircuitPriorityHalflifeMsec"));
     assertEquals("86.59.21.38", consensus.getDirSourceEntries().get(
+        "14C131DFC5C6F93646BE72FA1401C02A8DF2E8B4").getHostname());
+    assertEquals("86.59.21.38", consensus.getDirSourceEntries().get(
         "14C131DFC5C6F93646BE72FA1401C02A8DF2E8B4").getIp());
     assertTrue(consensus.containsStatusEntry(
         "00795A6E8D91C270FC23B30F388A495553E01894"));
@@ -723,6 +725,12 @@ public class RelayNetworkStatusConsensusImplTest {
   }
 
   @Test(expected = DescriptorParseException.class)
+  public void testDirSourceHostnameMissing()
+      throws DescriptorParseException {
+    DirSourceBuilder.createWithHostName("");
+  }
+
+  @Test(expected = DescriptorParseException.class)
   public void testDirSourceAddress24() throws DescriptorParseException {
     DirSourceBuilder.createWithAddress("212.112.245");
   }
diff --git a/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java b/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
index c6b2fc7..17f59a8 100644
--- a/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
+++ b/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
@@ -905,9 +905,11 @@ public class RelayNetworkStatusVoteImplTest {
   public void testHostname256()
       throws DescriptorParseException {
     /* This test doesn't fail, because we're not parsing the hostname. */
-    VoteBuilder.createWithDirSourceLine("dir-source urras "
+    RelayNetworkStatusVote vote =
+        VoteBuilder.createWithDirSourceLine("dir-source urras "
         + "80550987E1D626E3EBA5E5E75A458DE0626D088C 256.256.256.256 "
         + "208.83.223.34 443 80");
+    assertEquals("256.256.256.256", vote.getHostname());
   }
 
   @Test(expected = DescriptorParseException.class)

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