commit 39021ee925004d57d3d952867e03b543eb207254 Author: Karsten Loesing karsten.loesing@gmx.net Date: Fri Feb 17 09:19:26 2012 +0100
Parse old server descriptors with "opt read-history " lines. --- .../descriptor/impl/BandwidthHistoryImpl.java | 5 +++++ .../descriptor/impl/ServerDescriptorImplTest.java | 14 ++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/src/org/torproject/descriptor/impl/BandwidthHistoryImpl.java b/src/org/torproject/descriptor/impl/BandwidthHistoryImpl.java index 3e094ad..c696624 100644 --- a/src/org/torproject/descriptor/impl/BandwidthHistoryImpl.java +++ b/src/org/torproject/descriptor/impl/BandwidthHistoryImpl.java @@ -15,6 +15,11 @@ public class BandwidthHistoryImpl implements BandwidthHistory { if (partsNoOpt.length >= 5) { try { this.line = line; + if (lineNoOpt.startsWith("read-history ")) { + lineNoOpt = "read-history " + + lineNoOpt.substring("read-history ".length()); + partsNoOpt = lineNoOpt.split(" "); + } this.historyEndMillis = ParseHelper.parseTimestampAtIndex(line, partsNoOpt, 1, 2); if (partsNoOpt[3].startsWith("(") && diff --git a/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java b/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java index 85db9df..598c3ab 100644 --- a/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java +++ b/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java @@ -1007,14 +1007,12 @@ public class ServerDescriptorImplTest { assertTrue(bandwidthValues.isEmpty()); }
- /* TODO There are some old server descriptors with "read-history " - * lines. Find out if these were spec-compliant and if other lines may - * start with leading spaces, too. */ - @Test(expected = DescriptorParseException.class) - public void testReadHistoryLeadingSpace() - throws DescriptorParseException { - String readHistoryLine = "read-history 2012-01-01 03:51:44 (900 s) " - + "4268032,139264,7797760,1415168"; + @Test() + public void testReadHistoryTwoSpaces() throws DescriptorParseException { + /* There are some server descriptors from older Tor versions that + * contain "opt read-history " lines. */ + String readHistoryLine = "opt read-history 2012-01-01 03:51:44 " + + "(900 s) 4268032,139264,7797760,1415168"; DescriptorBuilder.createWithReadHistoryLine(readHistoryLine); }