Commit 368deb83 authored by Karsten Loesing's avatar Karsten Loesing
Browse files

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.
parent f826234e
# 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
......
......@@ -318,10 +318,20 @@ 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.
......
......@@ -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;
......
......@@ -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
......
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