Commit 783dad18 authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Parse hostnames from dir-source lines.

Implements #17934.
parent 8767f3e3
......@@ -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
......
......@@ -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();
......
......@@ -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();
......
......@@ -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;
......
......@@ -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;
......
......@@ -299,6 +299,8 @@ public class RelayNetworkStatusConsensusImplTest {
assertTrue(consensus.getKnownFlags().contains("Running"));
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(
......@@ -722,6 +724,12 @@ public class RelayNetworkStatusConsensusImplTest {
+ "4BB25CEF515B226ED03BB616EB2F60BEC8");
}
@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");
......
......@@ -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)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment