[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [onionoo/master] Resolve or suppress remaining checkstyle warnings.
commit 01c53dd0a261acfdad467fc5450abf5b12d42063
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Tue Jul 19 16:42:15 2016 +0200
Resolve or suppress remaining checkstyle warnings.
Implements the rest of #19613.
---
.../torproject/onionoo/docs/BandwidthDocument.java | 1 +
.../torproject/onionoo/docs/ClientsDocument.java | 1 +
.../torproject/onionoo/docs/DetailsDocument.java | 41 +++----
.../org/torproject/onionoo/docs/DetailsStatus.java | 49 +++++----
.../org/torproject/onionoo/docs/DocumentStore.java | 4 +-
.../org/torproject/onionoo/docs/NodeStatus.java | 18 +--
.../torproject/onionoo/docs/SummaryDocument.java | 15 +--
.../torproject/onionoo/docs/UptimeDocument.java | 1 +
.../torproject/onionoo/docs/WeightsDocument.java | 1 +
.../org/torproject/onionoo/docs/WeightsStatus.java | 6 +-
.../org/torproject/onionoo/server/Counter.java | 22 ++++
.../onionoo/server/HttpServletRequestWrapper.java | 1 +
.../onionoo/server/IntegerDistribution.java | 50 +++++++++
.../onionoo/server/MostFrequentString.java | 65 +++++++++++
.../org/torproject/onionoo/server/NodeIndex.java | 12 +-
.../org/torproject/onionoo/server/NodeIndexer.java | 25 +++--
.../onionoo/server/PerformanceMetrics.java | 122 ---------------------
.../torproject/onionoo/server/RequestHandler.java | 18 +--
.../torproject/onionoo/server/ResourceServlet.java | 46 ++++----
.../onionoo/updater/DescriptorDownloader.java | 10 +-
.../onionoo/updater/DescriptorSource.java | 6 +
.../torproject/onionoo/updater/LookupService.java | 27 ++---
.../onionoo/updater/NodeDetailsStatusUpdater.java | 8 +-
.../onionoo/writer/BandwidthDocumentWriter.java | 4 +-
.../onionoo/writer/DetailsDocumentWriter.java | 4 +-
.../onionoo/writer/SummaryDocumentWriter.java | 8 +-
26 files changed, 301 insertions(+), 264 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/docs/BandwidthDocument.java b/src/main/java/org/torproject/onionoo/docs/BandwidthDocument.java
index 6fe3240..1990734 100644
--- a/src/main/java/org/torproject/onionoo/docs/BandwidthDocument.java
+++ b/src/main/java/org/torproject/onionoo/docs/BandwidthDocument.java
@@ -5,6 +5,7 @@ package org.torproject.onionoo.docs;
import java.util.Map;
+@SuppressWarnings("checkstyle:membername")
public class BandwidthDocument extends Document {
@SuppressWarnings("unused")
diff --git a/src/main/java/org/torproject/onionoo/docs/ClientsDocument.java b/src/main/java/org/torproject/onionoo/docs/ClientsDocument.java
index 89729d2..f8b0c84 100644
--- a/src/main/java/org/torproject/onionoo/docs/ClientsDocument.java
+++ b/src/main/java/org/torproject/onionoo/docs/ClientsDocument.java
@@ -5,6 +5,7 @@ package org.torproject.onionoo.docs;
import java.util.Map;
+@SuppressWarnings("checkstyle:membername")
public class ClientsDocument extends Document {
@SuppressWarnings("unused")
diff --git a/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java b/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java
index 85c0154..a9257af 100644
--- a/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java
+++ b/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java
@@ -10,6 +10,7 @@ import java.util.List;
import java.util.Map;
import java.util.SortedSet;
+@SuppressWarnings("checkstyle:membername")
public class DetailsDocument extends Document {
/* We must ensure that details files only contain ASCII characters
@@ -20,12 +21,12 @@ public class DetailsDocument extends Document {
* to write six characters '\', 'u', '0', '0', 'F', '2'. The only thing
* we'll have to do is to change back the '\\' that Gson writes for the
* '\'. */
- private static String escapeJSON(String s) {
- return StringEscapeUtils.escapeJava(s);
+ private static String escapeJson(String stringToEscape) {
+ return StringEscapeUtils.escapeJava(stringToEscape);
}
- private static String unescapeJSON(String s) {
- return StringEscapeUtils.unescapeJava(s);
+ private static String unescapeJson(String stringToUnescape) {
+ return StringEscapeUtils.unescapeJava(stringToUnescape);
}
private String nickname;
@@ -154,31 +155,31 @@ public class DetailsDocument extends Document {
private String country_name;
public void setCountryName(String countryName) {
- this.country_name = escapeJSON(countryName);
+ this.country_name = escapeJson(countryName);
}
public String getCountryName() {
- return unescapeJSON(this.country_name);
+ return unescapeJson(this.country_name);
}
private String region_name;
public void setRegionName(String regionName) {
- this.region_name = escapeJSON(regionName);
+ this.region_name = escapeJson(regionName);
}
public String getRegionName() {
- return unescapeJSON(this.region_name);
+ return unescapeJson(this.region_name);
}
private String city_name;
public void setCityName(String cityName) {
- this.city_name = escapeJSON(cityName);
+ this.city_name = escapeJson(cityName);
}
public String getCityName() {
- return unescapeJSON(this.city_name);
+ return unescapeJson(this.city_name);
}
private Float latitude;
@@ -204,21 +205,21 @@ public class DetailsDocument extends Document {
private String as_number;
public void setAsNumber(String asNumber) {
- this.as_number = escapeJSON(asNumber);
+ this.as_number = escapeJson(asNumber);
}
public String getAsNumber() {
- return unescapeJSON(this.as_number);
+ return unescapeJson(this.as_number);
}
private String as_name;
public void setAsName(String asName) {
- this.as_name = escapeJSON(asName);
+ this.as_name = escapeJson(asName);
}
public String getAsName() {
- return unescapeJSON(this.as_name);
+ return unescapeJson(this.as_name);
}
private Long consensus_weight;
@@ -234,11 +235,11 @@ public class DetailsDocument extends Document {
private String host_name;
public void setHostName(String hostName) {
- this.host_name = escapeJSON(hostName);
+ this.host_name = escapeJson(hostName);
}
public String getHostName() {
- return unescapeJSON(this.host_name);
+ return unescapeJson(this.host_name);
}
private String last_restarted;
@@ -328,21 +329,21 @@ public class DetailsDocument extends Document {
private String contact;
public void setContact(String contact) {
- this.contact = escapeJSON(contact);
+ this.contact = escapeJson(contact);
}
public String getContact() {
- return unescapeJSON(this.contact);
+ return unescapeJson(this.contact);
}
private String platform;
public void setPlatform(String platform) {
- this.platform = escapeJSON(platform);
+ this.platform = escapeJson(platform);
}
public String getPlatform() {
- return unescapeJSON(this.platform);
+ return unescapeJson(this.platform);
}
private SortedSet<String> alleged_family;
diff --git a/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java b/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java
index 1a3c05d..7258054 100644
--- a/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java
+++ b/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java
@@ -10,6 +10,7 @@ import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
+@SuppressWarnings("checkstyle:membername")
public class DetailsStatus extends Document {
/* We must ensure that details files only contain ASCII characters
@@ -20,12 +21,12 @@ public class DetailsStatus extends Document {
* to write six characters '\', 'u', '0', '0', 'F', '2'. The only thing
* we'll have to do is to change back the '\\' that Gson writes for the
* '\'. */
- private static String escapeJSON(String s) {
- return StringEscapeUtils.escapeJava(s);
+ private static String escapeJson(String stringToEscape) {
+ return StringEscapeUtils.escapeJava(stringToEscape);
}
- private static String unescapeJSON(String s) {
- return StringEscapeUtils.unescapeJava(s);
+ private static String unescapeJson(String stringToUnescape) {
+ return StringEscapeUtils.unescapeJava(stringToUnescape);
}
/* From most recently published server descriptor: */
@@ -105,21 +106,21 @@ public class DetailsStatus extends Document {
private String contact;
public void setContact(String contact) {
- this.contact = escapeJSON(contact);
+ this.contact = escapeJson(contact);
}
public String getContact() {
- return unescapeJSON(this.contact);
+ return unescapeJson(this.contact);
}
private String platform;
public void setPlatform(String platform) {
- this.platform = escapeJSON(platform);
+ this.platform = escapeJson(platform);
}
public String getPlatform() {
- return unescapeJSON(this.platform);
+ return unescapeJson(this.platform);
}
private SortedSet<String> alleged_family;
@@ -470,51 +471,51 @@ public class DetailsStatus extends Document {
private String country_name;
public void setCountryName(String countryName) {
- this.country_name = escapeJSON(countryName);
+ this.country_name = escapeJson(countryName);
}
public String getCountryName() {
- return unescapeJSON(this.country_name);
+ return unescapeJson(this.country_name);
}
private String region_name;
public void setRegionName(String regionName) {
- this.region_name = escapeJSON(regionName);
+ this.region_name = escapeJson(regionName);
}
public String getRegionName() {
- return unescapeJSON(this.region_name);
+ return unescapeJson(this.region_name);
}
private String city_name;
public void setCityName(String cityName) {
- this.city_name = escapeJSON(cityName);
+ this.city_name = escapeJson(cityName);
}
public String getCityName() {
- return unescapeJSON(this.city_name);
+ return unescapeJson(this.city_name);
}
private String as_name;
- public void setASName(String aSName) {
- this.as_name = escapeJSON(aSName);
+ public void setAsName(String asName) {
+ this.as_name = escapeJson(asName);
}
- public String getASName() {
- return unescapeJSON(this.as_name);
+ public String getAsName() {
+ return unescapeJson(this.as_name);
}
private String as_number;
- public void setASNumber(String aSNumber) {
- this.as_number = escapeJSON(aSNumber);
+ public void setAsNumber(String asNumber) {
+ this.as_number = escapeJson(asNumber);
}
- public String getASNumber() {
- return unescapeJSON(this.as_number);
+ public String getAsNumber() {
+ return unescapeJson(this.as_number);
}
/* Reverse DNS lookup result: */
@@ -522,11 +523,11 @@ public class DetailsStatus extends Document {
private String host_name;
public void setHostName(String hostName) {
- this.host_name = escapeJSON(hostName);
+ this.host_name = escapeJson(hostName);
}
public String getHostName() {
- return unescapeJSON(this.host_name);
+ return unescapeJson(this.host_name);
}
}
diff --git a/src/main/java/org/torproject/onionoo/docs/DocumentStore.java b/src/main/java/org/torproject/onionoo/docs/DocumentStore.java
index 42c75aa..e1be777 100644
--- a/src/main/java/org/torproject/onionoo/docs/DocumentStore.java
+++ b/src/main/java/org/torproject/onionoo/docs/DocumentStore.java
@@ -420,7 +420,7 @@ public class DocumentStore {
String nickname = detailsDocument.getNickname();
List<String> addresses = new ArrayList<String>();
String countryCode = null;
- String aSNumber = null;
+ String asNumber = null;
String contact = null;
for (String orAddressAndPort : detailsDocument.getOrAddresses()) {
if (!orAddressAndPort.contains(":")) {
@@ -451,7 +451,7 @@ public class DocumentStore {
SummaryDocument summaryDocument = new SummaryDocument(isRelay,
nickname, fingerprint, addresses, lastSeenMillis, running,
relayFlags, consensusWeight, countryCode, firstSeenMillis,
- aSNumber, contact, family, family);
+ asNumber, contact, family, family);
return summaryDocument;
}
diff --git a/src/main/java/org/torproject/onionoo/docs/NodeStatus.java b/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
index afdd6c6..87cacb4 100644
--- a/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
+++ b/src/main/java/org/torproject/onionoo/docs/NodeStatus.java
@@ -67,9 +67,9 @@ public class NodeStatus extends Document {
String[] stringArray = null;
if (collection != null && !collection.isEmpty()) {
stringArray = new String[collection.size()];
- int i = 0;
+ int index = 0;
for (String string : collection) {
- stringArray[i++] = string;
+ stringArray[index++] = string;
}
}
return stringArray;
@@ -337,14 +337,14 @@ public class NodeStatus extends Document {
return this.countryCode;
}
- private String aSNumber;
+ private String asNumber;
- public void setASNumber(String aSNumber) {
- this.aSNumber = aSNumber;
+ public void setAsNumber(String asNumber) {
+ this.asNumber = asNumber;
}
- public String getASNumber() {
- return this.aSNumber;
+ public String getAsNumber() {
+ return this.asNumber;
}
/* Reverse DNS lookup result */
@@ -501,7 +501,7 @@ public class NodeStatus extends Document {
}
nodeStatus.addLastAddresses(lastChangedAddresses, address, orPort,
dirPort, orAddressesAndPorts);
- nodeStatus.setASNumber(parts[19]);
+ nodeStatus.setAsNumber(parts[19]);
nodeStatus.setContact(parts[20]);
if (!parts[21].equals("null")) {
nodeStatus.setRecommendedVersion(parts[21].equals("true"));
@@ -588,7 +588,7 @@ public class NodeStatus extends Document {
sb.append("\t" + DateTimeHelper.format(
this.getLastChangedOrAddressOrPort(),
DateTimeHelper.ISO_DATETIME_TAB_FORMAT));
- sb.append("\t" + (this.aSNumber != null ? this.aSNumber : "null"));
+ sb.append("\t" + (this.asNumber != null ? this.asNumber : "null"));
} else {
sb.append("\tnull\tnull\tnull");
}
diff --git a/src/main/java/org/torproject/onionoo/docs/SummaryDocument.java b/src/main/java/org/torproject/onionoo/docs/SummaryDocument.java
index c7d4774..133f616 100644
--- a/src/main/java/org/torproject/onionoo/docs/SummaryDocument.java
+++ b/src/main/java/org/torproject/onionoo/docs/SummaryDocument.java
@@ -16,6 +16,7 @@ import java.util.SortedSet;
import java.util.TreeSet;
import java.util.regex.Pattern;
+@SuppressWarnings("checkstyle:membername")
public class SummaryDocument extends Document {
private boolean t;
@@ -133,9 +134,9 @@ public class SummaryDocument extends Document {
String[] stringArray = null;
if (collection != null && !collection.isEmpty()) {
stringArray = new String[collection.size()];
- int i = 0;
+ int index = 0;
for (String string : collection) {
- stringArray[i++] = string;
+ stringArray[index++] = string;
}
}
return stringArray;
@@ -171,11 +172,11 @@ public class SummaryDocument extends Document {
private String as;
- public void setASNumber(String aSNumber) {
- this.as = aSNumber;
+ public void setAsNumber(String asNumber) {
+ this.as = asNumber;
}
- public String getASNumber() {
+ public String getAsNumber() {
return this.as;
}
@@ -274,7 +275,7 @@ public class SummaryDocument extends Document {
public SummaryDocument(boolean isRelay, String nickname,
String fingerprint, List<String> addresses, long lastSeenMillis,
boolean running, SortedSet<String> relayFlags, long consensusWeight,
- String countryCode, long firstSeenMillis, String aSNumber,
+ String countryCode, long firstSeenMillis, String asNumber,
String contact, SortedSet<String> familyFingerprints,
SortedSet<String> effectiveFamily) {
this.setRelay(isRelay);
@@ -287,7 +288,7 @@ public class SummaryDocument extends Document {
this.setConsensusWeight(consensusWeight);
this.setCountryCode(countryCode);
this.setFirstSeenMillis(firstSeenMillis);
- this.setASNumber(aSNumber);
+ this.setAsNumber(asNumber);
this.setContact(contact);
this.setFamilyFingerprints(familyFingerprints);
this.setEffectiveFamily(effectiveFamily);
diff --git a/src/main/java/org/torproject/onionoo/docs/UptimeDocument.java b/src/main/java/org/torproject/onionoo/docs/UptimeDocument.java
index 505d66c..98884b6 100644
--- a/src/main/java/org/torproject/onionoo/docs/UptimeDocument.java
+++ b/src/main/java/org/torproject/onionoo/docs/UptimeDocument.java
@@ -6,6 +6,7 @@ package org.torproject.onionoo.docs;
import java.util.Map;
import java.util.SortedMap;
+@SuppressWarnings("checkstyle:membername")
public class UptimeDocument extends Document {
@SuppressWarnings("unused")
diff --git a/src/main/java/org/torproject/onionoo/docs/WeightsDocument.java b/src/main/java/org/torproject/onionoo/docs/WeightsDocument.java
index 6e2ee02..9b1c8ef 100644
--- a/src/main/java/org/torproject/onionoo/docs/WeightsDocument.java
+++ b/src/main/java/org/torproject/onionoo/docs/WeightsDocument.java
@@ -5,6 +5,7 @@ package org.torproject.onionoo.docs;
import java.util.Map;
+@SuppressWarnings("checkstyle:membername")
public class WeightsDocument extends Document {
@SuppressWarnings("unused")
diff --git a/src/main/java/org/torproject/onionoo/docs/WeightsStatus.java b/src/main/java/org/torproject/onionoo/docs/WeightsStatus.java
index efb7c25..acd44a1 100644
--- a/src/main/java/org/torproject/onionoo/docs/WeightsStatus.java
+++ b/src/main/java/org/torproject/onionoo/docs/WeightsStatus.java
@@ -32,8 +32,10 @@ public class WeightsStatus extends Document {
private SortedMap<long[], double[]> history =
new TreeMap<long[], double[]>(
new Comparator<long[]>() {
- public int compare(long[] a, long[] b) {
- return a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0;
+ public int compare(long[] first, long[] second) {
+ return first[0] < second[0] ? -1
+ : first[0] > second[0] ? 1
+ : 0;
}
}
);
diff --git a/src/main/java/org/torproject/onionoo/server/Counter.java b/src/main/java/org/torproject/onionoo/server/Counter.java
new file mode 100644
index 0000000..655a56c
--- /dev/null
+++ b/src/main/java/org/torproject/onionoo/server/Counter.java
@@ -0,0 +1,22 @@
+/* Copyright 2014--2016 The Tor Project
+ * See LICENSE for licensing information */
+
+package org.torproject.onionoo.server;
+
+class Counter {
+
+ int value = 0;
+
+ void increment() {
+ this.value++;
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(this.value);
+ }
+
+ void clear() {
+ this.value = 0;
+ }
+}
diff --git a/src/main/java/org/torproject/onionoo/server/HttpServletRequestWrapper.java b/src/main/java/org/torproject/onionoo/server/HttpServletRequestWrapper.java
index 1aa964a..e819a1a 100644
--- a/src/main/java/org/torproject/onionoo/server/HttpServletRequestWrapper.java
+++ b/src/main/java/org/torproject/onionoo/server/HttpServletRequestWrapper.java
@@ -15,6 +15,7 @@ public class HttpServletRequestWrapper {
this.request = request;
}
+ @SuppressWarnings("abbreviationaswordinname")
protected String getRequestURI() {
return this.request.getRequestURI();
}
diff --git a/src/main/java/org/torproject/onionoo/server/IntegerDistribution.java b/src/main/java/org/torproject/onionoo/server/IntegerDistribution.java
new file mode 100644
index 0000000..c9e3a29
--- /dev/null
+++ b/src/main/java/org/torproject/onionoo/server/IntegerDistribution.java
@@ -0,0 +1,50 @@
+/* Copyright 2014--2016 The Tor Project
+ * See LICENSE for licensing information */
+
+package org.torproject.onionoo.server;
+
+import java.util.Arrays;
+
+class IntegerDistribution {
+
+ int[] logValues = new int[64];
+
+ void addLong(long value) {
+ logValues[64 - Long.numberOfLeadingZeros(value)]++;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ int totalValues = 0;
+ for (int i = 0; i < logValues.length; i++) {
+ totalValues += logValues[i];
+ }
+ int[] permilles = new int[] { 500, 900, 990, 999 };
+ if (totalValues > 0) {
+ int seenValues = 0;
+ for (int i = 0, j = 0; i < logValues.length; i++) {
+ seenValues += logValues[i];
+ while (j < permilles.length
+ && (seenValues * 1000 > totalValues * permilles[j])) {
+ sb.append((j > 0 ? ", " : "") + "." + permilles[j]
+ + (i < logValues.length - 1 ? "<" + (1L << i)
+ : ">=" + (1L << i - 1)));
+ j++;
+ }
+ if (j == permilles.length) {
+ break;
+ }
+ }
+ } else {
+ for (int j = 0; j < permilles.length; j++) {
+ sb.append((j > 0 ? ", " : "") + "." + permilles[j] + "<null");
+ }
+ }
+ return sb.toString();
+ }
+
+ void clear() {
+ Arrays.fill(logValues, 0, logValues.length - 1, 0);
+ }
+}
diff --git a/src/main/java/org/torproject/onionoo/server/MostFrequentString.java b/src/main/java/org/torproject/onionoo/server/MostFrequentString.java
new file mode 100644
index 0000000..12b5e04
--- /dev/null
+++ b/src/main/java/org/torproject/onionoo/server/MostFrequentString.java
@@ -0,0 +1,65 @@
+/* Copyright 2014--2016 The Tor Project
+ * See LICENSE for licensing information */
+
+package org.torproject.onionoo.server;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+class MostFrequentString {
+
+ Map<String, Integer> stringFrequencies = new HashMap<String, Integer>();
+
+ void addString(String string) {
+ if (!this.stringFrequencies.containsKey(string)) {
+ this.stringFrequencies.put(string, 1);
+ } else {
+ this.stringFrequencies.put(string,
+ this.stringFrequencies.get(string) + 1);
+ }
+ }
+
+ @Override
+ public String toString() {
+ SortedMap<Integer, SortedSet<String>> sortedFrequencies =
+ new TreeMap<Integer, SortedSet<String>>(
+ Collections.reverseOrder());
+ if (this.stringFrequencies.isEmpty()) {
+ return "null (0)";
+ }
+ for (Map.Entry<String, Integer> e : stringFrequencies.entrySet()) {
+ if (!sortedFrequencies.containsKey(e.getValue())) {
+ sortedFrequencies.put(e.getValue(), new TreeSet<String>(
+ Arrays.asList(new String[] { e.getKey() } )));
+ } else {
+ sortedFrequencies.get(e.getValue()).add(e.getKey());
+ }
+ }
+ StringBuilder sb = new StringBuilder();
+ int stringsToAdd = 3;
+ int written = 0;
+ for (Map.Entry<Integer, SortedSet<String>> e :
+ sortedFrequencies.entrySet()) {
+ for (String string : e.getValue()) {
+ if (stringsToAdd-- > 0) {
+ sb.append((written++ > 0 ? ", " : "") + string + " ("
+ + e.getKey() + ")");
+ }
+ }
+ if (stringsToAdd == 0) {
+ break;
+ }
+ }
+ return sb.toString();
+ }
+
+ void clear() {
+ this.stringFrequencies.clear();
+ }
+}
diff --git a/src/main/java/org/torproject/onionoo/server/NodeIndex.java b/src/main/java/org/torproject/onionoo/server/NodeIndex.java
index c000bba..7871690 100644
--- a/src/main/java/org/torproject/onionoo/server/NodeIndex.java
+++ b/src/main/java/org/torproject/onionoo/server/NodeIndex.java
@@ -86,15 +86,15 @@ class NodeIndex {
return relaysByCountryCode;
}
- private Map<String, Set<String>> relaysByASNumber = null;
+ private Map<String, Set<String>> relaysByAsNumber = null;
- public void setRelaysByASNumber(
- Map<String, Set<String>> relaysByASNumber) {
- this.relaysByASNumber = relaysByASNumber;
+ public void setRelaysByAsNumber(
+ Map<String, Set<String>> relaysByAsNumber) {
+ this.relaysByAsNumber = relaysByAsNumber;
}
- public Map<String, Set<String>> getRelaysByASNumber() {
- return relaysByASNumber;
+ public Map<String, Set<String>> getRelaysByAsNumber() {
+ return relaysByAsNumber;
}
private Map<String, Set<String>> relaysByFlag = null;
diff --git a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
index 93b5af7..99d1aee 100644
--- a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
+++ b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
@@ -71,6 +71,8 @@ public class NodeIndexer implements ServletContextListener, Runnable {
try {
this.wait(timeoutMillis);
} catch (InterruptedException e) {
+ /* Nothing that we could handle, just return what we have
+ * below. */
}
}
return this.lastIndexed;
@@ -84,6 +86,8 @@ public class NodeIndexer implements ServletContextListener, Runnable {
try {
this.wait(timeoutMillis);
} catch (InterruptedException e) {
+ /* Nothing that we could handle, just return what we have
+ * below. */
}
}
return this.latestNodeIndex;
@@ -110,6 +114,8 @@ public class NodeIndexer implements ServletContextListener, Runnable {
try {
Thread.sleep(ONE_MINUTE);
} catch (InterruptedException e) {
+ /* Nothing that we could handle, just check if there's new data
+ * to index now. */
}
}
}
@@ -137,14 +143,13 @@ public class NodeIndexer implements ServletContextListener, Runnable {
}
}
documentStore.invalidateDocumentCache();
- List<String> newRelaysByConsensusWeight = new ArrayList<String>();
Map<String, SummaryDocument> newRelayFingerprintSummaryLines =
new HashMap<String, SummaryDocument>();
Map<String, SummaryDocument> newBridgeFingerprintSummaryLines =
new HashMap<String, SummaryDocument>();
Map<String, Set<String>> newRelaysByCountryCode =
new HashMap<String, Set<String>>();
- Map<String, Set<String>> newRelaysByASNumber =
+ Map<String, Set<String>> newRelaysByAsNumber =
new HashMap<String, Set<String>>();
Map<String, Set<String>> newRelaysByFlag =
new HashMap<String, Set<String>>();
@@ -208,13 +213,13 @@ public class NodeIndexer implements ServletContextListener, Runnable {
newRelaysByCountryCode.get(countryCode).add(fingerprint);
newRelaysByCountryCode.get(countryCode).add(hashedFingerprint);
}
- if (entry.getASNumber() != null) {
- String aSNumber = entry.getASNumber();
- if (!newRelaysByASNumber.containsKey(aSNumber)) {
- newRelaysByASNumber.put(aSNumber, new HashSet<String>());
+ if (entry.getAsNumber() != null) {
+ String asNumber = entry.getAsNumber();
+ if (!newRelaysByAsNumber.containsKey(asNumber)) {
+ newRelaysByAsNumber.put(asNumber, new HashSet<String>());
}
- newRelaysByASNumber.get(aSNumber).add(fingerprint);
- newRelaysByASNumber.get(aSNumber).add(hashedFingerprint);
+ newRelaysByAsNumber.get(asNumber).add(fingerprint);
+ newRelaysByAsNumber.get(asNumber).add(hashedFingerprint);
}
for (String flag : entry.getRelayFlags()) {
String flagLowerCase = flag.toLowerCase();
@@ -261,7 +266,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
newRelaysByContact.get(contact).add(hashedFingerprint);
}
Collections.sort(orderRelaysByConsensusWeight);
- newRelaysByConsensusWeight = new ArrayList<String>();
+ List<String> newRelaysByConsensusWeight = new ArrayList<String>();
for (String relay : orderRelaysByConsensusWeight) {
newRelaysByConsensusWeight.add(relay.split(" ")[1]);
}
@@ -325,7 +330,7 @@ public class NodeIndexer implements ServletContextListener, Runnable {
newNodeIndex.setBridgeFingerprintSummaryLines(
newBridgeFingerprintSummaryLines);
newNodeIndex.setRelaysByCountryCode(newRelaysByCountryCode);
- newNodeIndex.setRelaysByASNumber(newRelaysByASNumber);
+ newNodeIndex.setRelaysByAsNumber(newRelaysByAsNumber);
newNodeIndex.setRelaysByFlag(newRelaysByFlag);
newNodeIndex.setBridgesByFlag(newBridgesByFlag);
newNodeIndex.setRelaysByContact(newRelaysByContact);
diff --git a/src/main/java/org/torproject/onionoo/server/PerformanceMetrics.java b/src/main/java/org/torproject/onionoo/server/PerformanceMetrics.java
index 7adad76..7a621cf 100644
--- a/src/main/java/org/torproject/onionoo/server/PerformanceMetrics.java
+++ b/src/main/java/org/torproject/onionoo/server/PerformanceMetrics.java
@@ -11,130 +11,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.SimpleDateFormat;
-import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.SortedMap;
-import java.util.SortedSet;
import java.util.TimeZone;
-import java.util.TreeMap;
-import java.util.TreeSet;
-
-class Counter {
-
- int value = 0;
-
- void increment() {
- this.value++;
- }
-
- @Override
- public String toString() {
- return String.valueOf(this.value);
- }
-
- void clear() {
- this.value = 0;
- }
-}
-
-class MostFrequentString {
-
- Map<String, Integer> stringFrequencies = new HashMap<String, Integer>();
-
- void addString(String string) {
- if (!this.stringFrequencies.containsKey(string)) {
- this.stringFrequencies.put(string, 1);
- } else {
- this.stringFrequencies.put(string,
- this.stringFrequencies.get(string) + 1);
- }
- }
-
- @Override
- public String toString() {
- SortedMap<Integer, SortedSet<String>> sortedFrequencies =
- new TreeMap<Integer, SortedSet<String>>(
- Collections.reverseOrder());
- if (this.stringFrequencies.isEmpty()) {
- return "null (0)";
- }
- for (Map.Entry<String, Integer> e : stringFrequencies.entrySet()) {
- if (!sortedFrequencies.containsKey(e.getValue())) {
- sortedFrequencies.put(e.getValue(), new TreeSet<String>(
- Arrays.asList(new String[] { e.getKey() } )));
- } else {
- sortedFrequencies.get(e.getValue()).add(e.getKey());
- }
- }
- StringBuilder sb = new StringBuilder();
- int stringsToAdd = 3;
- int written = 0;
- for (Map.Entry<Integer, SortedSet<String>> e :
- sortedFrequencies.entrySet()) {
- for (String string : e.getValue()) {
- if (stringsToAdd-- > 0) {
- sb.append((written++ > 0 ? ", " : "") + string + " ("
- + e.getKey() + ")");
- }
- }
- if (stringsToAdd == 0) {
- break;
- }
- }
- return sb.toString();
- }
-
- void clear() {
- this.stringFrequencies.clear();
- }
-}
-
-class IntegerDistribution {
-
- int[] logValues = new int[64];
-
- void addLong(long value) {
- logValues[64 - Long.numberOfLeadingZeros(value)]++;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- int totalValues = 0;
- for (int i = 0; i < logValues.length; i++) {
- totalValues += logValues[i];
- }
- int[] permilles = new int[] { 500, 900, 990, 999 };
- if (totalValues > 0) {
- int seenValues = 0;
- for (int i = 0, j = 0; i < logValues.length; i++) {
- seenValues += logValues[i];
- while (j < permilles.length
- && (seenValues * 1000 > totalValues * permilles[j])) {
- sb.append((j > 0 ? ", " : "") + "." + permilles[j]
- + (i < logValues.length - 1 ? "<" + (1L << i)
- : ">=" + (1L << i - 1)));
- j++;
- }
- if (j == permilles.length) {
- break;
- }
- }
- } else {
- for (int j = 0; j < permilles.length; j++) {
- sb.append((j > 0 ? ", " : "") + "." + permilles[j] + "<null");
- }
- }
- return sb.toString();
- }
-
- void clear() {
- Arrays.fill(logValues, 0, logValues.length - 1, 0);
- }
-}
public class PerformanceMetrics {
diff --git a/src/main/java/org/torproject/onionoo/server/RequestHandler.java b/src/main/java/org/torproject/onionoo/server/RequestHandler.java
index eaa4fe2..49b3b94 100644
--- a/src/main/java/org/torproject/onionoo/server/RequestHandler.java
+++ b/src/main/java/org/torproject/onionoo/server/RequestHandler.java
@@ -153,7 +153,7 @@ public class RequestHandler {
this.filterByLookup();
this.filterByFingerprint();
this.filterByCountryCode();
- this.filterByASNumber();
+ this.filterByAsNumber();
this.filterByFlag();
this.filterNodesByFirstSeenDays();
this.filterNodesByLastSeenDays();
@@ -369,23 +369,23 @@ public class RequestHandler {
this.filteredBridges.clear();
}
- private void filterByASNumber() {
+ private void filterByAsNumber() {
if (this.as == null) {
/* Not filtering by AS number. */
return;
}
- String aSNumber = this.as.toUpperCase();
- if (!aSNumber.startsWith("AS")) {
- aSNumber = "AS" + aSNumber;
+ String asNumber = this.as.toUpperCase();
+ if (!asNumber.startsWith("AS")) {
+ asNumber = "AS" + asNumber;
}
- if (!this.nodeIndex.getRelaysByASNumber().containsKey(aSNumber)) {
+ if (!this.nodeIndex.getRelaysByAsNumber().containsKey(asNumber)) {
this.filteredRelays.clear();
} else {
- Set<String> relaysWithASNumber =
- this.nodeIndex.getRelaysByASNumber().get(aSNumber);
+ Set<String> relaysWithAsNumber =
+ this.nodeIndex.getRelaysByAsNumber().get(asNumber);
Set<String> removeRelays = new HashSet<String>();
for (String fingerprint : this.filteredRelays.keySet()) {
- if (!relaysWithASNumber.contains(fingerprint)) {
+ if (!relaysWithAsNumber.contains(fingerprint)) {
removeRelays.add(fingerprint);
}
}
diff --git a/src/main/java/org/torproject/onionoo/server/ResourceServlet.java b/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
index 5b3ab69..92d0d81 100644
--- a/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
+++ b/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
@@ -78,6 +78,7 @@ public class ResourceServlet extends HttpServlet {
/** Handles the HTTP GET request in the wrapped <code>request</code> by
* writing an HTTP GET response to the likewise <code>response</code>,
* both of which are wrapped to facilitate testing. */
+ @SuppressWarnings("checkstyle:variabledeclarationusagedistance")
public void doGet(HttpServletRequestWrapper request,
HttpServletResponseWrapper response) throws IOException {
@@ -86,15 +87,6 @@ public class ResourceServlet extends HttpServlet {
return;
}
- long nowMillis = TimeFactory.getTime().currentTimeMillis();
- long indexWrittenMillis =
- NodeIndexerFactory.getNodeIndexer().getLastIndexed(
- INDEX_WAITING_TIME);
- long indexAgeMillis = nowMillis - indexWrittenMillis;
- long cacheMaxAgeMillis = Math.max(CACHE_MIN_TIME,
- ((CACHE_MAX_TIME - indexAgeMillis)
- / CACHE_INTERVAL) * CACHE_INTERVAL);
-
NodeIndex nodeIndex = NodeIndexerFactory.getNodeIndexer()
.getLatestNodeIndex(INDEX_WAITING_TIME);
if (nodeIndex == null) {
@@ -230,13 +222,13 @@ public class ResourceServlet extends HttpServlet {
rh.setCountry(countryCodeParameter);
}
if (parameterMap.containsKey("as")) {
- String aSNumberParameter = this.parseASNumberParameter(
+ String asNumberParameter = this.parseAsNumberParameter(
parameterMap.get("as"));
- if (aSNumberParameter == null) {
+ if (asNumberParameter == null) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
- rh.setAs(aSNumberParameter);
+ rh.setAs(asNumberParameter);
}
if (parameterMap.containsKey("flag")) {
String flagParameter = this.parseFlagParameter(
@@ -343,6 +335,14 @@ public class ResourceServlet extends HttpServlet {
rb.setFields(fields);
}
+ long indexWrittenMillis =
+ NodeIndexerFactory.getNodeIndexer().getLastIndexed(
+ INDEX_WAITING_TIME);
+ long indexAgeMillis = receivedRequestMillis - indexWrittenMillis;
+ long cacheMaxAgeMillis = Math.max(CACHE_MIN_TIME,
+ ((CACHE_MAX_TIME - indexAgeMillis)
+ / CACHE_INTERVAL) * CACHE_INTERVAL);
+
response.setHeader("Access-Control-Allow-Origin", "*");
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
@@ -418,11 +418,11 @@ public class ResourceServlet extends HttpServlet {
return parameter;
}
- private static Pattern aSNumberParameterPattern =
+ private static Pattern asNumberParameterPattern =
Pattern.compile("^[asAS]{0,2}[0-9]{1,10}$");
- private String parseASNumberParameter(String parameter) {
- if (!aSNumberParameterPattern.matcher(parameter).matches()) {
+ private String parseAsNumberParameter(String parameter) {
+ if (!asNumberParameterPattern.matcher(parameter).matches()) {
/* AS number contains illegal character(s). */
return null;
}
@@ -447,30 +447,30 @@ public class ResourceServlet extends HttpServlet {
/* Days contain illegal character(s). */
return null;
}
- int x = 0;
- int y = Integer.MAX_VALUE;
+ int fromDays = 0;
+ int toDays = Integer.MAX_VALUE;
try {
if (!parameter.contains("-")) {
- x = Integer.parseInt(parameter);
- y = x;
+ fromDays = Integer.parseInt(parameter);
+ toDays = fromDays;
} else {
String[] parts = parameter.split("-", 2);
if (parts[0].length() > 0) {
- x = Integer.parseInt(parts[0]);
+ fromDays = Integer.parseInt(parts[0]);
}
if (parts.length > 1 && parts[1].length() > 0) {
- y = Integer.parseInt(parts[1]);
+ toDays = Integer.parseInt(parts[1]);
}
}
} catch (NumberFormatException e) {
/* Invalid format. */
return null;
}
- if (x > y) {
+ if (fromDays > toDays) {
/* Second number or days must exceed first number. */
return null;
}
- return new int[] { x, y };
+ return new int[] { fromDays, toDays };
}
private String[] parseContactParameter(String parameter) {
diff --git a/src/main/java/org/torproject/onionoo/updater/DescriptorDownloader.java b/src/main/java/org/torproject/onionoo/updater/DescriptorDownloader.java
index 71a43d2..5822b77 100644
--- a/src/main/java/org/torproject/onionoo/updater/DescriptorDownloader.java
+++ b/src/main/java/org/torproject/onionoo/updater/DescriptorDownloader.java
@@ -79,8 +79,8 @@ class DescriptorDownloader {
String directoryUrl = this.protocolHostNameResourcePrefix
+ this.directory;
try {
- URL u = new URL(directoryUrl);
- HttpURLConnection huc = (HttpURLConnection) u.openConnection();
+ URL url = new URL(directoryUrl);
+ HttpURLConnection huc = (HttpURLConnection) url.openConnection();
huc.setRequestMethod("GET");
huc.connect();
if (huc.getResponseCode() != 200) {
@@ -129,8 +129,8 @@ class DescriptorDownloader {
File localFile = new File(this.inDir, this.directory + remoteFile);
try {
localFile.getParentFile().mkdirs();
- URL u = new URL(fileUrl);
- HttpURLConnection huc = (HttpURLConnection) u.openConnection();
+ URL url = new URL(fileUrl);
+ HttpURLConnection huc = (HttpURLConnection) url.openConnection();
huc.setRequestMethod("GET");
huc.addRequestProperty("Accept-Encoding", "gzip");
huc.connect();
@@ -140,7 +140,6 @@ class DescriptorDownloader {
+ huc.getResponseMessage() + ". Skipping.");
continue;
}
- long lastModified = huc.getHeaderFieldDate("Last-Modified", -1L);
InputStream is;
if (huc.getContentEncoding() != null
&& huc.getContentEncoding().equalsIgnoreCase("gzip")) {
@@ -158,6 +157,7 @@ class DescriptorDownloader {
}
}
localTempFile.renameTo(localFile);
+ long lastModified = huc.getHeaderFieldDate("Last-Modified", -1L);
if (lastModified >= 0) {
localFile.setLastModified(lastModified);
}
diff --git a/src/main/java/org/torproject/onionoo/updater/DescriptorSource.java b/src/main/java/org/torproject/onionoo/updater/DescriptorSource.java
index 176a17c..c251142 100644
--- a/src/main/java/org/torproject/onionoo/updater/DescriptorSource.java
+++ b/src/main/java/org/torproject/onionoo/updater/DescriptorSource.java
@@ -156,6 +156,12 @@ public class DescriptorSource {
case BRIDGE_EXTRA_INFOS:
log.info("Read recent bridge extra-info descriptors");
break;
+ default:
+ /* We shouldn't run into this default case, but if we do, it's
+ * because we added a new type to DescriptorType but forgot to
+ * update this switch statement. It's just logging, so not the
+ * end of the world. */
+ log.info("Read recent descriptors of type " + descriptorType);
}
}
diff --git a/src/main/java/org/torproject/onionoo/updater/LookupService.java b/src/main/java/org/torproject/onionoo/updater/LookupService.java
index 2b0993f..ec63751 100644
--- a/src/main/java/org/torproject/onionoo/updater/LookupService.java
+++ b/src/main/java/org/torproject/onionoo/updater/LookupService.java
@@ -39,7 +39,7 @@ public class LookupService {
private File geoLite2CityLocationsEnCsvFile;
- private File geoIPASNum2CsvFile;
+ private File geoIpAsNum2CsvFile;
private boolean hasAllFiles = false;
@@ -63,8 +63,8 @@ public class LookupService {
+ "geoip/.");
return;
}
- this.geoIPASNum2CsvFile = new File(this.geoipDir, "GeoIPASNum2.csv");
- if (!this.geoIPASNum2CsvFile.exists()) {
+ this.geoIpAsNum2CsvFile = new File(this.geoipDir, "GeoIPASNum2.csv");
+ if (!this.geoIpAsNum2CsvFile.exists()) {
log.error("No GeoIPASNum2.csv file in geoip/.");
return;
}
@@ -85,6 +85,7 @@ public class LookupService {
try {
octetValue = Integer.parseInt(parts[i]);
} catch (NumberFormatException e) {
+ /* Handled below, because octetValue will still be -1. */
}
if (octetValue < 0 || octetValue > 255) {
addressNumber = -1L;
@@ -228,9 +229,9 @@ public class LookupService {
}
/* Obtain a map from IP address numbers to ASN. */
- Map<Long, String> addressNumberASN = new HashMap<Long, String>();
+ Map<Long, String> addressNumberAsn = new HashMap<Long, String>();
try (BufferedReader br = this.createBufferedReaderFromIso88591File(
- this.geoIPASNum2CsvFile)) {
+ this.geoIpAsNum2CsvFile)) {
SortedSet<Long> sortedAddressNumbers = new TreeSet<Long>(
addressStringNumbers.values());
long firstAddressNumber = sortedAddressNumbers.first();
@@ -240,14 +241,14 @@ public class LookupService {
String[] parts = line.replaceAll("\"", "").split(",", 3);
if (parts.length != 3) {
log.error("Illegal line '" + line + "' in "
- + geoIPASNum2CsvFile.getAbsolutePath() + ".");
+ + geoIpAsNum2CsvFile.getAbsolutePath() + ".");
return lookupResults;
}
try {
long startIpNum = Long.parseLong(parts[0]);
if (startIpNum <= previousStartIpNum) {
log.error("Line '" + line + "' not sorted in "
- + geoIPASNum2CsvFile.getAbsolutePath() + ".");
+ + geoIpAsNum2CsvFile.getAbsolutePath() + ".");
return lookupResults;
}
previousStartIpNum = startIpNum;
@@ -264,7 +265,7 @@ public class LookupService {
while (firstAddressNumber <= endIpNum
&& firstAddressNumber != -1L) {
if (parts[2].startsWith("AS")) {
- addressNumberASN.put(firstAddressNumber, parts[2]);
+ addressNumberAsn.put(firstAddressNumber, parts[2]);
}
sortedAddressNumbers.remove(firstAddressNumber);
if (sortedAddressNumbers.isEmpty()) {
@@ -279,13 +280,13 @@ public class LookupService {
} catch (NumberFormatException e) {
log.error("Number format exception while parsing line "
+ "'" + line + "' in "
- + geoIPASNum2CsvFile.getAbsolutePath() + ".");
+ + geoIpAsNum2CsvFile.getAbsolutePath() + ".");
return lookupResults;
}
}
} catch (IOException e) {
log.error("I/O exception while reading "
- + geoIPASNum2CsvFile.getAbsolutePath() + ": " + e);
+ + geoIpAsNum2CsvFile.getAbsolutePath() + ": " + e);
return lookupResults;
}
@@ -297,7 +298,7 @@ public class LookupService {
long addressNumber = addressStringNumbers.get(addressString);
if (!addressNumberBlocks.containsKey(addressNumber)
&& !addressNumberLatLong.containsKey(addressNumber)
- && !addressNumberASN.containsKey(addressNumber)) {
+ && !addressNumberAsn.containsKey(addressNumber)) {
continue;
}
LookupResult lookupResult = new LookupResult();
@@ -325,8 +326,8 @@ public class LookupService {
lookupResult.setLatitude(latLong[0]);
lookupResult.setLongitude(latLong[1]);
}
- if (addressNumberASN.containsKey(addressNumber)) {
- String[] parts = addressNumberASN.get(addressNumber).split(" ",
+ if (addressNumberAsn.containsKey(addressNumber)) {
+ String[] parts = addressNumberAsn.get(addressNumber).split(" ",
2);
lookupResult.setAsNumber(parts[0]);
lookupResult.setAsName(parts.length == 2 ? parts[1] : "");
diff --git a/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java b/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
index d873072..a66aba8 100644
--- a/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
+++ b/src/main/java/org/torproject/onionoo/updater/NodeDetailsStatusUpdater.java
@@ -492,7 +492,7 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
updatedNodeStatus.setDefaultPolicy(
nodeStatus.getDefaultPolicy());
updatedNodeStatus.setPortList(nodeStatus.getPortList());
- updatedNodeStatus.setASNumber(nodeStatus.getASNumber());
+ updatedNodeStatus.setAsNumber(nodeStatus.getAsNumber());
updatedNodeStatus.setRecommendedVersion(
nodeStatus.getRecommendedVersion());
}
@@ -862,10 +862,10 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
detailsStatus.setCityName(lookupResult.getCityName());
detailsStatus.setLatitude(lookupResult.getLatitude());
detailsStatus.setLongitude(lookupResult.getLongitude());
- detailsStatus.setASNumber(lookupResult.getAsNumber());
- detailsStatus.setASName(lookupResult.getAsName());
+ detailsStatus.setAsNumber(lookupResult.getAsNumber());
+ detailsStatus.setAsName(lookupResult.getAsName());
nodeStatus.setCountryCode(lookupResult.getCountryCode());
- nodeStatus.setASNumber(lookupResult.getAsNumber());
+ nodeStatus.setAsNumber(lookupResult.getAsNumber());
}
if (this.consensusWeightFractions.containsKey(fingerprint)) {
diff --git a/src/main/java/org/torproject/onionoo/writer/BandwidthDocumentWriter.java b/src/main/java/org/torproject/onionoo/writer/BandwidthDocumentWriter.java
index 7238c1b..33b943e 100644
--- a/src/main/java/org/torproject/onionoo/writer/BandwidthDocumentWriter.java
+++ b/src/main/java/org/torproject/onionoo/writer/BandwidthDocumentWriter.java
@@ -107,12 +107,11 @@ public class BandwidthDocumentWriter implements DocumentWriter {
long totalMillis = 0L;
long totalBandwidth = 0L;
for (long[] v : history.values()) {
- long startMillis = v[0];
long endMillis = v[1];
- long bandwidth = v[2];
if (endMillis < intervalStartMillis) {
continue;
}
+ long startMillis = v[0];
if (endMillis - startMillis > dataPointInterval) {
/* This history interval is too long for this graph's data point
* interval. Maybe the next graph will contain it, but not this
@@ -128,6 +127,7 @@ public class BandwidthDocumentWriter implements DocumentWriter {
totalMillis = 0L;
intervalStartMillis += dataPointInterval;
}
+ long bandwidth = v[2];
totalBandwidth += bandwidth;
totalMillis += (endMillis - startMillis);
}
diff --git a/src/main/java/org/torproject/onionoo/writer/DetailsDocumentWriter.java b/src/main/java/org/torproject/onionoo/writer/DetailsDocumentWriter.java
index c167152..1c515e8 100644
--- a/src/main/java/org/torproject/onionoo/writer/DetailsDocumentWriter.java
+++ b/src/main/java/org/torproject/onionoo/writer/DetailsDocumentWriter.java
@@ -94,8 +94,8 @@ public class DetailsDocumentWriter implements DocumentWriter {
detailsDocument.setCountryName(detailsStatus.getCountryName());
detailsDocument.setRegionName(detailsStatus.getRegionName());
detailsDocument.setCityName(detailsStatus.getCityName());
- detailsDocument.setAsNumber(detailsStatus.getASNumber());
- detailsDocument.setAsName(detailsStatus.getASName());
+ detailsDocument.setAsNumber(detailsStatus.getAsNumber());
+ detailsDocument.setAsName(detailsStatus.getAsName());
if (detailsStatus.isRunning()) {
detailsDocument.setConsensusWeightFraction(
detailsStatus.getConsensusWeightFraction());
diff --git a/src/main/java/org/torproject/onionoo/writer/SummaryDocumentWriter.java b/src/main/java/org/torproject/onionoo/writer/SummaryDocumentWriter.java
index f941ee3..e9bb8f6 100644
--- a/src/main/java/org/torproject/onionoo/writer/SummaryDocumentWriter.java
+++ b/src/main/java/org/torproject/onionoo/writer/SummaryDocumentWriter.java
@@ -65,8 +65,6 @@ public class SummaryDocumentWriter implements DocumentWriter {
}
continue;
}
- boolean isRelay = nodeStatus.isRelay();
- String nickname = nodeStatus.getNickname();
List<String> addresses = new ArrayList<String>();
addresses.add(nodeStatus.getAddress());
for (String orAddress : nodeStatus.getOrAddresses()) {
@@ -81,20 +79,22 @@ public class SummaryDocumentWriter implements DocumentWriter {
}
long lastSeenMillis = nodeStatus.getLastSeenMillis();
SortedSet<String> relayFlags = nodeStatus.getRelayFlags();
+ boolean isRelay = nodeStatus.isRelay();
boolean running = relayFlags.contains("Running") && (isRelay
? lastSeenMillis == relaysLastValidAfterMillis
: lastSeenMillis == bridgesLastPublishedMillis);
long consensusWeight = nodeStatus.getConsensusWeight();
String countryCode = nodeStatus.getCountryCode();
long firstSeenMillis = nodeStatus.getFirstSeenMillis();
- String aSNumber = nodeStatus.getASNumber();
+ String asNumber = nodeStatus.getAsNumber();
String contact = nodeStatus.getContact();
SortedSet<String> declaredFamily = nodeStatus.getDeclaredFamily();
SortedSet<String> effectiveFamily = nodeStatus.getEffectiveFamily();
+ String nickname = nodeStatus.getNickname();
SummaryDocument summaryDocument = new SummaryDocument(isRelay,
nickname, fingerprint, addresses, lastSeenMillis, running,
relayFlags, consensusWeight, countryCode, firstSeenMillis,
- aSNumber, contact, declaredFamily, effectiveFamily);
+ asNumber, contact, declaredFamily, effectiveFamily);
if (this.documentStore.store(summaryDocument, fingerprint)) {
this.writtenDocuments++;
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits