tor-commits
Threads by month
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
August 2018
- 17 participants
- 2582 discussions
commit b8e3e95f00e5a6e0a8a8fbd424a7d0c4b5e91860
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Tue Aug 21 10:22:01 2018 +0200
Use parameterized log statements.
---
.../java/org/torproject/onionoo/cron/Main.java | 8 +--
.../torproject/onionoo/docs/BandwidthStatus.java | 4 +-
.../torproject/onionoo/docs/ClientsHistory.java | 22 +++---
.../org/torproject/onionoo/docs/ClientsStatus.java | 4 +-
.../org/torproject/onionoo/docs/DocumentStore.java | 82 ++++++++++------------
.../org/torproject/onionoo/docs/NodeStatus.java | 30 ++++----
.../org/torproject/onionoo/docs/UpdateStatus.java | 4 +-
.../org/torproject/onionoo/docs/UptimeHistory.java | 17 +++--
.../org/torproject/onionoo/docs/UptimeStatus.java | 4 +-
.../org/torproject/onionoo/docs/WeightsStatus.java | 12 ++--
.../org/torproject/onionoo/server/NodeIndexer.java | 4 +-
.../onionoo/server/PerformanceMetrics.java | 45 +++++-------
.../org/torproject/onionoo/server/ServerMain.java | 4 +-
.../onionoo/updater/DescriptorQueue.java | 21 +++---
.../onionoo/updater/DescriptorSource.java | 6 +-
.../torproject/onionoo/updater/LookupService.java | 60 +++++++---------
.../onionoo/updater/StatusUpdateRunner.java | 17 +++--
.../onionoo/writer/DocumentWriterRunner.java | 5 +-
18 files changed, 158 insertions(+), 191 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/cron/Main.java b/src/main/java/org/torproject/onionoo/cron/Main.java
index 9b34356..8e5812d 100644
--- a/src/main/java/org/torproject/onionoo/cron/Main.java
+++ b/src/main/java/org/torproject/onionoo/cron/Main.java
@@ -115,8 +115,8 @@ public class Main implements Runnable {
int initialDelay = (75 - currentMinute + currentMinute % 5) % 60;
/* Run after initialDelay delay and then every hour. */
- this.log.info("Periodic updater will start every hour at minute "
- + ((currentMinute + initialDelay) % 60) + ".");
+ this.log.info("Periodic updater will start every hour at minute {}.",
+ (currentMinute + initialDelay) % 60);
this.scheduler.scheduleAtFixedRate(mainRunnable, initialDelay, 60,
TimeUnit.MINUTES);
}
@@ -210,10 +210,10 @@ public class Main implements Runnable {
this.dwr.logStatistics();
}
if (this.dso != null) {
- this.log.info("Descriptor source\n" + this.dso.getStatsString());
+ this.log.info("Descriptor source\n{}", this.dso.getStatsString());
}
if (this.ds != null) {
- this.log.info("Document store\n" + this.ds.getStatsString());
+ this.log.info("Document store\n{}", this.ds.getStatsString());
}
}
diff --git a/src/main/java/org/torproject/onionoo/docs/BandwidthStatus.java b/src/main/java/org/torproject/onionoo/docs/BandwidthStatus.java
index 20e2e27..258e0e4 100644
--- a/src/main/java/org/torproject/onionoo/docs/BandwidthStatus.java
+++ b/src/main/java/org/torproject/onionoo/docs/BandwidthStatus.java
@@ -55,8 +55,8 @@ public class BandwidthStatus extends Document {
String line = s.nextLine();
String[] parts = line.split(" ");
if (parts.length != 6) {
- log.error("Illegal line '" + line + "' in bandwidth "
- + "history. Skipping this line.");
+ log.error("Illegal line '{}' in bandwidth history. Skipping this "
+ + "line.", line);
continue;
}
SortedMap<Long, long[]> history = parts[0].equals("r")
diff --git a/src/main/java/org/torproject/onionoo/docs/ClientsHistory.java b/src/main/java/org/torproject/onionoo/docs/ClientsHistory.java
index e4800e3..0efe181 100644
--- a/src/main/java/org/torproject/onionoo/docs/ClientsHistory.java
+++ b/src/main/java/org/torproject/onionoo/docs/ClientsHistory.java
@@ -73,29 +73,28 @@ public class ClientsHistory implements Comparable<ClientsHistory> {
String responseHistoryString) {
String[] parts = responseHistoryString.split(" ", 8);
if (parts.length != 8) {
- log.warn("Invalid number of space-separated strings in clients "
- + "history: '" + responseHistoryString + "'. Skipping");
+ log.warn("Invalid number of space-separated strings in clients history: "
+ + "'{}'. Skipping", responseHistoryString);
return null;
}
long startMillis = DateTimeHelper.parse(parts[0] + " " + parts[1]);
long endMillis = DateTimeHelper.parse(parts[2] + " " + parts[3]);
if (startMillis < 0L || endMillis < 0L) {
- log.warn("Invalid start or end timestamp in clients history: '"
- + responseHistoryString + "'. Skipping.");
+ log.warn("Invalid start or end timestamp in clients history: '{}'. "
+ + "Skipping.", responseHistoryString);
return null;
}
if (startMillis >= endMillis) {
- log.warn("Start timestamp must be smaller than end timestamp in "
- + "clients history: '" + responseHistoryString
- + "'. Skipping.");
+ log.warn("Start timestamp must be smaller than end timestamp in clients "
+ + "history: '{}'. Skipping.", responseHistoryString);
return null;
}
double totalResponses;
try {
totalResponses = Double.parseDouble(parts[4]);
} catch (NumberFormatException e) {
- log.warn("Invalid response number format in clients history: '"
- + responseHistoryString + "'. Skipping.");
+ log.warn("Invalid response number format in clients history: '{}'. "
+ + "Skipping.", responseHistoryString);
return null;
}
SortedMap<String, Double> responsesByCountry =
@@ -106,9 +105,8 @@ public class ClientsHistory implements Comparable<ClientsHistory> {
parseResponses(parts[7]);
if (responsesByCountry == null || responsesByTransport == null
|| responsesByVersion == null) {
- log.warn("Invalid format of responses by country, transport, or "
- + "version in clients history: '" + responseHistoryString
- + "'. Skipping.");
+ log.warn("Invalid format of responses by country, transport, or version "
+ + "in clients history: '{}'. Skipping.", responseHistoryString);
return null;
}
return new ClientsHistory(startMillis, endMillis, totalResponses,
diff --git a/src/main/java/org/torproject/onionoo/docs/ClientsStatus.java b/src/main/java/org/torproject/onionoo/docs/ClientsStatus.java
index 21a76e1..6de115b 100644
--- a/src/main/java/org/torproject/onionoo/docs/ClientsStatus.java
+++ b/src/main/java/org/torproject/onionoo/docs/ClientsStatus.java
@@ -44,8 +44,8 @@ public class ClientsStatus extends Document {
if (parsedLine != null) {
this.history.add(parsedLine);
} else {
- log.error("Could not parse clients history line '"
- + line + "'. Skipping.");
+ log.error("Could not parse clients history line '{}'. Skipping.",
+ line);
}
}
}
diff --git a/src/main/java/org/torproject/onionoo/docs/DocumentStore.java b/src/main/java/org/torproject/onionoo/docs/DocumentStore.java
index c5444c5..49176f8 100644
--- a/src/main/java/org/torproject/onionoo/docs/DocumentStore.java
+++ b/src/main/java/org/torproject/onionoo/docs/DocumentStore.java
@@ -135,8 +135,8 @@ public class DocumentStore {
this.listedFiles += parsedNodeStatuses.size();
this.listOperations++;
} catch (IOException e) {
- log.error("Could not read file '"
- + summaryFile.getAbsolutePath() + "'.", e);
+ log.error("Could not read file '{}'.", summaryFile.getAbsolutePath(),
+ e);
}
}
}
@@ -339,15 +339,15 @@ public class DocumentStore {
|| document instanceof UpdateStatus) {
documentString = document.toDocumentString();
} else {
- log.error("Serializing is not supported for type "
- + document.getClass().getName() + ".");
+ log.error("Serializing is not supported for type {}.",
+ document.getClass().getName());
return false;
}
try {
if (documentString.length() > ONE_MIBIBYTE) {
- log.warn("Attempting to store very large document file: path='"
- + documentFile.getAbsolutePath() + "', bytes="
- + documentString.length());
+ log.warn("Attempting to store very large document file: path='{}', "
+ + "bytes={}", documentFile.getAbsolutePath(),
+ documentString.length());
}
documentFile.getParentFile().mkdirs();
File documentTempFile = new File(
@@ -358,8 +358,8 @@ public class DocumentStore {
this.storedFiles++;
this.storedBytes += documentString.length();
} catch (IOException e) {
- log.error("Could not write file '"
- + documentFile.getAbsolutePath() + "'.", e);
+ log.error("Could not write file '{}'.", documentFile.getAbsolutePath(),
+ e);
return false;
}
return true;
@@ -419,10 +419,10 @@ public class DocumentStore {
String contact = null;
for (String orAddressAndPort : detailsDocument.getOrAddresses()) {
if (!orAddressAndPort.contains(":")) {
- log.warn("Attempt to create summary document from details "
- + "document for fingerprint " + fingerprint + " failed "
- + "because of invalid OR address/port: '" + orAddressAndPort
- + "'. Not returning a summary document in this case.");
+ log.warn("Attempt to create summary document from details document for "
+ + "fingerprint {} failed because of invalid OR address/port: '{}'. "
+ + "Not returning a summary document in this case.", fingerprint,
+ orAddressAndPort);
return null;
}
String orAddress = orAddressAndPort.substring(0,
@@ -464,9 +464,8 @@ public class DocumentStore {
/* Document file does not exist. That's okay. */
return null;
} else if (documentFile.isDirectory()) {
- log.error("Could not read file '"
- + documentFile.getAbsolutePath() + "', because it is a "
- + "directory.");
+ log.error("Could not read file '{}', because it is a directory.",
+ documentFile.getAbsolutePath());
return null;
}
String documentString;
@@ -487,14 +486,12 @@ public class DocumentStore {
this.retrievedFiles++;
this.retrievedBytes += documentString.length();
} catch (IOException e) {
- log.error("Could not read file '"
- + documentFile.getAbsolutePath() + "'.", e);
+ log.error("Could not read file '{}'.", documentFile.getAbsolutePath(), e);
return null;
}
if (documentString.length() > ONE_MIBIBYTE) {
- log.warn("Retrieved very large document file: path='"
- + documentFile.getAbsolutePath() + "', bytes="
- + documentString.length());
+ log.warn("Retrieved very large document file: path='{}', bytes={}",
+ documentFile.getAbsolutePath(), documentString.length());
}
T result = null;
if (!parse) {
@@ -517,8 +514,8 @@ public class DocumentStore {
return this.retrieveParsedDocumentFile(documentType, "{"
+ documentString + "}");
} else {
- log.error("Parsing is not supported for type "
- + documentType.getName() + ".");
+ log.error("Parsing is not supported for type {}.",
+ documentType.getName());
}
return result;
}
@@ -534,8 +531,8 @@ public class DocumentStore {
log.error(e.getMessage(), e);
}
if (result == null) {
- log.error("Could not initialize parsed status file of "
- + "type " + documentType.getName() + ".");
+ log.error("Could not initialize parsed status file of type {}.",
+ documentType.getName());
}
return result;
}
@@ -551,8 +548,8 @@ public class DocumentStore {
log.error(e.getMessage(), e);
}
if (result == null) {
- log.error("Could not initialize parsed document of type "
- + documentType.getName() + ".");
+ log.error("Could not initialize parsed document of type {}.",
+ documentType.getName());
}
return result;
}
@@ -568,8 +565,8 @@ public class DocumentStore {
log.error(e.getMessage(), e);
}
if (result == null) {
- log.error("Could not initialize unparsed document of type "
- + documentType.getName() + ".");
+ log.error("Could not initialize unparsed document of type {}.",
+ documentType.getName());
}
return result;
}
@@ -611,8 +608,7 @@ public class DocumentStore {
Class<T> documentType, String fingerprint) {
File documentFile = this.getDocumentFile(documentType, fingerprint);
if (documentFile == null || !documentFile.delete()) {
- log.error("Could not delete file '"
- + documentFile.getAbsolutePath() + "'.");
+ log.error("Could not delete file '{}'.", documentFile.getAbsolutePath());
return false;
}
this.removedFiles++;
@@ -624,9 +620,9 @@ public class DocumentStore {
File documentFile = null;
if (fingerprint == null && !documentType.equals(UpdateStatus.class)
&& !documentType.equals(UptimeStatus.class)) {
- log.warn("Attempted to locate a document file of type "
- + documentType.getName() + " without providing a fingerprint. "
- + "Such a file does not exist.");
+ log.warn("Attempted to locate a document file of type {} without "
+ + "providing a fingerprint. Such a file does not exist.",
+ documentType.getName());
return null;
}
File directory = null;
@@ -739,8 +735,8 @@ public class DocumentStore {
if (line != null) {
sb.append(line).append("\n");
} else {
- log.error("Could not serialize relay node status '"
- + relay.getFingerprint() + "'");
+ log.error("Could not serialize relay node status '{}'",
+ relay.getFingerprint());
}
}
for (NodeStatus bridge : cachedBridges.values()) {
@@ -748,8 +744,8 @@ public class DocumentStore {
if (line != null) {
sb.append(line).append("\n");
} else {
- log.error("Could not serialize bridge node status '"
- + bridge.getFingerprint() + "'");
+ log.error("Could not serialize bridge node status '{}'",
+ bridge.getFingerprint());
}
}
String documentString = sb.toString();
@@ -761,8 +757,7 @@ public class DocumentStore {
this.storedFiles++;
this.storedBytes += documentString.length();
} catch (IOException e) {
- log.error("Could not write file '"
- + summaryFile.getAbsolutePath() + "'.", e);
+ log.error("Could not write file '{}'.", summaryFile.getAbsolutePath(), e);
}
}
@@ -791,8 +786,8 @@ public class DocumentStore {
if (line != null) {
sb.append(line).append("\n");
} else {
- log.error("Could not serialize relay summary document '"
- + summaryDocument.getFingerprint() + "'");
+ log.error("Could not serialize relay summary document '{}'",
+ summaryDocument.getFingerprint());
}
}
String documentString = sb.toString();
@@ -805,8 +800,7 @@ public class DocumentStore {
this.storedFiles++;
this.storedBytes += documentString.length();
} catch (IOException e) {
- log.error("Could not write file '"
- + summaryFile.getAbsolutePath() + "'.", e);
+ log.error("Could not write file '{}'.", summaryFile.getAbsolutePath(), e);
}
}
diff --git a/src/main/java/org/torproject/onionoo/docs/NodeStatus.java b/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
index 1940198..9080b84 100644
--- a/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
+++ b/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
@@ -553,8 +553,8 @@ public class NodeStatus extends Document {
try {
String[] parts = documentString.trim().split("\t");
if (parts.length < 23) {
- log.error("Too few space-separated values in line '"
- + documentString.trim() + "'. Skipping.");
+ log.error("Too few space-separated values in line '{}'. Skipping.",
+ documentString.trim());
return null;
}
String fingerprint = parts[2];
@@ -568,8 +568,8 @@ public class NodeStatus extends Document {
if (addresses.contains(";")) {
String[] addressParts = addresses.split(";", -1);
if (addressParts.length != 3) {
- log.error("Invalid addresses entry in line '"
- + documentString.trim() + "'. Skipping.");
+ log.error("Invalid addresses entry in line '{}'. Skipping.",
+ documentString.trim());
return null;
}
address = addressParts[0];
@@ -590,8 +590,8 @@ public class NodeStatus extends Document {
long lastSeenMillis = DateTimeHelper.parse(parts[4] + " "
+ parts[5]);
if (lastSeenMillis < 0L) {
- log.error("Parse exception while parsing node status "
- + "line '" + documentString + "'. Skipping.");
+ log.error("Parse exception while parsing node status line '{}'. "
+ + "Skipping.", documentString);
return null;
} else if (lastSeenMillis == 0L) {
log.debug("Skipping node status with fingerprint {} that has so far "
@@ -617,8 +617,8 @@ public class NodeStatus extends Document {
}
long firstSeenMillis = DateTimeHelper.parse(parts[15] + " " + parts[16]);
if (firstSeenMillis < 0L) {
- log.error("Parse exception while parsing node status "
- + "line '" + documentString + "'. Skipping.");
+ log.error("Parse exception while parsing node status line '{}'. "
+ + "Skipping.", documentString);
return null;
}
nodeStatus.setFirstSeenMillis(firstSeenMillis);
@@ -627,8 +627,8 @@ public class NodeStatus extends Document {
lastChangedAddresses = DateTimeHelper.parse(parts[17] + " "
+ parts[18]);
if (lastChangedAddresses < 0L) {
- log.error("Parse exception while parsing node status "
- + "line '" + documentString + "'. Skipping.");
+ log.error("Parse exception while parsing node status line '{}'. "
+ + "Skipping.", documentString);
return null;
}
}
@@ -693,16 +693,14 @@ public class NodeStatus extends Document {
}
return nodeStatus;
} catch (NumberFormatException e) {
- log.error("Number format exception while parsing node "
- + "status line '" + documentString + "': " + e.getMessage()
- + ". Skipping.");
+ log.error("Number format exception while parsing node status line '{}'. "
+ + "Skipping.", documentString, e);
return null;
} catch (Exception e) {
/* This catch block is only here to handle yet unknown errors. It
* should go away once we're sure what kind of errors can occur. */
- log.error("Unknown exception while parsing node status "
- + "line '" + documentString + "': " + e.getMessage() + ". "
- + "Skipping.");
+ log.error("Unknown exception while parsing node status line '{}'. "
+ + "Skipping.", documentString, e);
return null;
}
}
diff --git a/src/main/java/org/torproject/onionoo/docs/UpdateStatus.java b/src/main/java/org/torproject/onionoo/docs/UpdateStatus.java
index 889a52d..11f32f9 100644
--- a/src/main/java/org/torproject/onionoo/docs/UpdateStatus.java
+++ b/src/main/java/org/torproject/onionoo/docs/UpdateStatus.java
@@ -25,8 +25,8 @@ public class UpdateStatus extends Document {
try {
this.updatedMillis = Long.parseLong(documentString.trim());
} catch (NumberFormatException e) {
- log.error("Could not parse timestamp '" + documentString + "'. "
- + "Setting to 1970-01-01 00:00:00.");
+ log.error("Could not parse timestamp '{}'. Setting to 1970-01-01 "
+ + "00:00:00.", documentString);
this.updatedMillis = 0L;
}
}
diff --git a/src/main/java/org/torproject/onionoo/docs/UptimeHistory.java b/src/main/java/org/torproject/onionoo/docs/UptimeHistory.java
index 0297b37..8bbb5b7 100644
--- a/src/main/java/org/torproject/onionoo/docs/UptimeHistory.java
+++ b/src/main/java/org/torproject/onionoo/docs/UptimeHistory.java
@@ -58,32 +58,31 @@ public class UptimeHistory implements Comparable<UptimeHistory> {
public static UptimeHistory fromString(String uptimeHistoryString) {
String[] parts = uptimeHistoryString.split(" ", -1);
if (parts.length < 3) {
- log.warn("Invalid number of space-separated strings in uptime "
- + "history: '" + uptimeHistoryString + "'. Skipping");
+ log.warn("Invalid number of space-separated strings in uptime history: "
+ + "'{}'. Skipping", uptimeHistoryString);
return null;
}
boolean relay = false;
if (parts[0].equalsIgnoreCase("r")) {
relay = true;
} else if (!parts[0].equals("b")) {
- log.warn("Invalid node type in uptime history: '"
- + uptimeHistoryString + "'. Supported types are 'r', 'R', and "
- + "'b'. Skipping.");
+ log.warn("Invalid node type in uptime history: '{}'. Supported types are "
+ + "'r', 'R', and 'b'. Skipping.", uptimeHistoryString);
return null;
}
long startMillis = DateTimeHelper.parse(parts[1],
DateTimeHelper.DATEHOUR_NOSPACE_FORMAT);
if (DateTimeHelper.NO_TIME_AVAILABLE == startMillis) {
- log.warn("Invalid start timestamp in uptime history: '"
- + uptimeHistoryString + "'. Skipping.");
+ log.warn("Invalid start timestamp in uptime history: '{}'. Skipping.",
+ uptimeHistoryString);
return null;
}
int uptimeHours;
try {
uptimeHours = Integer.parseInt(parts[2]);
} catch (NumberFormatException e) {
- log.warn("Invalid number format in uptime history: '"
- + uptimeHistoryString + "'. Skipping.");
+ log.warn("Invalid number format in uptime history: '{}'. Skipping.",
+ uptimeHistoryString);
return null;
}
SortedSet<String> flags = null;
diff --git a/src/main/java/org/torproject/onionoo/docs/UptimeStatus.java b/src/main/java/org/torproject/onionoo/docs/UptimeStatus.java
index bec5028..8fa5960 100644
--- a/src/main/java/org/torproject/onionoo/docs/UptimeStatus.java
+++ b/src/main/java/org/torproject/onionoo/docs/UptimeStatus.java
@@ -51,8 +51,8 @@ public class UptimeStatus extends Document {
this.bridgeHistory.add(parsedLine);
}
} else {
- log.error("Could not parse uptime history line '"
- + line + "'. Skipping.");
+ log.error("Could not parse uptime history line '{}'. Skipping.",
+ line);
}
}
}
diff --git a/src/main/java/org/torproject/onionoo/docs/WeightsStatus.java b/src/main/java/org/torproject/onionoo/docs/WeightsStatus.java
index f3b5452..c8b6fde 100644
--- a/src/main/java/org/torproject/onionoo/docs/WeightsStatus.java
+++ b/src/main/java/org/torproject/onionoo/docs/WeightsStatus.java
@@ -58,8 +58,8 @@ public class WeightsStatus extends Document {
continue;
}
if (parts.length != 9 && parts.length != 11) {
- log.error("Illegal line '" + line + "' in weights "
- + "status file. Skipping this line.");
+ log.error("Illegal line '{}' in weights status file. Skipping this "
+ + "line.", line);
continue;
}
if (parts[4].equals("NaN")) {
@@ -75,8 +75,8 @@ public class WeightsStatus extends Document {
break;
}
if (validAfterMillis > freshUntilMillis) {
- log.error("Illegal dates in '" + line + "' of weights "
- + "status file. Skipping.");
+ log.error("Illegal dates in '{}' of weights status file. Skipping.",
+ line);
break;
}
long[] interval = new long[] { validAfterMillis, freshUntilMillis };
@@ -91,8 +91,8 @@ public class WeightsStatus extends Document {
weights[6] = parseWeightDouble(parts[10]);
}
} catch (NumberFormatException e) {
- log.error("Could not parse weights values in line '" + line
- + "' while reading weights status file. Skipping.");
+ log.error("Could not parse weights values in line '{}' while reading "
+ + "weights status file. Skipping.", line);
break;
}
this.history.put(interval, weights);
diff --git a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
index 73b6777..8388f33 100644
--- a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
+++ b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
@@ -37,8 +37,8 @@ public class NodeIndexer implements ServletContextListener, Runnable {
File outDir = new File(System.getProperty("onionoo.basedir",
"/srv/onionoo.torproject.org/onionoo"), "out");
if (!outDir.exists() || !outDir.isDirectory()) {
- log.error("\n\n\tOut-dir not found! Expected directory: " + outDir
- + "\n\tSet system property 'onionoo.basedir'.");
+ log.error("\n\n\tOut-dir not found! Expected directory: {}"
+ + "\n\tSet system property 'onionoo.basedir'.", outDir);
System.exit(1);
}
DocumentStore documentStore = DocumentStoreFactory.getDocumentStore();
diff --git a/src/main/java/org/torproject/onionoo/server/PerformanceMetrics.java b/src/main/java/org/torproject/onionoo/server/PerformanceMetrics.java
index 98401ae..d0e7002 100644
--- a/src/main/java/org/torproject/onionoo/server/PerformanceMetrics.java
+++ b/src/main/java/org/torproject/onionoo/server/PerformanceMetrics.java
@@ -65,26 +65,19 @@ public class PerformanceMetrics {
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
- log.info("Request statistics ("
- + dateTimeFormat.format(lastLoggedMillis
- + LOG_INTERVAL_MILLIS) + ", " + (LOG_INTERVAL_SECONDS)
- + " s):");
- log.info(" Total processed requests: "
- + totalProcessedRequests);
- log.info(" Most frequently requested resource: "
- + requestsByResourceType);
- log.info(" Most frequently requested parameter "
- + "combinations: " + requestsByParameters);
- log.info(" Matching relays per request: "
- + matchingRelayDocuments);
- log.info(" Matching bridges per request: "
- + matchingBridgeDocuments);
- log.info(" Written characters per response: "
- + writtenChars);
- log.info(" Milliseconds to handle request: "
- + handleRequestMillis);
- log.info(" Milliseconds to build response: "
- + buildResponseMillis);
+ log.info("Request statistics ({}, {} s):",
+ dateTimeFormat.format(lastLoggedMillis + LOG_INTERVAL_MILLIS),
+ LOG_INTERVAL_SECONDS);
+ log.info(" Total processed requests: {}", totalProcessedRequests);
+ log.info(" Most frequently requested resource: {}",
+ requestsByResourceType);
+ log.info(" Most frequently requested parameter combinations: {}",
+ requestsByParameters);
+ log.info(" Matching relays per request: {}", matchingRelayDocuments);
+ log.info(" Matching bridges per request: {}", matchingBridgeDocuments);
+ log.info(" Written characters per response: {}", writtenChars);
+ log.info(" Milliseconds to handle request: {}", handleRequestMillis);
+ log.info(" Milliseconds to build response: {}", buildResponseMillis);
totalProcessedRequests.clear();
requestsByResourceType.clear();
requestsByParameters.clear();
@@ -101,9 +94,9 @@ public class PerformanceMetrics {
totalProcessedRequests.increment();
long handlingTime = parsedRequestMillis - receivedRequestMillis;
if (handlingTime > DateTimeHelper.ONE_SECOND) {
- log.warn("longer request handling: " + handlingTime + " ms for "
- + resourceType + " params: " + parameterKeys + " and "
- + charsWritten + " chars.");
+ log.warn("longer request handling: {} ms for {} params: {} and {} "
+ + "chars.", handlingTime, resourceType, parameterKeys,
+ charsWritten);
}
handleRequestMillis.addLong(handlingTime);
requestsByResourceType.addString(resourceType);
@@ -113,9 +106,9 @@ public class PerformanceMetrics {
writtenChars.addLong(charsWritten);
long responseTime = writtenResponseMillis - parsedRequestMillis;
if (responseTime > DateTimeHelper.ONE_SECOND) {
- log.warn("longer response building: " + responseTime + " ms for "
- + resourceType + " params: " + parameterKeys + " and "
- + charsWritten + " chars.");
+ log.warn("longer response building: {} ms for {} params: {} and {} "
+ + "chars.", responseTime, resourceType, parameterKeys,
+ charsWritten);
}
buildResponseMillis.addLong(responseTime);
}
diff --git a/src/main/java/org/torproject/onionoo/server/ServerMain.java b/src/main/java/org/torproject/onionoo/server/ServerMain.java
index a60974b..03a4f18 100644
--- a/src/main/java/org/torproject/onionoo/server/ServerMain.java
+++ b/src/main/java/org/torproject/onionoo/server/ServerMain.java
@@ -18,14 +18,14 @@ public class ServerMain {
public static void main(String[] args) {
try {
Resource onionooXml = Resource.newSystemResource("jetty.xml");
- log.info("Reading configuration from '" + onionooXml + "'.");
+ log.info("Reading configuration from '{}'.", onionooXml);
XmlConfiguration configuration = new XmlConfiguration(
onionooXml.getInputStream());
Server server = (Server) configuration.configure();
server.start();
server.join();
} catch (Exception ex) {
- log.error("Exiting, because of: " + ex.getMessage(), ex);
+ log.error("Exiting, because of: {}", ex.getMessage(), ex);
System.exit(1);
}
}
diff --git a/src/main/java/org/torproject/onionoo/updater/DescriptorQueue.java b/src/main/java/org/torproject/onionoo/updater/DescriptorQueue.java
index d00b8b2..76e46a2 100644
--- a/src/main/java/org/torproject/onionoo/updater/DescriptorQueue.java
+++ b/src/main/java/org/torproject/onionoo/updater/DescriptorQueue.java
@@ -89,14 +89,14 @@ class DescriptorQueue {
String[] parts = line.split(" ", 2);
excludedFiles.put(parts[1], Long.parseLong(parts[0]));
} catch (NumberFormatException e) {
- log.error("Illegal line '" + line + "' in parse "
- + "history. Skipping line.");
+ log.error("Illegal line '{}' in parse history. Skipping line.",
+ line);
}
}
} catch (IOException e) {
- log.error("Could not read history file '"
- + this.historyFile.getAbsolutePath() + "'. Not excluding "
- + "descriptors in this execution.", e);
+ log.error("Could not read history file '{}'. Not excluding "
+ + "descriptors in this execution.",
+ this.historyFile.getAbsolutePath(), e);
return;
}
this.historySizeBefore = excludedFiles.size();
@@ -128,9 +128,8 @@ class DescriptorQueue {
+ "\n");
}
} catch (IOException e) {
- log.error("Could not write history file '"
- + this.historyFile.getAbsolutePath() + "'. Not excluding "
- + "descriptors in next execution.");
+ log.error("Could not write history file '{}'. Not excluding descriptors "
+ + "in next execution.", this.historyFile.getAbsolutePath());
}
}
@@ -144,9 +143,9 @@ class DescriptorQueue {
this.descriptors = this.descriptorReader.readDescriptors(
this.directory).iterator();
} else {
- log.error("Directory " + this.directory.getAbsolutePath()
- + " either does not exist or is not a directory. Not adding "
- + "to descriptor reader.");
+ log.error("Directory {} either does not exist or is not a directory. "
+ + "Not adding to descriptor reader.",
+ this.directory.getAbsolutePath());
return null;
}
}
diff --git a/src/main/java/org/torproject/onionoo/updater/DescriptorSource.java b/src/main/java/org/torproject/onionoo/updater/DescriptorSource.java
index 64bb0e4..65d342a 100644
--- a/src/main/java/org/torproject/onionoo/updater/DescriptorSource.java
+++ b/src/main/java/org/torproject/onionoo/updater/DescriptorSource.java
@@ -201,9 +201,9 @@ public class DescriptorSource {
}
}
if (descriptorType == null) {
- log.warn("Unrecognized descriptor in "
- + this.inArchiveDir.getAbsolutePath() + " with annotations "
- + descriptor.getAnnotations() + ". Skipping descriptor.");
+ log.warn("Unrecognized descriptor in {} with annotations {}. Skipping "
+ + "descriptor.", this.inArchiveDir.getAbsolutePath(),
+ descriptor.getAnnotations());
continue;
}
for (DescriptorListener descriptorListener :
diff --git a/src/main/java/org/torproject/onionoo/updater/LookupService.java b/src/main/java/org/torproject/onionoo/updater/LookupService.java
index dd35b59..495fec7 100644
--- a/src/main/java/org/torproject/onionoo/updater/LookupService.java
+++ b/src/main/java/org/torproject/onionoo/updater/LookupService.java
@@ -133,9 +133,8 @@ public class LookupService {
while ((line = br.readLine()) != null) {
String[] parts = line.split(",", -1);
if (parts.length < 9) {
- log.error("Illegal line '" + line + "' in "
- + this.geoLite2CityBlocksIPv4CsvFile.getAbsolutePath()
- + ".");
+ log.error("Illegal line '{}' in {}.", line,
+ this.geoLite2CityBlocksIPv4CsvFile.getAbsolutePath());
return lookupResults;
}
try {
@@ -143,18 +142,15 @@ public class LookupService {
String startAddressString = networkAddressAndMask[0];
long startIpNum = this.parseAddressString(startAddressString);
if (startIpNum < 0L) {
- log.error("Illegal IP address in '" + line + "' in "
- + this.geoLite2CityBlocksIPv4CsvFile.getAbsolutePath()
- + ".");
+ log.error("Illegal IP address in '{}' in {}.", line,
+ this.geoLite2CityBlocksIPv4CsvFile.getAbsolutePath());
return lookupResults;
}
int networkMaskLength = networkAddressAndMask.length < 2 ? 0
: Integer.parseInt(networkAddressAndMask[1]);
if (networkMaskLength < 8 || networkMaskLength > 32) {
- log.error("Missing or illegal network mask in '" + line
- + "' in "
- + this.geoLite2CityBlocksIPv4CsvFile.getAbsolutePath()
- + ".");
+ log.error("Missing or illegal network mask in '{}' in {}.", line,
+ this.geoLite2CityBlocksIPv4CsvFile.getAbsolutePath());
return lookupResults;
}
if (parts[1].length() == 0 && parts[2].length() == 0) {
@@ -175,17 +171,14 @@ public class LookupService {
}
}
} catch (NumberFormatException e) {
- log.error("Number format exception while parsing line '" + line
- + "' in "
- + this.geoLite2CityBlocksIPv4CsvFile.getAbsolutePath()
- + ".", e);
+ log.error("Number format exception while parsing line '{}' in {}.",
+ line, this.geoLite2CityBlocksIPv4CsvFile.getAbsolutePath(), e);
return lookupResults;
}
}
} catch (IOException e) {
- log.error("I/O exception while reading "
- + this.geoLite2CityBlocksIPv4CsvFile.getAbsolutePath()
- + ": " + e);
+ log.error("I/O exception while reading {}: {}",
+ this.geoLite2CityBlocksIPv4CsvFile.getAbsolutePath(), e);
return lookupResults;
}
@@ -198,9 +191,8 @@ public class LookupService {
while ((line = br.readLine()) != null) {
String[] parts = line.replaceAll("\"", "").split(",", 13);
if (parts.length != 13) {
- log.error("Illegal line '" + line + "' in "
- + this.geoLite2CityLocationsEnCsvFile.getAbsolutePath()
- + ".");
+ log.error("Illegal line '{}' in {}.", line,
+ this.geoLite2CityLocationsEnCsvFile.getAbsolutePath());
return lookupResults;
}
@@ -210,17 +202,14 @@ public class LookupService {
blockLocations.put(locId, line);
}
} catch (NumberFormatException e) {
- log.error("Number format exception while parsing line "
- + "'" + line + "' in "
- + this.geoLite2CityLocationsEnCsvFile.getAbsolutePath()
- + ".");
+ log.error("Number format exception while parsing line '{}' in {}.",
+ line, this.geoLite2CityLocationsEnCsvFile.getAbsolutePath());
return lookupResults;
}
}
} catch (IOException e) {
- log.error("I/O exception while reading "
- + this.geoLite2CityLocationsEnCsvFile.getAbsolutePath()
- + ": " + e);
+ log.error("I/O exception while reading {}: {}",
+ this.geoLite2CityLocationsEnCsvFile.getAbsolutePath(), e);
return lookupResults;
}
@@ -236,15 +225,15 @@ public class LookupService {
while ((line = br.readLine()) != null) {
String[] parts = line.replaceAll("\"", "").split(",", 3);
if (parts.length != 3) {
- log.error("Illegal line '" + line + "' in "
- + geoIpAsNum2CsvFile.getAbsolutePath() + ".");
+ log.error("Illegal line '{}' in {}.", line,
+ geoIpAsNum2CsvFile.getAbsolutePath());
return lookupResults;
}
try {
long startIpNum = Long.parseLong(parts[0]);
if (startIpNum <= previousStartIpNum) {
- log.error("Line '" + line + "' not sorted in "
- + geoIpAsNum2CsvFile.getAbsolutePath() + ".");
+ log.error("Line '{}' not sorted in {}.", line,
+ geoIpAsNum2CsvFile.getAbsolutePath());
return lookupResults;
}
previousStartIpNum = startIpNum;
@@ -274,15 +263,14 @@ public class LookupService {
break;
}
} catch (NumberFormatException e) {
- log.error("Number format exception while parsing line "
- + "'" + line + "' in "
- + geoIpAsNum2CsvFile.getAbsolutePath() + ".");
+ log.error("Number format exception while parsing line '{}' in {}.",
+ line, geoIpAsNum2CsvFile.getAbsolutePath());
return lookupResults;
}
}
} catch (IOException e) {
- log.error("I/O exception while reading "
- + geoIpAsNum2CsvFile.getAbsolutePath() + ": " + e);
+ log.error("I/O exception while reading {}: {}",
+ geoIpAsNum2CsvFile.getAbsolutePath(), e);
return lookupResults;
}
diff --git a/src/main/java/org/torproject/onionoo/updater/StatusUpdateRunner.java b/src/main/java/org/torproject/onionoo/updater/StatusUpdateRunner.java
index 19d5c4b..d7eddfe 100644
--- a/src/main/java/org/torproject/onionoo/updater/StatusUpdateRunner.java
+++ b/src/main/java/org/torproject/onionoo/updater/StatusUpdateRunner.java
@@ -37,10 +37,9 @@ public class StatusUpdateRunner {
/** Lets each configured status updater update its status files. */
public void updateStatuses() {
for (StatusUpdater su : this.statusUpdaters) {
- log.debug("Begin update of " + su.getClass().getSimpleName());
+ log.debug("Begin update of {}", su.getClass().getSimpleName());
su.updateStatuses();
- log.info(su.getClass().getSimpleName()
- + " updated status files");
+ log.info("{} updated status files", su.getClass().getSimpleName());
}
}
@@ -49,14 +48,14 @@ public class StatusUpdateRunner {
for (StatusUpdater su : this.statusUpdaters) {
String statsString = su.getStatsString();
if (statsString != null) {
- LoggerFactory.getLogger("statistics").info(
- su.getClass().getSimpleName() + "\n" + statsString);
+ LoggerFactory.getLogger("statistics").info("{}\n{}",
+ su.getClass().getSimpleName(), statsString);
}
}
- LoggerFactory.getLogger("statistics").info("GeoIP lookup service\n"
- + this.ls.getStatsString());
- LoggerFactory.getLogger("statistics").info("Reverse domain name "
- + "resolver\n" + this.rdnr.getStatsString());
+ LoggerFactory.getLogger("statistics")
+ .info("GeoIP lookup service\n{}", this.ls.getStatsString());
+ LoggerFactory.getLogger("statistics")
+ .info("Reverse domain name resolver\n{}", this.rdnr.getStatsString());
}
}
diff --git a/src/main/java/org/torproject/onionoo/writer/DocumentWriterRunner.java b/src/main/java/org/torproject/onionoo/writer/DocumentWriterRunner.java
index 4ab8f7e..d69c129 100644
--- a/src/main/java/org/torproject/onionoo/writer/DocumentWriterRunner.java
+++ b/src/main/java/org/torproject/onionoo/writer/DocumentWriterRunner.java
@@ -34,7 +34,7 @@ public class DocumentWriterRunner {
public void writeDocuments() {
long mostRecentStatusMillis = retrieveMostRecentStatusMillis();
for (DocumentWriter dw : this.documentWriters) {
- log.debug("Writing " + dw.getClass().getSimpleName());
+ log.debug("Writing {}", dw.getClass().getSimpleName());
dw.writeDocuments(mostRecentStatusMillis);
}
}
@@ -56,8 +56,7 @@ public class DocumentWriterRunner {
for (DocumentWriter dw : this.documentWriters) {
String statsString = dw.getStatsString();
if (statsString != null) {
- log.info(dw.getClass().getSimpleName() + "\n"
- + statsString);
+ log.info("{}\n{}", dw.getClass().getSimpleName(), statsString);
}
}
}
1
0
[onionoo/master] Use Map.putIfAbsent and Map.getOrDefault where possible.
by karsten@torproject.org 27 Aug '18
by karsten@torproject.org 27 Aug '18
27 Aug '18
commit c51c4f20a56e56ff3d72b129666b824712f02d10
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Tue Aug 21 14:46:16 2018 +0200
Use Map.putIfAbsent and Map.getOrDefault where possible.
---
.../torproject/onionoo/docs/ClientsHistory.java | 9 +--
.../org/torproject/onionoo/docs/NodeStatus.java | 7 +--
.../onionoo/server/MostFrequentString.java | 17 ++----
.../org/torproject/onionoo/server/NodeIndexer.java | 68 ++++++----------------
.../onionoo/updater/ClientsStatusUpdater.java | 8 +--
.../onionoo/updater/DescriptorSource.java | 5 +-
.../onionoo/updater/NodeDetailsStatusUpdater.java | 20 ++-----
.../onionoo/updater/UptimeStatusUpdater.java | 9 +--
.../onionoo/docs/DummyDocumentStore.java | 4 +-
.../onionoo/server/ResourceServletTest.java | 5 +-
.../onionoo/updater/DummyDescriptorSource.java | 9 +--
11 files changed, 42 insertions(+), 119 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/docs/ClientsHistory.java b/src/main/java/org/torproject/onionoo/docs/ClientsHistory.java
index 0efe181..1890060 100644
--- a/src/main/java/org/torproject/onionoo/docs/ClientsHistory.java
+++ b/src/main/java/org/torproject/onionoo/docs/ClientsHistory.java
@@ -181,12 +181,9 @@ public class ClientsHistory implements Comparable<ClientsHistory> {
SortedMap<String, Double> thisResponses,
SortedMap<String, Double> otherResponses) {
for (Map.Entry<String, Double> e : otherResponses.entrySet()) {
- if (thisResponses.containsKey(e.getKey())) {
- thisResponses.put(e.getKey(), thisResponses.get(e.getKey())
- + e.getValue());
- } else {
- thisResponses.put(e.getKey(), e.getValue());
- }
+ thisResponses.putIfAbsent(e.getKey(), 0.0);
+ thisResponses.put(e.getKey(), thisResponses.get(e.getKey())
+ + e.getValue());
}
}
diff --git a/src/main/java/org/torproject/onionoo/docs/NodeStatus.java b/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
index 9080b84..32965dd 100644
--- a/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
+++ b/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
@@ -335,11 +335,8 @@ public class NodeStatus extends Document {
addressesAndPorts.add(address + ":" + dirPort);
}
addressesAndPorts.addAll(orAddressesAndPorts);
- if (this.lastAddresses.containsKey(lastSeenMillis)) {
- this.lastAddresses.get(lastSeenMillis).addAll(addressesAndPorts);
- } else {
- this.lastAddresses.put(lastSeenMillis, addressesAndPorts);
- }
+ this.lastAddresses.putIfAbsent(lastSeenMillis, new TreeSet<>());
+ this.lastAddresses.get(lastSeenMillis).addAll(addressesAndPorts);
}
/** Returns the time in milliseconds since the epoch when addresses or
diff --git a/src/main/java/org/torproject/onionoo/server/MostFrequentString.java b/src/main/java/org/torproject/onionoo/server/MostFrequentString.java
index 3d4d4c2..a6b7cb5 100644
--- a/src/main/java/org/torproject/onionoo/server/MostFrequentString.java
+++ b/src/main/java/org/torproject/onionoo/server/MostFrequentString.java
@@ -3,7 +3,6 @@
package org.torproject.onionoo.server;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -17,12 +16,8 @@ class MostFrequentString {
Map<String, Integer> stringFrequencies = new HashMap<>();
void addString(String string) {
- if (!this.stringFrequencies.containsKey(string)) {
- this.stringFrequencies.put(string, 1);
- } else {
- this.stringFrequencies.put(string,
- this.stringFrequencies.get(string) + 1);
- }
+ this.stringFrequencies.put(string,
+ this.stringFrequencies.getOrDefault(string, 0) + 1);
}
@Override
@@ -33,12 +28,8 @@ class MostFrequentString {
return "null (0)";
}
for (Map.Entry<String, Integer> e : stringFrequencies.entrySet()) {
- if (!sortedFrequencies.containsKey(e.getValue())) {
- sortedFrequencies.put(e.getValue(), new TreeSet<>(
- Arrays.asList(e.getKey())));
- } else {
- sortedFrequencies.get(e.getValue()).add(e.getKey());
- }
+ sortedFrequencies.putIfAbsent(e.getValue(), new TreeSet<>());
+ sortedFrequencies.get(e.getValue()).add(e.getKey());
}
StringBuilder sb = new StringBuilder();
int stringsToAdd = 3;
diff --git a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
index 8388f33..80418aa 100644
--- a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
+++ b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
@@ -209,10 +209,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
* installations in international waters. */
countryCode = "xz";
}
- if (!newRelaysByCountryCode.containsKey(countryCode)) {
- newRelaysByCountryCode.put(countryCode,
- new HashSet<>());
- }
+ newRelaysByCountryCode.putIfAbsent(countryCode, new HashSet<>());
newRelaysByCountryCode.get(countryCode).add(fingerprint);
newRelaysByCountryCode.get(countryCode).add(hashedFingerprint);
String asNumber;
@@ -225,22 +222,16 @@ public class NodeIndexer implements ServletContextListener, Runnable {
* shouldn't appear in any lookup databases. */
asNumber = "AS0";
}
- if (!newRelaysByAsNumber.containsKey(asNumber)) {
- newRelaysByAsNumber.put(asNumber, new HashSet<>());
- }
+ newRelaysByAsNumber.putIfAbsent(asNumber, new HashSet<>());
newRelaysByAsNumber.get(asNumber).add(fingerprint);
newRelaysByAsNumber.get(asNumber).add(hashedFingerprint);
String asName = entry.getAsName();
- if (!newRelaysByAsName.containsKey(asName)) {
- newRelaysByAsName.put(asName, new HashSet<>());
- }
+ newRelaysByAsName.putIfAbsent(asName, new HashSet<>());
newRelaysByAsName.get(asName).add(fingerprint);
newRelaysByAsName.get(asName).add(hashedFingerprint);
for (String flag : entry.getRelayFlags()) {
String flagLowerCase = flag.toLowerCase();
- if (!newRelaysByFlag.containsKey(flagLowerCase)) {
- newRelaysByFlag.put(flagLowerCase, new HashSet<>());
- }
+ newRelaysByFlag.putIfAbsent(flagLowerCase, new HashSet<>());
newRelaysByFlag.get(flagLowerCase).add(fingerprint);
newRelaysByFlag.get(flagLowerCase).add(hashedFingerprint);
}
@@ -258,42 +249,31 @@ public class NodeIndexer implements ServletContextListener, Runnable {
int daysSinceFirstSeen = (int) ((
(specialTime < 0 ? System.currentTimeMillis() : specialTime)
- entry.getFirstSeenMillis()) / ONE_DAY);
- if (!newRelaysByFirstSeenDays.containsKey(daysSinceFirstSeen)) {
- newRelaysByFirstSeenDays.put(daysSinceFirstSeen,
- new HashSet<>());
- }
+ newRelaysByFirstSeenDays.putIfAbsent(daysSinceFirstSeen, new HashSet<>());
newRelaysByFirstSeenDays.get(daysSinceFirstSeen).add(fingerprint);
newRelaysByFirstSeenDays.get(daysSinceFirstSeen).add(
hashedFingerprint);
int daysSinceLastSeen = (int) ((
(specialTime < 0 ? System.currentTimeMillis() : specialTime)
- entry.getLastSeenMillis()) / ONE_DAY);
- if (!newRelaysByLastSeenDays.containsKey(daysSinceLastSeen)) {
- newRelaysByLastSeenDays.put(daysSinceLastSeen,
- new HashSet<>());
- }
+ newRelaysByLastSeenDays.putIfAbsent(daysSinceLastSeen, new HashSet<>());
newRelaysByLastSeenDays.get(daysSinceLastSeen).add(fingerprint);
newRelaysByLastSeenDays.get(daysSinceLastSeen).add(
hashedFingerprint);
String contact = entry.getContact();
- if (!newRelaysByContact.containsKey(contact)) {
- newRelaysByContact.put(contact, new HashSet<>());
- }
+ newRelaysByContact.putIfAbsent(contact, new HashSet<>());
newRelaysByContact.get(contact).add(fingerprint);
newRelaysByContact.get(contact).add(hashedFingerprint);
String version = entry.getVersion();
if (null != version) {
- if (!newRelaysByVersion.containsKey(version)) {
- newRelaysByVersion.put(version, new HashSet<>());
- }
+ newRelaysByVersion.putIfAbsent(version, new HashSet<>());
newRelaysByVersion.get(version).add(fingerprint);
newRelaysByVersion.get(version).add(hashedFingerprint);
}
String operatingSystem = entry.getOperatingSystem();
if (null != operatingSystem) {
- if (!newRelaysByOperatingSystem.containsKey(operatingSystem)) {
- newRelaysByOperatingSystem.put(operatingSystem, new HashSet<>());
- }
+ newRelaysByOperatingSystem.putIfAbsent(operatingSystem,
+ new HashSet<>());
newRelaysByOperatingSystem.get(operatingSystem).add(fingerprint);
newRelaysByOperatingSystem.get(operatingSystem).add(hashedFingerprint);
}
@@ -308,9 +288,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
}
for (String hostName : allHostNames) {
String hostNameLowerCase = hostName.toLowerCase();
- if (!newRelaysByHostName.containsKey(hostNameLowerCase)) {
- newRelaysByHostName.put(hostNameLowerCase, new HashSet<>());
- }
+ newRelaysByHostName.putIfAbsent(hostNameLowerCase, new HashSet<>());
newRelaysByHostName.get(hostNameLowerCase).add(fingerprint);
newRelaysByHostName.get(hostNameLowerCase).add(hashedFingerprint);
}
@@ -346,9 +324,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
entry);
for (String flag : entry.getRelayFlags()) {
String flagLowerCase = flag.toLowerCase();
- if (!newBridgesByFlag.containsKey(flagLowerCase)) {
- newBridgesByFlag.put(flagLowerCase, new HashSet<>());
- }
+ newBridgesByFlag.putIfAbsent(flagLowerCase, new HashSet<>());
newBridgesByFlag.get(flagLowerCase).add(hashedFingerprint);
newBridgesByFlag.get(flagLowerCase).add(
hashedHashedFingerprint);
@@ -356,10 +332,8 @@ public class NodeIndexer implements ServletContextListener, Runnable {
int daysSinceFirstSeen = (int) ((
(specialTime < 0 ? System.currentTimeMillis() : specialTime)
- entry.getFirstSeenMillis()) / ONE_DAY);
- if (!newBridgesByFirstSeenDays.containsKey(daysSinceFirstSeen)) {
- newBridgesByFirstSeenDays.put(daysSinceFirstSeen,
- new HashSet<>());
- }
+ newBridgesByFirstSeenDays.putIfAbsent(daysSinceFirstSeen,
+ new HashSet<>());
newBridgesByFirstSeenDays.get(daysSinceFirstSeen).add(
hashedFingerprint);
newBridgesByFirstSeenDays.get(daysSinceFirstSeen).add(
@@ -367,27 +341,21 @@ public class NodeIndexer implements ServletContextListener, Runnable {
int daysSinceLastSeen = (int) ((
(specialTime < 0 ? System.currentTimeMillis() : specialTime)
- entry.getLastSeenMillis()) / ONE_DAY);
- if (!newBridgesByLastSeenDays.containsKey(daysSinceLastSeen)) {
- newBridgesByLastSeenDays.put(daysSinceLastSeen,
- new HashSet<>());
- }
+ newBridgesByLastSeenDays.putIfAbsent(daysSinceLastSeen, new HashSet<>());
newBridgesByLastSeenDays.get(daysSinceLastSeen).add(
hashedFingerprint);
newBridgesByLastSeenDays.get(daysSinceLastSeen).add(
hashedHashedFingerprint);
String version = entry.getVersion();
if (null != version) {
- if (!newBridgesByVersion.containsKey(version)) {
- newBridgesByVersion.put(version, new HashSet<>());
- }
+ newBridgesByVersion.putIfAbsent(version, new HashSet<>());
newBridgesByVersion.get(version).add(hashedFingerprint);
newBridgesByVersion.get(version).add(hashedHashedFingerprint);
}
String operatingSystem = entry.getOperatingSystem();
if (null != operatingSystem) {
- if (!newBridgesByOperatingSystem.containsKey(operatingSystem)) {
- newBridgesByOperatingSystem.put(operatingSystem, new HashSet<>());
- }
+ newBridgesByOperatingSystem.putIfAbsent(operatingSystem,
+ new HashSet<>());
newBridgesByOperatingSystem.get(operatingSystem)
.add(hashedFingerprint);
newBridgesByOperatingSystem.get(operatingSystem)
diff --git a/src/main/java/org/torproject/onionoo/updater/ClientsStatusUpdater.java b/src/main/java/org/torproject/onionoo/updater/ClientsStatusUpdater.java
index 205e391..e7ccd0b 100644
--- a/src/main/java/org/torproject/onionoo/updater/ClientsStatusUpdater.java
+++ b/src/main/java/org/torproject/onionoo/updater/ClientsStatusUpdater.java
@@ -114,12 +114,8 @@ public class ClientsStatusUpdater implements DescriptorListener,
ClientsHistory newResponseHistory = new ClientsHistory(
startMillis, endMillis, totalResponses, responsesByCountry,
responsesByTransport, responsesByVersion);
- if (!this.newResponses.containsKey(hashedFingerprint)) {
- this.newResponses.put(hashedFingerprint,
- new TreeSet<>());
- }
- this.newResponses.get(hashedFingerprint).add(
- newResponseHistory);
+ this.newResponses.putIfAbsent(hashedFingerprint, new TreeSet<>());
+ this.newResponses.get(hashedFingerprint).add(newResponseHistory);
}
}
diff --git a/src/main/java/org/torproject/onionoo/updater/DescriptorSource.java b/src/main/java/org/torproject/onionoo/updater/DescriptorSource.java
index 65d342a..afa27a5 100644
--- a/src/main/java/org/torproject/onionoo/updater/DescriptorSource.java
+++ b/src/main/java/org/torproject/onionoo/updater/DescriptorSource.java
@@ -81,10 +81,7 @@ public class DescriptorSource {
/** Registers a descriptor listener for a given descriptor type. */
public void registerDescriptorListener(DescriptorListener listener,
DescriptorType descriptorType) {
- if (!this.descriptorListeners.containsKey(descriptorType)) {
- this.descriptorListeners.put(descriptorType,
- new HashSet<>());
- }
+ this.descriptorListeners.putIfAbsent(descriptorType, new HashSet<>());
this.descriptorListeners.get(descriptorType).add(listener);
}
diff --git a/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java b/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
index 1cd989d..9bb4ab7 100644
--- a/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
+++ b/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
@@ -223,16 +223,11 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
if (scanMillis < this.now - DateTimeHelper.ONE_DAY) {
continue;
}
- if (!this.exitListEntries.containsKey(fingerprint)) {
- this.exitListEntries.put(fingerprint, new HashMap<>());
- }
+ this.exitListEntries.putIfAbsent(fingerprint, new HashMap<>());
String exitAddress = exitAddressScanMillis.getKey();
- if (!this.exitListEntries.get(fingerprint).containsKey(
- exitAddress)
- || this.exitListEntries.get(fingerprint).get(exitAddress)
+ if (this.exitListEntries.get(fingerprint).getOrDefault(exitAddress, 0L)
< scanMillis) {
- this.exitListEntries.get(fingerprint).put(exitAddress,
- scanMillis);
+ this.exitListEntries.get(fingerprint).put(exitAddress, scanMillis);
}
}
}
@@ -288,14 +283,12 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
nodeStatus.setVersion(version);
}
if (entry.getUnmeasured()) {
- if (!this.lastSeenUnmeasured.containsKey(fingerprint)
- || this.lastSeenUnmeasured.get(fingerprint)
+ if (this.lastSeenUnmeasured.getOrDefault(fingerprint, 0L)
< validAfterMillis) {
this.lastSeenUnmeasured.put(fingerprint, validAfterMillis);
}
} else if (consensus.getConsensusMethod() >= 17) {
- if (!this.lastSeenMeasured.containsKey(fingerprint)
- || this.lastSeenMeasured.get(fingerprint)
+ if (this.lastSeenMeasured.getOrDefault(fingerprint, 0L)
< validAfterMillis) {
this.lastSeenMeasured.put(fingerprint, validAfterMillis);
}
@@ -846,8 +839,7 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
this.exitListEntries.get(fingerprint).entrySet()) {
String exitAddress = e.getKey();
long scanMillis = e.getValue();
- if (!exitAddresses.containsKey(exitAddress)
- || exitAddresses.get(exitAddress) < scanMillis) {
+ if (exitAddresses.getOrDefault(exitAddress, 0L) < scanMillis) {
exitAddresses.put(exitAddress, scanMillis);
}
}
diff --git a/src/main/java/org/torproject/onionoo/updater/UptimeStatusUpdater.java b/src/main/java/org/torproject/onionoo/updater/UptimeStatusUpdater.java
index f1ff574..58cd2fb 100644
--- a/src/main/java/org/torproject/onionoo/updater/UptimeStatusUpdater.java
+++ b/src/main/java/org/torproject/onionoo/updater/UptimeStatusUpdater.java
@@ -103,10 +103,7 @@ public class UptimeStatusUpdater implements DescriptorListener,
for (NetworkStatusEntry entry :
consensus.getStatusEntries().values()) {
String fingerprint = entry.getFingerprint();
- if (!this.newRunningRelays.containsKey(fingerprint)) {
- this.newRunningRelays.put(fingerprint,
- new TreeMap<>());
- }
+ this.newRunningRelays.putIfAbsent(fingerprint, new TreeMap<>());
this.newRunningRelays.get(fingerprint).put(dateHourMillis,
new Flags(entry.getFlags()));
}
@@ -124,9 +121,7 @@ public class UptimeStatusUpdater implements DescriptorListener,
long dateHourMillis = (status.getPublishedMillis()
/ DateTimeHelper.ONE_HOUR) * DateTimeHelper.ONE_HOUR;
for (String fingerprint : fingerprints) {
- if (!this.newRunningBridges.containsKey(fingerprint)) {
- this.newRunningBridges.put(fingerprint, new TreeSet<>());
- }
+ this.newRunningBridges.putIfAbsent(fingerprint, new TreeSet<>());
this.newRunningBridges.get(fingerprint).add(dateHourMillis);
}
this.newBridgeStatuses.add(dateHourMillis);
diff --git a/src/test/java/org/torproject/onionoo/docs/DummyDocumentStore.java b/src/test/java/org/torproject/onionoo/docs/DummyDocumentStore.java
index 3c79235..a8f51ae 100644
--- a/src/test/java/org/torproject/onionoo/docs/DummyDocumentStore.java
+++ b/src/test/java/org/torproject/onionoo/docs/DummyDocumentStore.java
@@ -19,9 +19,7 @@ public class DummyDocumentStore extends DocumentStore {
private <T extends Document> SortedMap<String, Document>
getStoredDocumentsByClass(Class<T> documentType) {
- if (!this.storedDocuments.containsKey(documentType)) {
- this.storedDocuments.put(documentType, new TreeMap<>());
- }
+ this.storedDocuments.putIfAbsent(documentType, new TreeMap<>());
return this.storedDocuments.get(documentType);
}
diff --git a/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java b/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
index 022381b..a6042b1 100644
--- a/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
+++ b/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
@@ -335,10 +335,7 @@ public class ResourceServletTest {
new HashMap<>();
for (String parameter : uriParts[1].split("&")) {
String[] parameterParts = parameter.split("=");
- if (!parameterLists.containsKey(parameterParts[0])) {
- parameterLists.put(parameterParts[0],
- new ArrayList<>());
- }
+ parameterLists.putIfAbsent(parameterParts[0], new ArrayList<>());
parameterLists.get(parameterParts[0]).add(parameterParts[1]);
}
parameters = new HashMap<>();
diff --git a/src/test/java/org/torproject/onionoo/updater/DummyDescriptorSource.java b/src/test/java/org/torproject/onionoo/updater/DummyDescriptorSource.java
index 22ae477..e31585d 100644
--- a/src/test/java/org/torproject/onionoo/updater/DummyDescriptorSource.java
+++ b/src/test/java/org/torproject/onionoo/updater/DummyDescriptorSource.java
@@ -31,9 +31,7 @@ public class DummyDescriptorSource extends DescriptorSource {
private Set<Descriptor> getDescriptorsByType(
DescriptorType descriptorType) {
- if (!this.descriptors.containsKey(descriptorType)) {
- this.descriptors.put(descriptorType, new HashSet<>());
- }
+ this.descriptors.putIfAbsent(descriptorType, new HashSet<>());
return this.descriptors.get(descriptorType);
}
@@ -43,10 +41,7 @@ public class DummyDescriptorSource extends DescriptorSource {
/** Register a listener to receive descriptors of the demanded type. */
public void registerDescriptorListener(DescriptorListener listener,
DescriptorType descriptorType) {
- if (!this.descriptorListeners.containsKey(descriptorType)) {
- this.descriptorListeners.put(descriptorType,
- new HashSet<>());
- }
+ this.descriptorListeners.putIfAbsent(descriptorType, new HashSet<>());
this.descriptorListeners.get(descriptorType).add(listener);
}
1
0
27 Aug '18
commit 91588c989c0c4cd489b3a13f11683266247399cb
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Tue Aug 21 11:47:29 2018 +0200
Remove an unnecessary return statement.
---
src/main/java/org/torproject/onionoo/server/RequestHandler.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/main/java/org/torproject/onionoo/server/RequestHandler.java b/src/main/java/org/torproject/onionoo/server/RequestHandler.java
index 81cd8dc..d1e9cce 100644
--- a/src/main/java/org/torproject/onionoo/server/RequestHandler.java
+++ b/src/main/java/org/torproject/onionoo/server/RequestHandler.java
@@ -209,7 +209,6 @@ public class RequestHandler {
private void filterByType() {
if (this.type == null) {
/* Not filtering by type. */
- return;
} else if (this.type.equals("relay")) {
this.filteredBridges.clear();
} else {
1
0
commit 680118d0b0168865fae20a2d00109358817af98b
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Tue Aug 21 09:52:44 2018 +0200
Make a couple JavaDoc fixes.
---
src/main/java/org/torproject/onionoo/docs/NodeStatus.java | 2 +-
src/main/java/org/torproject/onionoo/docs/SummaryDocument.java | 6 +++---
src/main/java/org/torproject/onionoo/server/NodeIndexer.java | 6 +++---
src/main/java/org/torproject/onionoo/server/ResourceServlet.java | 4 ++--
src/main/java/org/torproject/onionoo/updater/LookupService.java | 2 +-
src/main/java/org/torproject/onionoo/util/FormattingUtils.java | 2 +-
6 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/docs/NodeStatus.java b/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
index fe55229..1940198 100644
--- a/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
+++ b/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
@@ -29,7 +29,7 @@ import java.util.stream.Collectors;
* are relevant descriptors, consensuses or other documents available.
*
* <p>At the end of each run of the hourly updater, these documents are
- * concatenated and written to a single file in <code>status/summary</code>.
+ * concatenated and written to a single file in {@code status/summary}.
* Each line contains a single document.
*
* <p>A new NodeStatus can be created from a string using the
diff --git a/src/main/java/org/torproject/onionoo/docs/SummaryDocument.java b/src/main/java/org/torproject/onionoo/docs/SummaryDocument.java
index c4308ec..5286f6c 100644
--- a/src/main/java/org/torproject/onionoo/docs/SummaryDocument.java
+++ b/src/main/java/org/torproject/onionoo/docs/SummaryDocument.java
@@ -58,7 +58,7 @@ public class SummaryDocument extends Document {
@JsonIgnore
private transient String hashedFingerprint = null;
- /** Returns the SHA1-hashed fingerprint, or <code>null</code> if no
+ /** Returns the SHA1-hashed fingerprint, or {@code null} if no
* fingerprint is set. */
public String getHashedFingerprint() {
if (this.hashedFingerprint == null && this.fingerprint != null) {
@@ -75,7 +75,7 @@ public class SummaryDocument extends Document {
@JsonIgnore
private transient String base64Fingerprint = null;
- /** Returns the base64-encoded fingerprint, or <code>null</code> if no
+ /** Returns the base64-encoded fingerprint, or {@code null} if no
* fingerprint is set. */
public String getBase64Fingerprint() {
if (this.base64Fingerprint == null && this.fingerprint != null) {
@@ -93,7 +93,7 @@ public class SummaryDocument extends Document {
private transient String[] fingerprintSortedHexBlocks = null;
/** Returns a sorted array containing blocks of 4 upper-case hex
- * characters from the fingerprint, or <code>null</code> if no
+ * characters from the fingerprint, or {@code null} if no
* fingerprint is set. */
public String[] getFingerprintSortedHexBlocks() {
if (this.fingerprintSortedHexBlocks == null && this.fingerprint != null) {
diff --git a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
index 350a3ef..73b6777 100644
--- a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
+++ b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
@@ -61,8 +61,8 @@ public class NodeIndexer implements ServletContextListener, Runnable {
private Thread nodeIndexerThread = null;
/** Returns the creation time of the last known node index in
- * milliseconds since the epoch, or <code>-1</code> if no node index
- * could be retrieved within <code>timeoutMillis</code> milliseconds. */
+ * milliseconds since the epoch, or {@code -1} if no node index
+ * could be retrieved within {@code timeoutMillis} milliseconds. */
public synchronized long getLastIndexed(long timeoutMillis) {
if (this.lastIndexed == -1L && this.nodeIndexerThread != null
&& timeoutMillis > 0L) {
@@ -77,7 +77,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
}
/** Returns the last known node index, or null if no node index could be
- * retrieved within <code>timeoutMillis</code> milliseconds. */
+ * retrieved within {@code timeoutMillis} milliseconds. */
public synchronized NodeIndex getLatestNodeIndex(long timeoutMillis) {
if (this.latestNodeIndex == null && this.nodeIndexerThread != null
&& timeoutMillis > 0L) {
diff --git a/src/main/java/org/torproject/onionoo/server/ResourceServlet.java b/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
index 7567233..7913d22 100644
--- a/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
+++ b/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
@@ -86,8 +86,8 @@ public class ResourceServlet extends HttpServlet {
doGet(request, response, System.currentTimeMillis());
}
- /** Handles the HTTP GET request in the wrapped <code>request</code> by
- * writing an HTTP GET response to the likewise <code>response</code>,
+ /** Handles the HTTP GET request in the wrapped {@code request} by
+ * writing an HTTP GET response to the likewise {@code response},
* both of which are wrapped to facilitate testing. */
@SuppressWarnings("checkstyle:variabledeclarationusagedistance")
public void doGet(HttpServletRequestWrapper request,
diff --git a/src/main/java/org/torproject/onionoo/updater/LookupService.java b/src/main/java/org/torproject/onionoo/updater/LookupService.java
index 976a9ca..dd35b59 100644
--- a/src/main/java/org/torproject/onionoo/updater/LookupService.java
+++ b/src/main/java/org/torproject/onionoo/updater/LookupService.java
@@ -98,7 +98,7 @@ public class LookupService {
}
/** Looks up address strings in the configured
- * <code>GeoLite2-City-*.csv</code> and <code>GeoIPASNum2.csv</code>
+ * {@code GeoLite2-City-*.csv} and {@code GeoIPASNum2.csv}
* files and returns all lookup results. */
public SortedMap<String, LookupResult> lookup(
SortedSet<String> addressStrings) {
diff --git a/src/main/java/org/torproject/onionoo/util/FormattingUtils.java b/src/main/java/org/torproject/onionoo/util/FormattingUtils.java
index 558477d..5307384 100644
--- a/src/main/java/org/torproject/onionoo/util/FormattingUtils.java
+++ b/src/main/java/org/torproject/onionoo/util/FormattingUtils.java
@@ -25,7 +25,7 @@ public class FormattingUtils {
private static final long ONE_MINUTE = 60L * ONE_SECOND;
/** Formats the given number of milliseconds using the format
- * <code>"${minutes}:${seconds}.{milliseconds} minutes"</code>. */
+ * {@code "${minutes}:${seconds}.{milliseconds} minutes"}. */
public static String formatMillis(long millis) {
return String.format("%02d:%02d.%03d minutes", millis / ONE_MINUTE,
(millis % ONE_MINUTE) / ONE_SECOND, millis % ONE_SECOND);
1
0
[onionoo/master] Fix trivial bug in parsing bridge extra-info descriptors.
by karsten@torproject.org 27 Aug '18
by karsten@torproject.org 27 Aug '18
27 Aug '18
commit ba53eddc3735191ec8b11a3178c3cb0190460c3e
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Tue Aug 21 12:03:45 2018 +0200
Fix trivial bug in parsing bridge extra-info descriptors.
If the first thing we'd learn from a bridge was an extra-info
descriptor, we would not have stored the contained transports. This
case is very unlikely and has very little effect. Worth fixing anyway.
Found via code analysis.
---
.../onionoo/updater/NodeDetailsStatusUpdater.java | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java b/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
index 7223e5a..1cd989d 100644
--- a/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
+++ b/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
@@ -346,14 +346,16 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
DetailsStatus.class, true, fingerprint);
if (detailsStatus == null) {
detailsStatus = new DetailsStatus();
- } else if (null == detailsStatus.getExtraInfoDescPublished()
- || descriptor.getPublishedMillis()
- > detailsStatus.getExtraInfoDescPublished()) {
- detailsStatus.setExtraInfoDescPublished(
- descriptor.getPublishedMillis());
- detailsStatus.setTransports(descriptor.getTransports());
- this.documentStore.store(detailsStatus, fingerprint);
+ } else if (null != detailsStatus.getExtraInfoDescPublished()
+ && detailsStatus.getExtraInfoDescPublished()
+ >= descriptor.getPublishedMillis()) {
+ /* Already parsed more recent extra-info descriptor from this bridge. */
+ return;
}
+ detailsStatus.setExtraInfoDescPublished(
+ descriptor.getPublishedMillis());
+ detailsStatus.setTransports(descriptor.getTransports());
+ this.documentStore.store(detailsStatus, fingerprint);
}
private void processBridgeNetworkStatus(BridgeNetworkStatus status) {
1
0
commit ec16e791150785cfda603961469bc86bd65218a7
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Mon Aug 20 12:37:07 2018 +0200
Replace Comparator with lambda.
---
.../org/torproject/onionoo/docs/WeightsStatus.java | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/docs/WeightsStatus.java b/src/main/java/org/torproject/onionoo/docs/WeightsStatus.java
index c221fdd..adce2c8 100644
--- a/src/main/java/org/torproject/onionoo/docs/WeightsStatus.java
+++ b/src/main/java/org/torproject/onionoo/docs/WeightsStatus.java
@@ -27,16 +27,14 @@ public class WeightsStatus extends Document {
this.isDirty = false;
}
- private Comparator<long[]> histComparator = new Comparator<long[]>() {
- public int compare(long[] first, long[] second) {
- int relation = Long.compare(first[0], second[0]);
- if (0 != relation) {
- return relation;
- } else {
- return Long.compare(first[1], second[1]);
- }
- }
- };
+ private Comparator<long[]> histComparator = (first, second) -> {
+ int relation = Long.compare(first[0], second[0]);
+ if (0 != relation) {
+ return relation;
+ } else {
+ return Long.compare(first[1], second[1]);
+ }
+ };
private SortedMap<long[], double[]> history = new TreeMap<>(histComparator);
1
0
commit 54dfc8985ee7da543644762f8011f1323e53e24e
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Mon Aug 20 14:50:52 2018 +0200
Remove unthrown exceptions.
---
src/main/java/org/torproject/onionoo/server/ResourceServlet.java | 2 +-
src/main/java/org/torproject/onionoo/updater/LookupService.java | 6 ++----
.../java/org/torproject/onionoo/server/ResourceServletTest.java | 4 ++--
.../torproject/onionoo/updater/NodeDetailsStatusUpdaterTest.java | 2 +-
4 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/server/ResourceServlet.java b/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
index afcb867..1c72b9e 100644
--- a/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
+++ b/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
@@ -51,7 +51,7 @@ public class ResourceServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest request,
- HttpServletResponse response) throws IOException, ServletException {
+ HttpServletResponse response) throws IOException {
HttpServletRequestWrapper requestWrapper =
new HttpServletRequestWrapper(request);
HttpServletResponseWrapper responseWrapper =
diff --git a/src/main/java/org/torproject/onionoo/updater/LookupService.java b/src/main/java/org/torproject/onionoo/updater/LookupService.java
index 4bcc754..4af4443 100644
--- a/src/main/java/org/torproject/onionoo/updater/LookupService.java
+++ b/src/main/java/org/torproject/onionoo/updater/LookupService.java
@@ -14,7 +14,6 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
-import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import java.nio.charset.StandardCharsets;
@@ -340,14 +339,13 @@ public class LookupService {
}
private BufferedReader createBufferedReaderFromUtf8File(File utf8File)
- throws FileNotFoundException, CharacterCodingException {
+ throws FileNotFoundException {
return this.createBufferedReaderFromFile(utf8File,
StandardCharsets.UTF_8.newDecoder());
}
private BufferedReader createBufferedReaderFromIso88591File(
- File iso88591File) throws FileNotFoundException,
- CharacterCodingException {
+ File iso88591File) throws FileNotFoundException {
return this.createBufferedReaderFromFile(iso88591File,
StandardCharsets.ISO_8859_1.newDecoder());
}
diff --git a/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java b/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
index bc01003..0be1635 100644
--- a/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
+++ b/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
@@ -87,7 +87,7 @@ public class ResourceServletTest {
private int errorStatusCode;
- protected void sendError(int errorStatusCode) throws IOException {
+ protected void sendError(int errorStatusCode) {
this.errorStatusCode = errorStatusCode;
}
@@ -385,7 +385,7 @@ public class ResourceServletTest {
}
@Test(timeout = 100)
- public void testValidSummaryRelay() throws IOException {
+ public void testValidSummaryRelay() {
this.runTest("/summary");
assertEquals("2013-04-24 12:00:00",
this.summaryDocument.relays_published);
diff --git a/src/test/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdaterTest.java b/src/test/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdaterTest.java
index 1bcc7eb..068c724 100644
--- a/src/test/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdaterTest.java
+++ b/src/test/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdaterTest.java
@@ -33,7 +33,7 @@ public class NodeDetailsStatusUpdaterTest {
}
@Test
- public void testExitReset() throws Exception {
+ public void testExitReset() {
NodeDetailsStatusUpdater ndsu = new NodeDetailsStatusUpdater(null, null);
DescriptorParser dp = DescriptorSourceFactory.createDescriptorParser();
String descString = RELAY1 + PUB1 + RELAY2 + POLICY1 + RELAY3;
1
0
commit 38bd70aecb7b6c0a1440a31ec0a5585b2a2c8ef4
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Mon Aug 20 15:05:33 2018 +0200
Use diamond operator.
---
.../org/torproject/onionoo/docs/DetailsDocument.java | 2 +-
.../org/torproject/onionoo/docs/DetailsStatus.java | 2 +-
.../java/org/torproject/onionoo/docs/NodeStatus.java | 2 +-
.../org/torproject/onionoo/server/NodeIndexer.java | 20 ++++++++++----------
.../onionoo/updater/ClientsStatusUpdater.java | 2 +-
.../torproject/onionoo/updater/DescriptorSource.java | 2 +-
.../onionoo/updater/NodeDetailsStatusUpdater.java | 2 +-
.../onionoo/updater/RdnsLookupRequest.java | 2 +-
.../onionoo/updater/UptimeStatusUpdater.java | 4 ++--
.../torproject/onionoo/docs/DummyDocumentStore.java | 2 +-
.../onionoo/server/ResourceServletTest.java | 10 +++++-----
.../onionoo/updater/DummyDescriptorSource.java | 4 ++--
.../onionoo/updater/LookupServiceTest.java | 6 +++---
13 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java b/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java
index 5e53d4c..504f0b5 100644
--- a/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java
+++ b/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java
@@ -76,7 +76,7 @@ public class DetailsDocument extends Document {
}
public List<String> getExitAddresses() {
- return this.exitAddresses == null ? new ArrayList<String>()
+ return this.exitAddresses == null ? new ArrayList<>()
: this.exitAddresses;
}
diff --git a/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java b/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java
index 7cd87ee..31762d3 100644
--- a/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java
+++ b/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java
@@ -248,7 +248,7 @@ public class DetailsStatus extends Document {
}
public SortedSet<String> getOrAddressesAndPorts() {
- return this.orAddressesAndPorts == null ? new TreeSet<String>() :
+ return this.orAddressesAndPorts == null ? new TreeSet<>() :
this.orAddressesAndPorts;
}
diff --git a/src/main/java/org/torproject/onionoo/docs/NodeStatus.java b/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
index c0c6adf..bef403b 100644
--- a/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
+++ b/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
@@ -182,7 +182,7 @@ public class NodeStatus extends Document {
}
public SortedSet<String> getOrAddressesAndPorts() {
- return this.orAddressesAndPorts == null ? new TreeSet<String>()
+ return this.orAddressesAndPorts == null ? new TreeSet<>()
: this.orAddressesAndPorts;
}
diff --git a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
index 3812fea..350a3ef 100644
--- a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
+++ b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
@@ -211,7 +211,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
}
if (!newRelaysByCountryCode.containsKey(countryCode)) {
newRelaysByCountryCode.put(countryCode,
- new HashSet<String>());
+ new HashSet<>());
}
newRelaysByCountryCode.get(countryCode).add(fingerprint);
newRelaysByCountryCode.get(countryCode).add(hashedFingerprint);
@@ -226,7 +226,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
asNumber = "AS0";
}
if (!newRelaysByAsNumber.containsKey(asNumber)) {
- newRelaysByAsNumber.put(asNumber, new HashSet<String>());
+ newRelaysByAsNumber.put(asNumber, new HashSet<>());
}
newRelaysByAsNumber.get(asNumber).add(fingerprint);
newRelaysByAsNumber.get(asNumber).add(hashedFingerprint);
@@ -239,7 +239,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
for (String flag : entry.getRelayFlags()) {
String flagLowerCase = flag.toLowerCase();
if (!newRelaysByFlag.containsKey(flagLowerCase)) {
- newRelaysByFlag.put(flagLowerCase, new HashSet<String>());
+ newRelaysByFlag.put(flagLowerCase, new HashSet<>());
}
newRelaysByFlag.get(flagLowerCase).add(fingerprint);
newRelaysByFlag.get(flagLowerCase).add(hashedFingerprint);
@@ -260,7 +260,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
- entry.getFirstSeenMillis()) / ONE_DAY);
if (!newRelaysByFirstSeenDays.containsKey(daysSinceFirstSeen)) {
newRelaysByFirstSeenDays.put(daysSinceFirstSeen,
- new HashSet<String>());
+ new HashSet<>());
}
newRelaysByFirstSeenDays.get(daysSinceFirstSeen).add(fingerprint);
newRelaysByFirstSeenDays.get(daysSinceFirstSeen).add(
@@ -270,21 +270,21 @@ public class NodeIndexer implements ServletContextListener, Runnable {
- entry.getLastSeenMillis()) / ONE_DAY);
if (!newRelaysByLastSeenDays.containsKey(daysSinceLastSeen)) {
newRelaysByLastSeenDays.put(daysSinceLastSeen,
- new HashSet<String>());
+ new HashSet<>());
}
newRelaysByLastSeenDays.get(daysSinceLastSeen).add(fingerprint);
newRelaysByLastSeenDays.get(daysSinceLastSeen).add(
hashedFingerprint);
String contact = entry.getContact();
if (!newRelaysByContact.containsKey(contact)) {
- newRelaysByContact.put(contact, new HashSet<String>());
+ newRelaysByContact.put(contact, new HashSet<>());
}
newRelaysByContact.get(contact).add(fingerprint);
newRelaysByContact.get(contact).add(hashedFingerprint);
String version = entry.getVersion();
if (null != version) {
if (!newRelaysByVersion.containsKey(version)) {
- newRelaysByVersion.put(version, new HashSet<String>());
+ newRelaysByVersion.put(version, new HashSet<>());
}
newRelaysByVersion.get(version).add(fingerprint);
newRelaysByVersion.get(version).add(hashedFingerprint);
@@ -347,7 +347,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
for (String flag : entry.getRelayFlags()) {
String flagLowerCase = flag.toLowerCase();
if (!newBridgesByFlag.containsKey(flagLowerCase)) {
- newBridgesByFlag.put(flagLowerCase, new HashSet<String>());
+ newBridgesByFlag.put(flagLowerCase, new HashSet<>());
}
newBridgesByFlag.get(flagLowerCase).add(hashedFingerprint);
newBridgesByFlag.get(flagLowerCase).add(
@@ -358,7 +358,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
- entry.getFirstSeenMillis()) / ONE_DAY);
if (!newBridgesByFirstSeenDays.containsKey(daysSinceFirstSeen)) {
newBridgesByFirstSeenDays.put(daysSinceFirstSeen,
- new HashSet<String>());
+ new HashSet<>());
}
newBridgesByFirstSeenDays.get(daysSinceFirstSeen).add(
hashedFingerprint);
@@ -369,7 +369,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
- entry.getLastSeenMillis()) / ONE_DAY);
if (!newBridgesByLastSeenDays.containsKey(daysSinceLastSeen)) {
newBridgesByLastSeenDays.put(daysSinceLastSeen,
- new HashSet<String>());
+ new HashSet<>());
}
newBridgesByLastSeenDays.get(daysSinceLastSeen).add(
hashedFingerprint);
diff --git a/src/main/java/org/torproject/onionoo/updater/ClientsStatusUpdater.java b/src/main/java/org/torproject/onionoo/updater/ClientsStatusUpdater.java
index 0529dcf..8265f43 100644
--- a/src/main/java/org/torproject/onionoo/updater/ClientsStatusUpdater.java
+++ b/src/main/java/org/torproject/onionoo/updater/ClientsStatusUpdater.java
@@ -116,7 +116,7 @@ public class ClientsStatusUpdater implements DescriptorListener,
responsesByTransport, responsesByVersion);
if (!this.newResponses.containsKey(hashedFingerprint)) {
this.newResponses.put(hashedFingerprint,
- new TreeSet<ClientsHistory>());
+ new TreeSet<>());
}
this.newResponses.get(hashedFingerprint).add(
newResponseHistory);
diff --git a/src/main/java/org/torproject/onionoo/updater/DescriptorSource.java b/src/main/java/org/torproject/onionoo/updater/DescriptorSource.java
index 20e249d..64bb0e4 100644
--- a/src/main/java/org/torproject/onionoo/updater/DescriptorSource.java
+++ b/src/main/java/org/torproject/onionoo/updater/DescriptorSource.java
@@ -83,7 +83,7 @@ public class DescriptorSource {
DescriptorType descriptorType) {
if (!this.descriptorListeners.containsKey(descriptorType)) {
this.descriptorListeners.put(descriptorType,
- new HashSet<DescriptorListener>());
+ new HashSet<>());
}
this.descriptorListeners.get(descriptorType).add(listener);
}
diff --git a/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java b/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
index 507d633..82cea1b 100644
--- a/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
+++ b/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
@@ -224,7 +224,7 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
continue;
}
if (!this.exitListEntries.containsKey(fingerprint)) {
- this.exitListEntries.put(fingerprint, new HashMap<String, Long>());
+ this.exitListEntries.put(fingerprint, new HashMap<>());
}
String exitAddress = exitAddressScanMillis.getKey();
if (!this.exitListEntries.get(fingerprint).containsKey(
diff --git a/src/main/java/org/torproject/onionoo/updater/RdnsLookupRequest.java b/src/main/java/org/torproject/onionoo/updater/RdnsLookupRequest.java
index 380b62c..9f3c6cf 100644
--- a/src/main/java/org/torproject/onionoo/updater/RdnsLookupRequest.java
+++ b/src/main/java/org/torproject/onionoo/updater/RdnsLookupRequest.java
@@ -91,7 +91,7 @@ class RdnsLookupRequest extends Thread {
envProps.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.dns.DnsContextFactory");
final DirContext dnsContext = new InitialDirContext(envProps);
- Set<String> results = new TreeSet<String>();
+ Set<String> results = new TreeSet<>();
Attributes dnsEntries =
dnsContext.getAttributes(hostName, new String[] { type });
if (dnsEntries != null) {
diff --git a/src/main/java/org/torproject/onionoo/updater/UptimeStatusUpdater.java b/src/main/java/org/torproject/onionoo/updater/UptimeStatusUpdater.java
index 8405bf8..338bf58 100644
--- a/src/main/java/org/torproject/onionoo/updater/UptimeStatusUpdater.java
+++ b/src/main/java/org/torproject/onionoo/updater/UptimeStatusUpdater.java
@@ -105,7 +105,7 @@ public class UptimeStatusUpdater implements DescriptorListener,
String fingerprint = entry.getFingerprint();
if (!this.newRunningRelays.containsKey(fingerprint)) {
this.newRunningRelays.put(fingerprint,
- new TreeMap<Long, Flags>());
+ new TreeMap<>());
}
this.newRunningRelays.get(fingerprint).put(dateHourMillis,
new Flags(entry.getFlags()));
@@ -125,7 +125,7 @@ public class UptimeStatusUpdater implements DescriptorListener,
/ DateTimeHelper.ONE_HOUR) * DateTimeHelper.ONE_HOUR;
for (String fingerprint : fingerprints) {
if (!this.newRunningBridges.containsKey(fingerprint)) {
- this.newRunningBridges.put(fingerprint, new TreeSet<Long>());
+ this.newRunningBridges.put(fingerprint, new TreeSet<>());
}
this.newRunningBridges.get(fingerprint).add(dateHourMillis);
}
diff --git a/src/test/java/org/torproject/onionoo/docs/DummyDocumentStore.java b/src/test/java/org/torproject/onionoo/docs/DummyDocumentStore.java
index 8827725..3c79235 100644
--- a/src/test/java/org/torproject/onionoo/docs/DummyDocumentStore.java
+++ b/src/test/java/org/torproject/onionoo/docs/DummyDocumentStore.java
@@ -20,7 +20,7 @@ public class DummyDocumentStore extends DocumentStore {
private <T extends Document> SortedMap<String, Document>
getStoredDocumentsByClass(Class<T> documentType) {
if (!this.storedDocuments.containsKey(documentType)) {
- this.storedDocuments.put(documentType, new TreeMap<String, Document>());
+ this.storedDocuments.put(documentType, new TreeMap<>());
}
return this.storedDocuments.get(documentType);
}
diff --git a/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java b/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
index 0be1635..063f550 100644
--- a/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
+++ b/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
@@ -56,7 +56,7 @@ public class ResourceServletTest {
this.requestUri = requestUri;
this.queryString = queryString;
this.parameterMap = parameterMap == null
- ? new HashMap<String, String[]>() : parameterMap;
+ ? new HashMap<>() : parameterMap;
}
@Override
@@ -162,8 +162,8 @@ public class ResourceServletTest {
"Running", "V2Dir", "Valid" })), 1140L, "us",
DateTimeHelper.parse("2013-04-16 18:00:00"), "AS7922",
"comcast cable communications, llc", null,
- new TreeSet<String>(Arrays.asList(new String[] {
- "000C5F55BD4814B917CC474BD537F1A3B33CCE2A" })),
+ new TreeSet<>(Arrays.asList(new String[]{
+ "000C5F55BD4814B917CC474BD537F1A3B33CCE2A"})),
new TreeSet<>(Arrays.asList(new String[] {
"000C5F55BD4814B917CC474BD537F1A3B33CCE2A" })), null, null,
new TreeSet<>(Arrays.asList(
@@ -182,7 +182,7 @@ public class ResourceServletTest {
"liberty global operations b.v.",
"1024d/51e2a1c7 \"steven j. murdoch\" "
+ "<tor+steven.murdoch(a)cl.cam.ac.uk> <fb-token:5sr_k_zs2wm=>",
- new TreeSet<String>(), new TreeSet<String>(), "0.2.3.24-rc-dev",
+ new TreeSet<>(), new TreeSet<>(), "0.2.3.24-rc-dev",
"windows xp", null, null, false);
this.relays.put("0025C136C1F3A9EEFE2AE3F918F03BFA21B5070B",
relayTimMayTribute);
@@ -337,7 +337,7 @@ public class ResourceServletTest {
String[] parameterParts = parameter.split("=");
if (!parameterLists.containsKey(parameterParts[0])) {
parameterLists.put(parameterParts[0],
- new ArrayList<String>());
+ new ArrayList<>());
}
parameterLists.get(parameterParts[0]).add(parameterParts[1]);
}
diff --git a/src/test/java/org/torproject/onionoo/updater/DummyDescriptorSource.java b/src/test/java/org/torproject/onionoo/updater/DummyDescriptorSource.java
index c311b2b..c985090 100644
--- a/src/test/java/org/torproject/onionoo/updater/DummyDescriptorSource.java
+++ b/src/test/java/org/torproject/onionoo/updater/DummyDescriptorSource.java
@@ -32,7 +32,7 @@ public class DummyDescriptorSource extends DescriptorSource {
private Set<Descriptor> getDescriptorsByType(
DescriptorType descriptorType) {
if (!this.descriptors.containsKey(descriptorType)) {
- this.descriptors.put(descriptorType, new HashSet<Descriptor>());
+ this.descriptors.put(descriptorType, new HashSet<>());
}
return this.descriptors.get(descriptorType);
}
@@ -45,7 +45,7 @@ public class DummyDescriptorSource extends DescriptorSource {
DescriptorType descriptorType) {
if (!this.descriptorListeners.containsKey(descriptorType)) {
this.descriptorListeners.put(descriptorType,
- new HashSet<DescriptorListener>());
+ new HashSet<>());
}
this.descriptorListeners.get(descriptorType).add(listener);
}
diff --git a/src/test/java/org/torproject/onionoo/updater/LookupServiceTest.java b/src/test/java/org/torproject/onionoo/updater/LookupServiceTest.java
index 6311316..743fe1d 100644
--- a/src/test/java/org/torproject/onionoo/updater/LookupServiceTest.java
+++ b/src/test/java/org/torproject/onionoo/updater/LookupServiceTest.java
@@ -234,19 +234,19 @@ public class LookupServiceTest {
@Test()
public void testLookupNoBlocksLines() {
- this.assertLookupResult(new ArrayList<String>(), null, null,
+ this.assertLookupResult(new ArrayList<>(), null, null,
"8.8.8.8", null, null, null, null, null, null, null, null);
}
@Test()
public void testLookupNoLocationLines() {
- this.assertLookupResult(null, new ArrayList<String>(), null,
+ this.assertLookupResult(null, new ArrayList<>(), null,
"8.8.8.8", null, null, null, null, null, null, null, null);
}
@Test()
public void testLookupNoGeoipAsNum2Lines() {
- this.assertLookupResult(null, null, new ArrayList<String>(),
+ this.assertLookupResult(null, null, new ArrayList<>(),
"8.8.8.8", null, null, null, null, null, null, null, null);
}
1
0
commit c9aadac0907bee8cc1a0657842506735b801622f
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Mon Aug 20 14:57:35 2018 +0200
Use Java 5 foreach loop.
---
src/main/java/org/torproject/onionoo/server/IntegerDistribution.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/server/IntegerDistribution.java b/src/main/java/org/torproject/onionoo/server/IntegerDistribution.java
index f462765..19862a0 100644
--- a/src/main/java/org/torproject/onionoo/server/IntegerDistribution.java
+++ b/src/main/java/org/torproject/onionoo/server/IntegerDistribution.java
@@ -17,8 +17,8 @@ class IntegerDistribution {
public String toString() {
StringBuilder sb = new StringBuilder();
int totalValues = 0;
- for (int i = 0; i < logValues.length; i++) {
- totalValues += logValues[i];
+ for (int logValue : logValues) {
+ totalValues += logValue;
}
int[] permilles = new int[] { 500, 900, 990, 999 };
if (totalValues > 0) {
1
0
27 Aug '18
commit d09bfefe943974b966eb487de0e062cac540ba56
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Mon Aug 20 14:41:26 2018 +0200
Use more appropriate assert methods in tests.
---
.../torproject/onionoo/docs/UptimeStatusTest.java | 21 +++++++--------------
.../onionoo/updater/UptimeStatusUpdaterTest.java | 10 ++++++----
2 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/src/test/java/org/torproject/onionoo/docs/UptimeStatusTest.java b/src/test/java/org/torproject/onionoo/docs/UptimeStatusTest.java
index aff5ce5..1b567ac 100644
--- a/src/test/java/org/torproject/onionoo/docs/UptimeStatusTest.java
+++ b/src/test/java/org/torproject/onionoo/docs/UptimeStatusTest.java
@@ -34,8 +34,7 @@ public class UptimeStatusTest {
uptimeStatus.getRelayHistory().size());
UptimeHistory newUptimeHistory =
uptimeStatus.getRelayHistory().first();
- assertEquals("History not for relay.", true,
- newUptimeHistory.isRelay());
+ assertTrue("History not for relay.", newUptimeHistory.isRelay());
assertEquals("History start millis not same as provided.",
DateTimeHelper.parse("2013-12-20 00:00:00"),
newUptimeHistory.getStartMillis());
@@ -55,8 +54,7 @@ public class UptimeStatusTest {
uptimeStatus.getRelayHistory().size());
UptimeHistory newUptimeHistory =
uptimeStatus.getRelayHistory().first();
- assertEquals("History not for relay.", true,
- newUptimeHistory.isRelay());
+ assertTrue("History not for relay.", newUptimeHistory.isRelay());
assertEquals("History start millis not same as provided.",
DateTimeHelper.parse("2013-12-20 00:00:00"),
newUptimeHistory.getStartMillis());
@@ -84,8 +82,7 @@ public class UptimeStatusTest {
uptimeStatus.getRelayHistory().size());
UptimeHistory newUptimeHistory =
uptimeStatus.getRelayHistory().first();
- assertEquals("History not for relay.", true,
- newUptimeHistory.isRelay());
+ assertTrue("History not for relay.", newUptimeHistory.isRelay());
assertEquals("History start millis not as expected.",
DateTimeHelper.parse("2013-07-22 17:00:00"),
newUptimeHistory.getStartMillis());
@@ -128,8 +125,7 @@ public class UptimeStatusTest {
3, uptimeStatus.getRelayHistory().size());
UptimeHistory newUptimeHistory =
uptimeStatus.getRelayHistory().first();
- assertEquals("History not for relay.", true,
- newUptimeHistory.isRelay());
+ assertTrue("History not for relay.", newUptimeHistory.isRelay());
assertEquals("History start millis not as expected.",
DateTimeHelper.parse("2013-07-22 16:00:00"),
newUptimeHistory.getStartMillis());
@@ -150,8 +146,7 @@ public class UptimeStatusTest {
2, uptimeStatus.getRelayHistory().size());
UptimeHistory newUptimeHistory =
uptimeStatus.getRelayHistory().first();
- assertEquals("History not for relay.", true,
- newUptimeHistory.isRelay());
+ assertTrue("History not for relay.", newUptimeHistory.isRelay());
assertEquals("History start millis not as expected.",
DateTimeHelper.parse("2013-07-22 17:00:00"),
newUptimeHistory.getStartMillis());
@@ -176,8 +171,7 @@ public class UptimeStatusTest {
1, uptimeStatus.getRelayHistory().size());
UptimeHistory newUptimeHistory =
uptimeStatus.getRelayHistory().first();
- assertEquals("History not for relay.", true,
- newUptimeHistory.isRelay());
+ assertTrue("History not for relay.", newUptimeHistory.isRelay());
assertEquals("History start millis not as expected.",
DateTimeHelper.parse("2013-07-22 16:00:00"),
newUptimeHistory.getStartMillis());
@@ -198,8 +192,7 @@ public class UptimeStatusTest {
+ "entry.", 1, uptimeStatus.getBridgeHistory().size());
UptimeHistory newUptimeHistory =
uptimeStatus.getBridgeHistory().last();
- assertEquals("History not for bridge.", false,
- newUptimeHistory.isRelay());
+ assertFalse("History not for bridge.", newUptimeHistory.isRelay());
assertEquals("History start millis not as expected.",
DateTimeHelper.parse("2013-07-22 16:00:00"),
newUptimeHistory.getStartMillis());
diff --git a/src/test/java/org/torproject/onionoo/updater/UptimeStatusUpdaterTest.java b/src/test/java/org/torproject/onionoo/updater/UptimeStatusUpdaterTest.java
index 4797356..df6dd66 100644
--- a/src/test/java/org/torproject/onionoo/updater/UptimeStatusUpdaterTest.java
+++ b/src/test/java/org/torproject/onionoo/updater/UptimeStatusUpdaterTest.java
@@ -4,6 +4,8 @@
package org.torproject.onionoo.updater;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import org.torproject.onionoo.docs.DateTimeHelper;
import org.torproject.onionoo.docs.DocumentStoreFactory;
@@ -75,7 +77,7 @@ public class UptimeStatusUpdaterTest {
UptimeHistory history = status.getRelayHistory().first();
assertEquals("History must contain one entry.", 1,
status.getRelayHistory().size());
- assertEquals("History not for relay.", true, history.isRelay());
+ assertTrue("History not for relay.", history.isRelay());
assertEquals("History start millis not as expected.",
VALID_AFTER_SAMPLE, history.getStartMillis());
assertEquals("History uptime hours must be 1.", 1,
@@ -111,7 +113,7 @@ public class UptimeStatusUpdaterTest {
assertEquals("Relay history must contain one entry.", 1,
status.getRelayHistory().size());
UptimeHistory history = status.getRelayHistory().first();
- assertEquals("History not for relay.", true, history.isRelay());
+ assertTrue("History not for relay.", history.isRelay());
assertEquals("History start millis not as expected.",
DateTimeHelper.parse("2013-07-22 17:00:00"),
history.getStartMillis());
@@ -151,7 +153,7 @@ public class UptimeStatusUpdaterTest {
UptimeHistory history = status.getBridgeHistory().first();
assertEquals("Bridge history must contain one entry.", 1,
status.getBridgeHistory().size());
- assertEquals("History not for bridge.", false, history.isRelay());
+ assertFalse("History not for bridge.", history.isRelay());
assertEquals("History start millis not as expected.",
DateTimeHelper.parse("2014-03-21 20:00:00"),
history.getStartMillis());
@@ -174,7 +176,7 @@ public class UptimeStatusUpdaterTest {
assertEquals("Bridge history must contain one entry.", 1,
status.getBridgeHistory().size());
UptimeHistory history = status.getBridgeHistory().last();
- assertEquals("History not for bridge.", false, history.isRelay());
+ assertFalse("History not for bridge.", history.isRelay());
assertEquals("History start millis not as expected.",
DateTimeHelper.parse("2013-07-22 17:00:00"),
history.getStartMillis());
1
0