[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-lib/master] directory-footer lines were optional before consensus method 9.
commit b57644ef288f7441fc07ce4833a0c1407e052a5e
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Fri Feb 17 08:06:56 2012 +0100
directory-footer lines were optional before consensus method 9.
---
.../impl/RelayNetworkStatusConsensusImpl.java | 5 ++---
.../impl/RelayNetworkStatusVoteImpl.java | 5 ++---
.../descriptor/impl/ConsensusBuilder.java | 6 ++++++
.../impl/RelayNetworkStatusConsensusImplTest.java | 15 +++++++++++++++
.../impl/RelayNetworkStatusVoteImplTest.java | 2 +-
5 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
index 10f97c0..734ee4c 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
@@ -44,11 +44,10 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl
super(consensusBytes, failUnrecognizedDescriptorLines);
Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList((
"vote-status,consensus-method,valid-after,fresh-until,"
- + "valid-until,voting-delay,known-flags,"
- + "directory-footer").split(",")));
+ + "valid-until,voting-delay,known-flags").split(",")));
this.checkExactlyOnceKeywords(exactlyOnceKeywords);
Set<String> atMostOnceKeywords = new HashSet<String>(Arrays.asList((
- "client-versions,server-versions,params,"
+ "client-versions,server-versions,params,directory-footer,"
+ "bandwidth-weights").split(",")));
this.checkAtMostOnceKeywords(atMostOnceKeywords);
this.checkFirstKeyword("network-status-version");
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
index a00cd75..28850a7 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
@@ -47,12 +47,11 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
+ "valid-until,voting-delay,known-flags,dir-source,"
+ "dir-key-certificate-version,fingerprint,dir-key-published,"
+ "dir-key-expires,dir-identity-key,dir-signing-key,"
- + "dir-key-certification,directory-footer,directory-signature").
- split(",")));
+ + "dir-key-certification,directory-signature").split(",")));
this.checkExactlyOnceKeywords(exactlyOnceKeywords);
Set<String> atMostOnceKeywords = new HashSet<String>(Arrays.asList((
"client-versions,server-versions,params,contact,legacy-key,"
- + "dir-key-crosscert,dir-address").split(",")));
+ + "dir-key-crosscert,dir-address,directory-footer").split(",")));
this.checkAtMostOnceKeywords(atMostOnceKeywords);
this.checkFirstKeyword("network-status-version");
}
diff --git a/test/org/torproject/descriptor/impl/ConsensusBuilder.java b/test/org/torproject/descriptor/impl/ConsensusBuilder.java
index 2d0291d..f35864b 100644
--- a/test/org/torproject/descriptor/impl/ConsensusBuilder.java
+++ b/test/org/torproject/descriptor/impl/ConsensusBuilder.java
@@ -108,6 +108,9 @@ public class ConsensusBuilder {
List<String> dirSources = new ArrayList<String>();
List<String> statusEntries = new ArrayList<String>();
private String directoryFooterLine = "directory-footer";
+ protected void setDirectoryFooterLine(String line) {
+ this.directoryFooterLine = line;
+ }
protected static RelayNetworkStatusConsensus
createWithDirectoryFooterLine(String line)
throws DescriptorParseException {
@@ -119,6 +122,9 @@ public class ConsensusBuilder {
+ "Wbe=0 Wbg=0 Wbm=10000 Wdb=10000 Web=10000 Wed=1021 Wee=10000 "
+ "Weg=1021 Wem=10000 Wgb=10000 Wgd=8694 Wgg=10000 Wgm=10000 "
+ "Wmb=10000 Wmd=285 Wme=0 Wmg=0 Wmm=10000";
+ protected void setBandwidthWeightsLine(String line) {
+ this.bandwidthWeightsLine = line;
+ }
protected static RelayNetworkStatusConsensus
createWithBandwidthWeightsLine(String line)
throws DescriptorParseException {
diff --git a/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java b/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
index b37b72a..65c9658 100644
--- a/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
+++ b/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
@@ -981,10 +981,25 @@ public class RelayNetworkStatusConsensusImplTest {
@Test(expected = DescriptorParseException.class)
public void testDirectoryFooterNoLine()
throws DescriptorParseException {
+ /* This breaks, because a bandwidth-weights line without a preceding
+ * directory-footer line is not allowed. */
ConsensusBuilder.createWithDirectoryFooterLine(null);
}
@Test()
+ public void testDirectoryFooterMissing()
+ throws DescriptorParseException {
+ ConsensusBuilder cb = new ConsensusBuilder();
+ cb.setDirectoryFooterLine(null);
+ cb.setBandwidthWeightsLine(null);
+ /* This does not break, because directory footers were optional before
+ * consensus method 9. */
+ RelayNetworkStatusConsensus consensus =
+ new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
+ assertNull(consensus.getBandwidthWeights());
+ }
+
+ @Test()
public void testDirectoryFooterLineSpace()
throws DescriptorParseException {
ConsensusBuilder.createWithDirectoryFooterLine("directory-footer ");
diff --git a/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java b/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
index 8a60eec..7569d7a 100644
--- a/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
+++ b/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
@@ -1032,7 +1032,7 @@ public class RelayNetworkStatusVoteImplTest {
VoteBuilder.createWithDirKeyCertificationLines(null);
}
- @Test(expected = DescriptorParseException.class)
+ @Test()
public void testDirectoryFooterLineMissing()
throws DescriptorParseException {
VoteBuilder.createWithDirectoryFooterLine(null);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits