[tor-commits] [collector/master] Implements task-19727: make exitlist url configurable and correct default setting.
karsten at torproject.org
karsten at torproject.org
Fri Jul 22 12:34:20 UTC 2016
commit 7dc17f8e14b3e87f26bd34e1d7c4649546e3476a
Author: iwakeh <iwakeh at torproject.org>
Date: Fri Jul 22 09:13:28 2016 +0200
Implements task-19727: make exitlist url configurable and correct default setting.
---
.../org/torproject/collector/conf/Configuration.java | 16 ++++++++++++++++
src/main/java/org/torproject/collector/conf/Key.java | 2 ++
.../collector/exitlists/ExitListDownloader.java | 4 +---
src/main/resources/collector.properties | 1 +
.../org/torproject/collector/conf/ConfigurationTest.java | 9 ++++++++-
5 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/torproject/collector/conf/Configuration.java b/src/main/java/org/torproject/collector/conf/Configuration.java
index 4e05ad4..9295811 100644
--- a/src/main/java/org/torproject/collector/conf/Configuration.java
+++ b/src/main/java/org/torproject/collector/conf/Configuration.java
@@ -3,6 +3,8 @@
package org.torproject.collector.conf;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
@@ -113,4 +115,18 @@ public class Configuration extends Properties {
}
}
+ /**
+ * Returns a {@code URL} property, e.g.
+ * {@code urlProperty = https://my.url.here}.
+ */
+ public URL getUrl(Key key) throws ConfigurationException {
+ try {
+ checkClass(key, URL.class);
+ return new URL(getProperty(key.name()));
+ } catch (MalformedURLException mue) {
+ throw new ConfigurationException("Corrupt property: " + key
+ + " reason: " + mue.getMessage(), mue);
+ }
+ }
+
}
diff --git a/src/main/java/org/torproject/collector/conf/Key.java b/src/main/java/org/torproject/collector/conf/Key.java
index 4f5df64..b4119b6 100644
--- a/src/main/java/org/torproject/collector/conf/Key.java
+++ b/src/main/java/org/torproject/collector/conf/Key.java
@@ -1,5 +1,6 @@
package org.torproject.collector.conf;
+import java.net.URL;
import java.nio.file.Path;
/**
@@ -9,6 +10,7 @@ import java.nio.file.Path;
public enum Key {
ExitlistOutputDirectory(Path.class),
+ ExitlistUrl(URL.class),
InstanceBaseUrl(String.class),
LockFilePath(Path.class),
ArchivePath(Path.class),
diff --git a/src/main/java/org/torproject/collector/exitlists/ExitListDownloader.java b/src/main/java/org/torproject/collector/exitlists/ExitListDownloader.java
index 70de74f..79fe19f 100644
--- a/src/main/java/org/torproject/collector/exitlists/ExitListDownloader.java
+++ b/src/main/java/org/torproject/collector/exitlists/ExitListDownloader.java
@@ -84,9 +84,7 @@ public class ExitListDownloader extends Thread {
sb.append("@type tordnsel 1.0\n");
sb.append("Downloaded " + dateTimeFormat.format(downloadedDate)
+ "\n");
- String exitAddressesUrl =
- "http://exitlist.torproject.org/exit-addresses";
- URL url = new URL(exitAddressesUrl);
+ URL url = config.getUrl(Key.ExitlistUrl);
HttpURLConnection huc = (HttpURLConnection) url.openConnection();
huc.setRequestMethod("GET");
huc.connect();
diff --git a/src/main/resources/collector.properties b/src/main/resources/collector.properties
index fb9e1b4..76ae6bd 100644
--- a/src/main/resources/collector.properties
+++ b/src/main/resources/collector.properties
@@ -98,6 +98,7 @@ SanitizedBridgesWriteDirectory = out/bridge-descriptors/
#
##
ExitlistOutputDirectory = out/exit-lists/
+ExitlistUrl = https://check.torproject.org/exit-addresses
######## Torperf downloader ########
#
diff --git a/src/test/java/org/torproject/collector/conf/ConfigurationTest.java b/src/test/java/org/torproject/collector/conf/ConfigurationTest.java
index 57dda75..ac9fd4f 100644
--- a/src/test/java/org/torproject/collector/conf/ConfigurationTest.java
+++ b/src/test/java/org/torproject/collector/conf/ConfigurationTest.java
@@ -22,7 +22,7 @@ public class ConfigurationTest {
public void testKeyCount() throws Exception {
assertEquals("The number of properties keys in enum Key changed."
+ "\n This test class should be adapted.",
- 32, Key.values().length);
+ 33, Key.values().length);
}
@Test()
@@ -129,6 +129,13 @@ public class ConfigurationTest {
}
@Test( expected = ConfigurationException.class)
+ public void testUrlValueException() throws Exception {
+ Configuration conf = new Configuration();
+ conf.load(new ByteArrayInputStream("ExitlistUrl = xxx://y.y.y".getBytes()));
+ conf.getUrl(Key.ExitlistUrl);
+ }
+
+ @Test( expected = ConfigurationException.class)
public void testIntValueException() throws Exception {
Configuration conf = new Configuration();
conf.load(new ByteArrayInputStream("BridgeDescriptorMappingsLimit = y7".getBytes()));
More information about the tor-commits
mailing list