commit 368deb83efd2e8492070593d10268a1a3e2ff397 Author: Karsten Loesing karsten.loesing@gmx.net Date: Wed Apr 4 22:04:03 2018 +0200
Create ServerDescriptor#isHiddenServiceDir.
Turns out that Tor has never supported versions in the hidden-service-dir descriptor line.
This commit replaces ServerDescriptor#getHiddenServiceDirVersions with ServerDescriptor#isHiddenServiceDir.
Fixes #25712. --- CHANGELOG.md | 7 +++++- .../torproject/descriptor/ServerDescriptor.java | 10 ++++++++ .../descriptor/impl/ServerDescriptorImpl.java | 29 ++++++++-------------- .../descriptor/impl/ServerDescriptorImplTest.java | 11 +++----- 4 files changed, 31 insertions(+), 26 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md index 58235e3..d64d58d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changes in version 2.3.0 - 2018-0?-??
- * Minor changes. + * Medium changes + - Replace ServerDescriptor#getHiddenServiceDirVersions with + ServerDescriptor#isHiddenServiceDir, because Tor has never + supported versions in the hidden-service-dir descriptor line. + + * Minor changes - Override logLines() method from LogDescriptor in WebServerAccessLog. - Use 1-minute connect and read timeouts for fetching CollecTor's diff --git a/src/main/java/org/torproject/descriptor/ServerDescriptor.java b/src/main/java/org/torproject/descriptor/ServerDescriptor.java index ac9c645..1b91ec8 100644 --- a/src/main/java/org/torproject/descriptor/ServerDescriptor.java +++ b/src/main/java/org/torproject/descriptor/ServerDescriptor.java @@ -318,11 +318,21 @@ public interface ServerDescriptor extends Descriptor { * this server stores and serves, or null if it doesn't store and serve * any hidden service descriptors. * + * @deprecated Replaced with {@link #isHiddenServiceDir}, because Tor has + * never supported versions in the hidden-service-dir descriptor line. + * * @since 1.0.0 */ public List<Integer> getHiddenServiceDirVersions();
/** + * Return whether this server stores and serves hidden service descriptors. + * + * @since 2.3.0 + */ + public boolean isHiddenServiceDir(); + + /** * Return the list of link protocol versions that this server * supports. * diff --git a/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java index ca79cd2..9c9d47a 100644 --- a/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java @@ -10,6 +10,7 @@ import org.torproject.descriptor.ServerDescriptor; import java.io.File; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.EnumSet; import java.util.List; import java.util.Scanner; @@ -462,21 +463,8 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl }
private void parseHiddenServiceDirLine(String line, String lineNoOpt, - String[] partsNoOpt) throws DescriptorParseException { - if (partsNoOpt.length == 1) { - this.hiddenServiceDirVersions = new Integer[] { 2 }; - } else { - try { - Integer[] result = new Integer[partsNoOpt.length - 1]; - for (int i = 1; i < partsNoOpt.length; i++) { - result[i - 1] = Integer.parseInt(partsNoOpt[i]); - } - this.hiddenServiceDirVersions = result; - } catch (NumberFormatException e) { - throw new DescriptorParseException("Illegal value in line '" - + line + "'."); - } - } + String[] partsNoOpt) { + this.hiddenServiceDir = true; }
private void parseProtocolsLine(String line, String lineNoOpt, @@ -854,12 +842,17 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl return this.extraInfoDigestSha256; }
- private Integer[] hiddenServiceDirVersions; + private boolean hiddenServiceDir; + + @Override + public boolean isHiddenServiceDir() { + return this.hiddenServiceDir; + }
@Override + @SuppressWarnings("deprecation") public List<Integer> getHiddenServiceDirVersions() { - return this.hiddenServiceDirVersions == null ? null - : Arrays.asList(this.hiddenServiceDirVersions); + return this.hiddenServiceDir ? null : Collections.singletonList(2); }
private Integer[] linkProtocolVersions; diff --git a/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java b/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java index f121cb3..b81c3fb 100644 --- a/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java +++ b/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java @@ -482,8 +482,7 @@ public class ServerDescriptorImplTest { assertEquals(53470, (int) descriptor.getBandwidthObserved()); assertEquals("1469D1550738A25B1E7B47CDDBCD7B2899F51B74", descriptor.getExtraInfoDigestSha1Hex()); - assertEquals(Arrays.asList(new Integer[] {2}), - descriptor.getHiddenServiceDirVersions()); + assertTrue(descriptor.isHiddenServiceDir()); assertEquals("Random Person <nobody AT example dot com>", descriptor.getContact()); assertEquals(Arrays.asList(new String[] {"reject *:*"}), @@ -1014,7 +1013,7 @@ public class ServerDescriptorImplTest { throws DescriptorParseException { ServerDescriptor descriptor = DescriptorBuilder .createWithHiddenServiceDirLine(null); - assertNull(descriptor.getHiddenServiceDirVersions()); + assertFalse(descriptor.isHiddenServiceDir()); }
@Test @@ -1022,8 +1021,7 @@ public class ServerDescriptorImplTest { throws DescriptorParseException { ServerDescriptor descriptor = DescriptorBuilder .createWithHiddenServiceDirLine("hidden-service-dir"); - assertEquals(Arrays.asList(new Integer[] {2}), - descriptor.getHiddenServiceDirVersions()); + assertTrue(descriptor.isHiddenServiceDir()); }
@Test @@ -1031,8 +1029,7 @@ public class ServerDescriptorImplTest { throws DescriptorParseException { ServerDescriptor descriptor = DescriptorBuilder .createWithHiddenServiceDirLine("hidden-service-dir 2 3"); - assertEquals(Arrays.asList(new Integer[] {2, 3}), - descriptor.getHiddenServiceDirVersions()); + assertTrue(descriptor.isHiddenServiceDir()); }
@Test
tor-commits@lists.torproject.org