commit be27fef42e6ae52127636f92f4dd2acd1e72a4a4 Author: Karsten Loesing karsten.loesing@gmx.net Date: Wed Nov 7 12:27:54 2012 -0500
Looks like $fingerprint~nickname is also a valid family line entry.
Support for $fingerprint=nickname was previously added in 6a46f46. --- .../torproject/descriptor/ServerDescriptor.java | 4 ++-- .../descriptor/impl/ServerDescriptorImpl.java | 12 ++++++++---- .../descriptor/impl/ServerDescriptorImplTest.java | 13 ++++++++++++- 3 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/src/org/torproject/descriptor/ServerDescriptor.java b/src/org/torproject/descriptor/ServerDescriptor.java index a7f76c7..0875eeb 100644 --- a/src/org/torproject/descriptor/ServerDescriptor.java +++ b/src/org/torproject/descriptor/ServerDescriptor.java @@ -91,8 +91,8 @@ public interface ServerDescriptor extends Descriptor { * information is included in the descriptor. */ public String getContact();
- /* Return the nicknames, ($-prefixed) fingerprints, or - * $fingerprint=nickname tuples contained in the family line of this + /* Return nicknames, ($-prefixed) fingerprints, $fingerprint=nickname, + * or $fingerprint~nickname tuples contained in the family line of this * relay, or null if the descriptor does not contain a family line. */ public List<String> getFamilyEntries();
diff --git a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java index df3662f..4443284 100644 --- a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java +++ b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java @@ -327,12 +327,16 @@ public class ServerDescriptorImpl extends DescriptorImpl this.familyEntries = new ArrayList<String>(); for (int i = 1; i < partsNoOpt.length; i++) { if (partsNoOpt[i].startsWith("$")) { - if (partsNoOpt[i].contains("=")) { + if (partsNoOpt[i].contains("=") ^ partsNoOpt[i].contains("~")) { + String separator = partsNoOpt[i].contains("=") ? "=" : "~"; String fingerprint = ParseHelper.parseTwentyByteHexString(line, - partsNoOpt[i].substring(1, partsNoOpt[i].indexOf("="))); + partsNoOpt[i].substring(1, partsNoOpt[i].indexOf( + separator))); String nickname = ParseHelper.parseNickname(line, - partsNoOpt[i].substring(partsNoOpt[i].indexOf("=") + 1)); - this.familyEntries.add("$" + fingerprint + "=" + nickname); + partsNoOpt[i].substring(partsNoOpt[i].indexOf( + separator) + 1)); + this.familyEntries.add("$" + fingerprint + separator + + nickname); } else { this.familyEntries.add("$" + ParseHelper.parseTwentyByteHexString(line, diff --git a/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java b/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java index 264ff13..ece15fb 100644 --- a/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java +++ b/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java @@ -896,7 +896,7 @@ public class ServerDescriptorImplTest { }
@Test() - public void testFamilyFingerprintNickname() + public void testFamilyFingerprintNicknameNamed() throws DescriptorParseException { ServerDescriptor descriptor = DescriptorBuilder. createWithFamilyLine("family " @@ -907,6 +907,17 @@ public class ServerDescriptorImplTest { }
@Test() + public void testFamilyFingerprintNicknameUnnamed() + throws DescriptorParseException { + ServerDescriptor descriptor = DescriptorBuilder. + createWithFamilyLine("family " + + "$D8733048FC8EC9102466AD8F3098622BF1BF71FD~saberrider2008"); + assertEquals(Arrays.asList(new String[] + { "$D8733048FC8EC9102466AD8F3098622BF1BF71FD~saberrider2008" }), + descriptor.getFamilyEntries()); + } + + @Test() public void testWriteHistory() throws DescriptorParseException { String writeHistoryLine = "write-history 2012-01-01 03:51:44 (900 s) " + "4345856,261120,7591936,1748992";
tor-commits@lists.torproject.org