[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [onionoo/master] Reduce visibility of attributes to private.
commit 1635812bdd5326c265eb4cdeae751b29d8deae95
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Tue Apr 8 23:41:50 2014 +0200
Reduce visibility of attributes to private.
Suggested by SonarQube.
---
.../onionoo/BandwidthDocumentWriter.java | 5 +-
src/org/torproject/onionoo/BandwidthStatus.java | 18 +-
.../torproject/onionoo/BandwidthStatusUpdater.java | 8 +-
.../torproject/onionoo/ClientsDocumentWriter.java | 22 +-
src/org/torproject/onionoo/ClientsStatus.java | 39 +-
.../torproject/onionoo/ClientsStatusUpdater.java | 27 +-
src/org/torproject/onionoo/DescriptorSource.java | 28 +-
.../torproject/onionoo/DetailsDocumentWriter.java | 15 +-
src/org/torproject/onionoo/Document.java | 8 +-
src/org/torproject/onionoo/DocumentStore.java | 12 +-
src/org/torproject/onionoo/LookupService.java | 104 +++--
.../onionoo/NodeDetailsStatusUpdater.java | 31 +-
src/org/torproject/onionoo/NodeStatus.java | 456 +++++++++++---------
src/org/torproject/onionoo/ResponseBuilder.java | 25 +-
.../onionoo/ReverseDomainNameResolver.java | 6 +-
.../torproject/onionoo/UptimeDocumentWriter.java | 42 +-
src/org/torproject/onionoo/UptimeStatus.java | 23 +-
.../torproject/onionoo/UptimeStatusUpdater.java | 22 +-
.../torproject/onionoo/WeightsDocumentWriter.java | 6 +-
src/org/torproject/onionoo/WeightsStatus.java | 15 +-
.../torproject/onionoo/WeightsStatusUpdater.java | 12 +-
.../org/torproject/onionoo/DummyDocumentStore.java | 2 +-
test/org/torproject/onionoo/LookupServiceTest.java | 33 +-
23 files changed, 567 insertions(+), 392 deletions(-)
diff --git a/src/org/torproject/onionoo/BandwidthDocumentWriter.java b/src/org/torproject/onionoo/BandwidthDocumentWriter.java
index 0c7308e..8e9b93c 100644
--- a/src/org/torproject/onionoo/BandwidthDocumentWriter.java
+++ b/src/org/torproject/onionoo/BandwidthDocumentWriter.java
@@ -49,7 +49,8 @@ public class BandwidthDocumentWriter implements FingerprintListener,
continue;
}
this.writeBandwidthDataFileToDisk(fingerprint,
- bandwidthStatus.writeHistory, bandwidthStatus.readHistory);
+ bandwidthStatus.getWriteHistory(),
+ bandwidthStatus.getReadHistory());
}
Logger.printStatusTime("Wrote bandwidth document files");
}
@@ -64,7 +65,7 @@ public class BandwidthDocumentWriter implements FingerprintListener,
+ "\"write_history\":{\n" + writeHistoryString + "},\n"
+ "\"read_history\":{\n" + readHistoryString + "}}\n");
BandwidthDocument bandwidthDocument = new BandwidthDocument();
- bandwidthDocument.documentString = sb.toString();
+ bandwidthDocument.setDocumentString(sb.toString());
this.documentStore.store(bandwidthDocument, fingerprint);
}
diff --git a/src/org/torproject/onionoo/BandwidthStatus.java b/src/org/torproject/onionoo/BandwidthStatus.java
index 00e8ca8..37bbc8d 100644
--- a/src/org/torproject/onionoo/BandwidthStatus.java
+++ b/src/org/torproject/onionoo/BandwidthStatus.java
@@ -8,9 +8,23 @@ import java.util.TreeMap;
class BandwidthStatus extends Document {
- SortedMap<Long, long[]> writeHistory = new TreeMap<Long, long[]>();
+ private SortedMap<Long, long[]> writeHistory =
+ new TreeMap<Long, long[]>();
+ public void setWriteHistory(SortedMap<Long, long[]> writeHistory) {
+ this.writeHistory = writeHistory;
+ }
+ public SortedMap<Long, long[]> getWriteHistory() {
+ return this.writeHistory;
+ }
- SortedMap<Long, long[]> readHistory = new TreeMap<Long, long[]>();
+ private SortedMap<Long, long[]> readHistory =
+ new TreeMap<Long, long[]>();
+ public void setReadHistory(SortedMap<Long, long[]> readHistory) {
+ this.readHistory = readHistory;
+ }
+ public SortedMap<Long, long[]> getReadHistory() {
+ return this.readHistory;
+ }
public void fromDocumentString(String documentString) {
Scanner s = new Scanner(documentString);
diff --git a/src/org/torproject/onionoo/BandwidthStatusUpdater.java b/src/org/torproject/onionoo/BandwidthStatusUpdater.java
index 6aff25d..7633e9f 100644
--- a/src/org/torproject/onionoo/BandwidthStatusUpdater.java
+++ b/src/org/torproject/onionoo/BandwidthStatusUpdater.java
@@ -51,14 +51,14 @@ public class BandwidthStatusUpdater implements DescriptorListener,
}
if (descriptor.getWriteHistory() != null) {
parseHistoryLine(descriptor.getWriteHistory().getLine(),
- bandwidthStatus.writeHistory);
+ bandwidthStatus.getWriteHistory());
}
if (descriptor.getReadHistory() != null) {
parseHistoryLine(descriptor.getReadHistory().getLine(),
- bandwidthStatus.readHistory);
+ bandwidthStatus.getReadHistory());
}
- this.compressHistory(bandwidthStatus.writeHistory);
- this.compressHistory(bandwidthStatus.readHistory);
+ this.compressHistory(bandwidthStatus.getWriteHistory());
+ this.compressHistory(bandwidthStatus.getReadHistory());
this.documentStore.store(bandwidthStatus, fingerprint);
}
diff --git a/src/org/torproject/onionoo/ClientsDocumentWriter.java b/src/org/torproject/onionoo/ClientsDocumentWriter.java
index d9ff02d..34047b5 100644
--- a/src/org/torproject/onionoo/ClientsDocumentWriter.java
+++ b/src/org/torproject/onionoo/ClientsDocumentWriter.java
@@ -74,10 +74,10 @@ public class ClientsDocumentWriter implements FingerprintListener,
if (clientsStatus == null) {
continue;
}
- SortedSet<ClientsHistory> history = clientsStatus.history;
+ SortedSet<ClientsHistory> history = clientsStatus.getHistory();
ClientsDocument clientsDocument = new ClientsDocument();
- clientsDocument.documentString = this.formatHistoryString(
- hashedFingerprint, history);
+ clientsDocument.setDocumentString(this.formatHistoryString(
+ hashedFingerprint, history));
this.documentStore.store(clientsDocument, hashedFingerprint);
this.writtenDocuments++;
}
@@ -140,11 +140,11 @@ public class ClientsDocumentWriter implements FingerprintListener,
totalResponsesByTransport = new TreeMap<String, Double>(),
totalResponsesByVersion = new TreeMap<String, Double>();
for (ClientsHistory hist : history) {
- if (hist.endMillis < intervalStartMillis) {
+ if (hist.getEndMillis() < intervalStartMillis) {
continue;
}
while ((intervalStartMillis / dataPointInterval) !=
- (hist.endMillis / dataPointInterval)) {
+ (hist.getEndMillis() / dataPointInterval)) {
dataPoints.add(millis * 2L < dataPointInterval
? -1.0 : responses * ((double) DateTimeHelper.ONE_DAY)
/ (((double) millis) * 10.0));
@@ -152,10 +152,10 @@ public class ClientsDocumentWriter implements FingerprintListener,
millis = 0L;
intervalStartMillis += dataPointInterval;
}
- responses += hist.totalResponses;
- totalResponses += hist.totalResponses;
+ responses += hist.getTotalResponses();
+ totalResponses += hist.getTotalResponses();
for (Map.Entry<String, Double> e :
- hist.responsesByCountry.entrySet()) {
+ hist.getResponsesByCountry().entrySet()) {
if (!totalResponsesByCountry.containsKey(e.getKey())) {
totalResponsesByCountry.put(e.getKey(), 0.0);
}
@@ -163,7 +163,7 @@ public class ClientsDocumentWriter implements FingerprintListener,
+ totalResponsesByCountry.get(e.getKey()));
}
for (Map.Entry<String, Double> e :
- hist.responsesByTransport.entrySet()) {
+ hist.getResponsesByTransport().entrySet()) {
if (!totalResponsesByTransport.containsKey(e.getKey())) {
totalResponsesByTransport.put(e.getKey(), 0.0);
}
@@ -171,14 +171,14 @@ public class ClientsDocumentWriter implements FingerprintListener,
+ totalResponsesByTransport.get(e.getKey()));
}
for (Map.Entry<String, Double> e :
- hist.responsesByVersion.entrySet()) {
+ hist.getResponsesByVersion().entrySet()) {
if (!totalResponsesByVersion.containsKey(e.getKey())) {
totalResponsesByVersion.put(e.getKey(), 0.0);
}
totalResponsesByVersion.put(e.getKey(), e.getValue()
+ totalResponsesByVersion.get(e.getKey()));
}
- millis += (hist.endMillis - hist.startMillis);
+ millis += (hist.getEndMillis() - hist.getStartMillis());
}
dataPoints.add(millis * 2L < dataPointInterval
? -1.0 : responses * ((double) DateTimeHelper.ONE_DAY)
diff --git a/src/org/torproject/onionoo/ClientsStatus.java b/src/org/torproject/onionoo/ClientsStatus.java
index 26f9eab..8bf0998 100644
--- a/src/org/torproject/onionoo/ClientsStatus.java
+++ b/src/org/torproject/onionoo/ClientsStatus.java
@@ -11,17 +11,35 @@ import java.util.TreeSet;
class ClientsHistory implements Comparable<ClientsHistory> {
- long startMillis;
+ private long startMillis;
+ public long getStartMillis() {
+ return this.startMillis;
+ }
- long endMillis;
+ private long endMillis;
+ public long getEndMillis() {
+ return this.endMillis;
+ }
- double totalResponses;
+ private double totalResponses;
+ public double getTotalResponses() {
+ return this.totalResponses;
+ }
- SortedMap<String, Double> responsesByCountry;
+ private SortedMap<String, Double> responsesByCountry;
+ public SortedMap<String, Double> getResponsesByCountry() {
+ return this.responsesByCountry;
+ }
- SortedMap<String, Double> responsesByTransport;
+ private SortedMap<String, Double> responsesByTransport;
+ public SortedMap<String, Double> getResponsesByTransport() {
+ return this.responsesByTransport;
+ }
- SortedMap<String, Double> responsesByVersion;
+ private SortedMap<String, Double> responsesByVersion;
+ public SortedMap<String, Double> getResponsesByVersion() {
+ return this.responsesByVersion;
+ }
ClientsHistory(long startMillis, long endMillis,
double totalResponses,
@@ -158,7 +176,14 @@ class ClientsHistory implements Comparable<ClientsHistory> {
class ClientsStatus extends Document {
- SortedSet<ClientsHistory> history = new TreeSet<ClientsHistory>();
+ private SortedSet<ClientsHistory> history =
+ new TreeSet<ClientsHistory>();
+ public void setHistory(SortedSet<ClientsHistory> history) {
+ this.history = history;
+ }
+ public SortedSet<ClientsHistory> getHistory() {
+ return this.history;
+ }
public void fromDocumentString(String documentString) {
Scanner s = new Scanner(documentString);
diff --git a/src/org/torproject/onionoo/ClientsStatusUpdater.java b/src/org/torproject/onionoo/ClientsStatusUpdater.java
index 8a98ccf..56803d4 100644
--- a/src/org/torproject/onionoo/ClientsStatusUpdater.java
+++ b/src/org/torproject/onionoo/ClientsStatusUpdater.java
@@ -155,42 +155,43 @@ public class ClientsStatusUpdater implements DescriptorListener,
private void addToHistory(ClientsStatus clientsStatus,
SortedSet<ClientsHistory> newIntervals) {
- SortedSet<ClientsHistory> history = clientsStatus.history;
+ SortedSet<ClientsHistory> history = clientsStatus.getHistory();
for (ClientsHistory interval : newIntervals) {
if ((history.headSet(interval).isEmpty() ||
- history.headSet(interval).last().endMillis <=
- interval.startMillis) &&
+ history.headSet(interval).last().getEndMillis() <=
+ interval.getStartMillis()) &&
(history.tailSet(interval).isEmpty() ||
- history.tailSet(interval).first().startMillis >=
- interval.endMillis)) {
+ history.tailSet(interval).first().getStartMillis() >=
+ interval.getEndMillis())) {
history.add(interval);
}
}
}
private void compressHistory(ClientsStatus clientsStatus) {
- SortedSet<ClientsHistory> history = clientsStatus.history;
+ SortedSet<ClientsHistory> history = clientsStatus.getHistory();
SortedSet<ClientsHistory> compressedHistory =
new TreeSet<ClientsHistory>();
ClientsHistory lastResponses = null;
String lastMonthString = "1970-01";
for (ClientsHistory responses : history) {
long intervalLengthMillis;
- if (this.now - responses.endMillis <=
+ if (this.now - responses.getEndMillis() <=
DateTimeHelper.ROUGHLY_THREE_MONTHS) {
intervalLengthMillis = DateTimeHelper.ONE_DAY;
- } else if (this.now - responses.endMillis <=
+ } else if (this.now - responses.getEndMillis() <=
DateTimeHelper.ROUGHLY_ONE_YEAR) {
intervalLengthMillis = DateTimeHelper.TWO_DAYS;
} else {
intervalLengthMillis = DateTimeHelper.TEN_DAYS;
}
- String monthString = DateTimeHelper.format(responses.startMillis,
+ String monthString = DateTimeHelper.format(
+ responses.getStartMillis(),
DateTimeHelper.ISO_YEARMONTH_FORMAT);
if (lastResponses != null &&
- lastResponses.endMillis == responses.startMillis &&
- ((lastResponses.endMillis - 1L) / intervalLengthMillis) ==
- ((responses.endMillis - 1L) / intervalLengthMillis) &&
+ lastResponses.getEndMillis() == responses.getStartMillis() &&
+ ((lastResponses.getEndMillis() - 1L) / intervalLengthMillis) ==
+ ((responses.getEndMillis() - 1L) / intervalLengthMillis) &&
lastMonthString.equals(monthString)) {
lastResponses.addResponses(responses);
} else {
@@ -204,7 +205,7 @@ public class ClientsStatusUpdater implements DescriptorListener,
if (lastResponses != null) {
compressedHistory.add(lastResponses);
}
- clientsStatus.history = compressedHistory;
+ clientsStatus.setHistory(compressedHistory);
}
public String getStatsString() {
diff --git a/src/org/torproject/onionoo/DescriptorSource.java b/src/org/torproject/onionoo/DescriptorSource.java
index c72e8ce..86fba25 100644
--- a/src/org/torproject/onionoo/DescriptorSource.java
+++ b/src/org/torproject/onionoo/DescriptorSource.java
@@ -77,13 +77,25 @@ class DescriptorQueue {
private List<Descriptor> descriptors;
- int historySizeBefore;
+ private int historySizeBefore;
+ public int getHistorySizeBefore() {
+ return this.historySizeBefore;
+ }
- int historySizeAfter;
+ private int historySizeAfter;
+ public int getHistorySizeAfter() {
+ return this.historySizeAfter;
+ }
- long returnedDescriptors = 0L;
+ private long returnedDescriptors = 0L;
+ public long getReturnedDescriptors() {
+ return this.returnedDescriptors;
+ }
- long returnedBytes = 0L;
+ private long returnedBytes = 0L;
+ public long getReturnedBytes() {
+ return this.returnedBytes;
+ }
public DescriptorQueue(File inDir, File statusDir) {
this.inDir = inDir;
@@ -424,10 +436,10 @@ public class DescriptorSource {
int historySizeBefore = 0, historySizeAfter = 0;
long descriptors = 0L, bytes = 0L;
for (DescriptorQueue descriptorQueue : descriptorQueues) {
- historySizeBefore += descriptorQueue.historySizeBefore;
- historySizeAfter += descriptorQueue.historySizeAfter;
- descriptors += descriptorQueue.returnedDescriptors;
- bytes += descriptorQueue.returnedBytes;
+ historySizeBefore += descriptorQueue.getHistorySizeBefore();
+ historySizeAfter += descriptorQueue.getHistorySizeAfter();
+ descriptors += descriptorQueue.getReturnedDescriptors();
+ bytes += descriptorQueue.getReturnedBytes();
}
sb.append(" " + Logger.formatDecimalNumber(historySizeBefore)
+ " descriptors excluded from this execution\n");
diff --git a/src/org/torproject/onionoo/DetailsDocumentWriter.java b/src/org/torproject/onionoo/DetailsDocumentWriter.java
index 57d0877..cea6ba3 100644
--- a/src/org/torproject/onionoo/DetailsDocumentWriter.java
+++ b/src/org/torproject/onionoo/DetailsDocumentWriter.java
@@ -263,13 +263,14 @@ public class DetailsDocumentWriter implements DescriptorListener,
/* Append descriptor-specific part from details status file, and
* update contact in node status. */
+ /* TODO Updating the contact here seems like a pretty bad hack. */
DetailsStatus detailsStatus = this.documentStore.retrieve(
DetailsStatus.class, false, fingerprint);
if (detailsStatus != null &&
- detailsStatus.documentString.length() > 0) {
- sb.append(",\n" + detailsStatus.documentString);
+ detailsStatus.getDocumentString().length() > 0) {
+ sb.append(",\n" + detailsStatus.getDocumentString());
String contact = null;
- Scanner s = new Scanner(detailsStatus.documentString);
+ Scanner s = new Scanner(detailsStatus.getDocumentString());
while (s.hasNextLine()) {
String line = s.nextLine();
if (!line.startsWith("\"contact\":")) {
@@ -291,7 +292,7 @@ public class DetailsDocumentWriter implements DescriptorListener,
/* Write details file to disk. */
DetailsDocument detailsDocument = new DetailsDocument();
- detailsDocument.documentString = sb.toString();
+ detailsDocument.setDocumentString(sb.toString());
this.documentStore.store(detailsDocument, fingerprint);
}
}
@@ -343,8 +344,8 @@ public class DetailsDocumentWriter implements DescriptorListener,
DetailsStatus detailsStatus = this.documentStore.retrieve(
DetailsStatus.class, false, fingerprint);
if (detailsStatus != null &&
- detailsStatus.documentString.length() > 0) {
- sb.append(",\n" + detailsStatus.documentString);
+ detailsStatus.getDocumentString().length() > 0) {
+ sb.append(",\n" + detailsStatus.getDocumentString());
}
/* Finish details string. */
@@ -352,7 +353,7 @@ public class DetailsDocumentWriter implements DescriptorListener,
/* Write details file to disk. */
DetailsDocument detailsDocument = new DetailsDocument();
- detailsDocument.documentString = sb.toString();
+ detailsDocument.setDocumentString(sb.toString());
this.documentStore.store(detailsDocument, fingerprint);
}
}
diff --git a/src/org/torproject/onionoo/Document.java b/src/org/torproject/onionoo/Document.java
index f0fac2c..bea0794 100644
--- a/src/org/torproject/onionoo/Document.java
+++ b/src/org/torproject/onionoo/Document.java
@@ -4,7 +4,13 @@ package org.torproject.onionoo;
abstract class Document {
- transient String documentString;
+ private transient String documentString;
+ public void setDocumentString(String documentString) {
+ this.documentString = documentString;
+ }
+ public String getDocumentString() {
+ return this.documentString;
+ }
public void fromDocumentString(String documentString) {
/* Subclasses may override this method to parse documentString. */
diff --git a/src/org/torproject/onionoo/DocumentStore.java b/src/org/torproject/onionoo/DocumentStore.java
index 46b5d98..fa0e98c 100644
--- a/src/org/torproject/onionoo/DocumentStore.java
+++ b/src/org/torproject/onionoo/DocumentStore.java
@@ -35,10 +35,10 @@ public class DocumentStore {
private Time time;
- boolean listedArchivedNodeStatuses = false,
+ private boolean listedArchivedNodeStatuses = false,
listedCurrentNodeStatuses = false;
- long listOperations = 0L, listedFiles = 0L, storedFiles = 0L,
+ private long listOperations = 0L, listedFiles = 0L, storedFiles = 0L,
storedBytes = 0L, retrievedFiles = 0L, retrievedBytes = 0L,
removedFiles = 0L;
@@ -187,8 +187,8 @@ public class DocumentStore {
return false;
}
String documentString;
- if (document.documentString != null) {
- documentString = document.documentString;
+ if (document.getDocumentString() != null) {
+ documentString = document.getDocumentString();
} else if (document instanceof DetailsDocument ||
document instanceof BandwidthDocument ||
document instanceof WeightsDocument ||
@@ -329,7 +329,7 @@ public class DocumentStore {
Gson gson = new Gson();
try {
result = gson.fromJson(documentString, documentType);
- result.documentString = documentString;
+ result.setDocumentString(documentString);
} catch (JsonParseException e) {
/* Handle below. */
e.printStackTrace();
@@ -346,7 +346,7 @@ public class DocumentStore {
T result = null;
try {
result = documentType.newInstance();
- result.documentString = documentString;
+ result.setDocumentString(documentString);
} catch (InstantiationException e) {
/* Handle below. */
e.printStackTrace();
diff --git a/src/org/torproject/onionoo/LookupService.java b/src/org/torproject/onionoo/LookupService.java
index 39f4e2e..a950f02 100644
--- a/src/org/torproject/onionoo/LookupService.java
+++ b/src/org/torproject/onionoo/LookupService.java
@@ -17,12 +17,79 @@ import java.util.TreeMap;
import java.util.TreeSet;
import java.util.regex.Pattern;
+class LookupResult {
+
+ private String countryCode;
+ public void setCountryCode(String countryCode) {
+ this.countryCode = countryCode;
+ }
+ public String getCountryCode() {
+ return this.countryCode;
+ }
+
+ private String countryName;
+ public void setCountryName(String countryName) {
+ this.countryName = countryName;
+ }
+ public String getCountryName() {
+ return this.countryName;
+ }
+
+ private String regionName;
+ public void setRegionName(String regionName) {
+ this.regionName = regionName;
+ }
+ public String getRegionName() {
+ return this.regionName;
+ }
+
+ private String cityName;
+ public void setCityName(String cityName) {
+ this.cityName = cityName;
+ }
+ public String getCityName() {
+ return this.cityName;
+ }
+
+ private String latitude;
+ public void setLatitude(String latitude) {
+ this.latitude = latitude;
+ }
+ public String getLatitude() {
+ return this.latitude;
+ }
+
+ private String longitude;
+ public void setLongitude(String longitude) {
+ this.longitude = longitude;
+ }
+ public String getLongitude() {
+ return this.longitude;
+ }
+
+ private String asNumber;
+ public void setAsNumber(String asNumber) {
+ this.asNumber = asNumber;
+ }
+ public String getAsNumber() {
+ return this.asNumber;
+ }
+
+ private String asName;
+ public void setAsName(String asName) {
+ this.asName = asName;
+ }
+ public String getAsName() {
+ return this.asName;
+ }
+}
+
public class LookupService {
- File geoipDir;
- File geoLite2CityBlocksCsvFile;
- File geoLite2CityLocationsCsvFile;
- File geoIPASNum2CsvFile;
+ private File geoipDir;
+ private File geoLite2CityBlocksCsvFile;
+ private File geoLite2CityLocationsCsvFile;
+ private File geoIPASNum2CsvFile;
private boolean hasAllFiles = false;
public LookupService(File geoipDir) {
this.geoipDir = geoipDir;
@@ -294,28 +361,28 @@ public class LookupService {
if (blockLocations.containsKey(blockNumber)) {
String[] parts = blockLocations.get(blockNumber).
replaceAll("\"", "").split(",", -1);
- lookupResult.countryCode = parts[3].toLowerCase();
+ lookupResult.setCountryCode(parts[3].toLowerCase());
if (parts[4].length() > 0) {
- lookupResult.countryName = parts[4];
+ lookupResult.setCountryName(parts[4]);
}
if (parts[6].length() > 0) {
- lookupResult.regionName = parts[6];
+ lookupResult.setRegionName(parts[6]);
}
if (parts[7].length() > 0) {
- lookupResult.cityName = parts[7];
+ lookupResult.setCityName(parts[7]);
}
}
}
if (addressNumberLatLong.containsKey(addressNumber)) {
String[] latLong = addressNumberLatLong.get(addressNumber);
- lookupResult.latitude = latLong[0];
- lookupResult.longitude = latLong[1];
+ lookupResult.setLatitude(latLong[0]);
+ lookupResult.setLongitude(latLong[1]);
}
if (addressNumberASN.containsKey(addressNumber)) {
String[] parts = addressNumberASN.get(addressNumber).split(" ",
2);
- lookupResult.aSNumber = parts[0];
- lookupResult.aSName = parts[1];
+ lookupResult.setAsNumber(parts[0]);
+ lookupResult.setAsName(parts[1]);
}
lookupResults.put(addressString, lookupResult);
}
@@ -327,18 +394,7 @@ public class LookupService {
return lookupResults;
}
- class LookupResult {
- String countryCode;
- String countryName;
- String regionName;
- String cityName;
- String latitude;
- String longitude;
- String aSNumber;
- String aSName;
- }
-
- int addressesLookedUp = 0, addressesResolved = 0;
+ private int addressesLookedUp = 0, addressesResolved = 0;
public String getStatsString() {
StringBuilder sb = new StringBuilder();
diff --git a/src/org/torproject/onionoo/NodeDetailsStatusUpdater.java b/src/org/torproject/onionoo/NodeDetailsStatusUpdater.java
index d6cd2ec..2cf5061 100644
--- a/src/org/torproject/onionoo/NodeDetailsStatusUpdater.java
+++ b/src/org/torproject/onionoo/NodeDetailsStatusUpdater.java
@@ -20,7 +20,6 @@ import org.torproject.descriptor.Descriptor;
import org.torproject.descriptor.NetworkStatusEntry;
import org.torproject.descriptor.RelayNetworkStatusConsensus;
import org.torproject.descriptor.ServerDescriptor;
-import org.torproject.onionoo.LookupService.LookupResult;
public class NodeDetailsStatusUpdater implements DescriptorListener,
StatusUpdater {
@@ -245,14 +244,14 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
String addressString = node.getAddress();
if (lookupResults.containsKey(addressString)) {
LookupResult lookupResult = lookupResults.get(addressString);
- node.setCountryCode(lookupResult.countryCode);
- node.setCountryName(lookupResult.countryName);
- node.setRegionName(lookupResult.regionName);
- node.setCityName(lookupResult.cityName);
- node.setLatitude(lookupResult.latitude);
- node.setLongitude(lookupResult.longitude);
- node.setASNumber(lookupResult.aSNumber);
- node.setASName(lookupResult.aSName);
+ node.setCountryCode(lookupResult.getCountryCode());
+ node.setCountryName(lookupResult.getCountryName());
+ node.setRegionName(lookupResult.getRegionName());
+ node.setCityName(lookupResult.getCityName());
+ node.setLatitude(lookupResult.getLatitude());
+ node.setLongitude(lookupResult.getLongitude());
+ node.setASNumber(lookupResult.getAsNumber());
+ node.setASName(lookupResult.getAsName());
}
}
}
@@ -290,7 +289,7 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
String publishedDateTime =
DateTimeHelper.format(descriptor.getPublishedMillis());
if (detailsStatus != null) {
- String detailsString = detailsStatus.documentString;
+ String detailsString = detailsStatus.getDocumentString();
String descPublishedLine = "\"desc_published\":\""
+ publishedDateTime + "\",";
Scanner s = new Scanner(detailsString);
@@ -363,7 +362,7 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
sb.append(",\n\"hibernating\":true");
}
detailsStatus = new DetailsStatus();
- detailsStatus.documentString = sb.toString();
+ detailsStatus.setDocumentString(sb.toString());
this.documentStore.store(detailsStatus, fingerprint);
}
@@ -376,7 +375,7 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
DateTimeHelper.format(descriptor.getPublishedMillis());
String poolAssignmentLine = null;
if (detailsStatus != null) {
- String detailsString = detailsStatus.documentString;
+ String detailsString = detailsStatus.getDocumentString();
String descPublishedLine = "\"desc_published\":\""
+ publishedDateTime + "\",";
Scanner s = new Scanner(detailsString);
@@ -407,7 +406,7 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
sb.append(",\n" + poolAssignmentLine);
}
detailsStatus = new DetailsStatus();
- detailsStatus.documentString = sb.toString();
+ detailsStatus.setDocumentString(sb.toString());
this.documentStore.store(detailsStatus, fingerprint);
}
@@ -425,7 +424,7 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
DetailsStatus detailsStatus = this.documentStore.retrieve(
DetailsStatus.class, false, fingerprint);
if (detailsStatus != null) {
- String detailsString = detailsStatus.documentString;
+ String detailsString = detailsStatus.getDocumentString();
Scanner s = new Scanner(detailsString);
int linesWritten = 0;
boolean endsWithComma = false;
@@ -443,7 +442,7 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
}
sb.append("\"pool_assignment\":\"" + details + "\"");
detailsStatus = new DetailsStatus();
- detailsStatus.documentString = sb.toString();
+ detailsStatus.setDocumentString(sb.toString());
this.documentStore.store(detailsStatus, fingerprint);
}
}
@@ -535,7 +534,7 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
DetailsStatus.class, false, fingerprint);
if (detailsStatus != null) {
double advertisedBandwidth = -1.0;
- String detailsString = detailsStatus.documentString;
+ String detailsString = detailsStatus.getDocumentString();
Scanner s = new Scanner(detailsString);
while (s.hasNextLine()) {
String line = s.nextLine();
diff --git a/src/org/torproject/onionoo/NodeStatus.java b/src/org/torproject/onionoo/NodeStatus.java
index da39a5b..8e89682 100644
--- a/src/org/torproject/onionoo/NodeStatus.java
+++ b/src/org/torproject/onionoo/NodeStatus.java
@@ -19,41 +19,285 @@ import org.apache.commons.codec.digest.DigestUtils;
/* Store search data of a single relay that was running in the past seven
* days. */
public class NodeStatus extends Document {
+
private boolean isRelay;
+ public boolean isRelay() {
+ return this.isRelay;
+ }
+
private String fingerprint;
+ public String getFingerprint() {
+ return this.fingerprint;
+ }
+
private String hashedFingerprint;
+ public String getHashedFingerprint() {
+ return this.hashedFingerprint;
+ }
+
private String nickname;
+ public String getNickname() {
+ return this.nickname;
+ }
+
private String address;
+ public String getAddress() {
+ return this.address;
+ }
+
private SortedSet<String> orAddresses;
private SortedSet<String> orAddressesAndPorts;
+ public SortedSet<String> getOrAddresses() {
+ return new TreeSet<String>(this.orAddresses);
+ }
+ public void addOrAddressAndPort(String orAddressAndPort) {
+ if (!orAddressAndPort.contains(":")) {
+ System.err.println("Illegal OR address:port '" + orAddressAndPort
+ + "'. Exiting.");
+ System.exit(1);
+ } else if (orAddressAndPort.length() > 0) {
+ String orAddress = orAddressAndPort.substring(0,
+ orAddressAndPort.lastIndexOf(':'));
+ if (this.exitAddresses.contains(orAddress)) {
+ this.exitAddresses.remove(orAddress);
+ }
+ this.orAddresses.add(orAddress);
+ this.orAddressesAndPorts.add(orAddressAndPort);
+ }
+ }
+ public SortedSet<String> getOrAddressesAndPorts() {
+ return new TreeSet<String>(this.orAddressesAndPorts);
+ }
+
private SortedSet<String> exitAddresses;
+ public void addExitAddress(String exitAddress) {
+ if (exitAddress.length() > 0 && !this.address.equals(exitAddress) &&
+ !this.orAddresses.contains(exitAddress)) {
+ this.exitAddresses.add(exitAddress);
+ }
+ }
+ public SortedSet<String> getExitAddresses() {
+ return new TreeSet<String>(this.exitAddresses);
+ }
+
private String latitude;
+ public void setLatitude(String latitude) {
+ this.latitude = latitude;
+ }
+ public String getLatitude() {
+ return this.latitude;
+ }
+
private String longitude;
+ public void setLongitude(String longitude) {
+ this.longitude = longitude;
+ }
+ public String getLongitude() {
+ return this.longitude;
+ }
+
private String countryCode;
+ public void setCountryCode(String countryCode) {
+ this.countryCode = countryCode;
+ }
+ public String getCountryCode() {
+ return this.countryCode;
+ }
+
private String countryName;
+ public void setCountryName(String countryName) {
+ this.countryName = countryName;
+ }
+ public String getCountryName() {
+ return this.countryName;
+ }
+
private String regionName;
+ public void setRegionName(String regionName) {
+ this.regionName = regionName;
+ }
+ public String getRegionName() {
+ return this.regionName;
+ }
+
private String cityName;
+ public void setCityName(String cityName) {
+ this.cityName = cityName;
+ }
+ public String getCityName() {
+ return this.cityName;
+ }
+
private String aSName;
+ public void setASName(String aSName) {
+ this.aSName = aSName;
+ }
+ public String getASName() {
+ return this.aSName;
+ }
+
private String aSNumber;
+ public void setASNumber(String aSNumber) {
+ this.aSNumber = aSNumber;
+ }
+ public String getASNumber() {
+ return this.aSNumber;
+ }
+
private long firstSeenMillis;
+ public long getFirstSeenMillis() {
+ return this.firstSeenMillis;
+ }
+
private long lastSeenMillis;
+ public long getLastSeenMillis() {
+ return this.lastSeenMillis;
+ }
+
private int orPort;
+ public int getOrPort() {
+ return this.orPort;
+ }
+
private int dirPort;
+ public int getDirPort() {
+ return this.dirPort;
+ }
+
private SortedSet<String> relayFlags;
+ public SortedSet<String> getRelayFlags() {
+ return this.relayFlags;
+ }
+
private long consensusWeight;
+ public long getConsensusWeight() {
+ return this.consensusWeight;
+ }
+
private boolean running;
+ public void setRunning(boolean running) {
+ this.running = running;
+ }
+ public boolean getRunning() {
+ return this.running;
+ }
+
private String hostName;
+ public void setHostName(String hostName) {
+ this.hostName = hostName;
+ }
+ public String getHostName() {
+ return this.hostName;
+ }
+
private long lastRdnsLookup = -1L;
+ public void setLastRdnsLookup(long lastRdnsLookup) {
+ this.lastRdnsLookup = lastRdnsLookup;
+ }
+ public long getLastRdnsLookup() {
+ return this.lastRdnsLookup;
+ }
+
private double advertisedBandwidthFraction = -1.0;
+ public void setAdvertisedBandwidthFraction(
+ double advertisedBandwidthFraction) {
+ this.advertisedBandwidthFraction = advertisedBandwidthFraction;
+ }
+ public double getAdvertisedBandwidthFraction() {
+ return this.advertisedBandwidthFraction;
+ }
+
private double consensusWeightFraction = -1.0;
+ public void setConsensusWeightFraction(double consensusWeightFraction) {
+ this.consensusWeightFraction = consensusWeightFraction;
+ }
+ public double getConsensusWeightFraction() {
+ return this.consensusWeightFraction;
+ }
+
private double guardProbability = -1.0;
+ public void setGuardProbability(double guardProbability) {
+ this.guardProbability = guardProbability;
+ }
+ public double getGuardProbability() {
+ return this.guardProbability;
+ }
+
private double middleProbability = -1.0;
+ public void setMiddleProbability(double middleProbability) {
+ this.middleProbability = middleProbability;
+ }
+ public double getMiddleProbability() {
+ return this.middleProbability;
+ }
+
private double exitProbability = -1.0;
+ public void setExitProbability(double exitProbability) {
+ this.exitProbability = exitProbability;
+ }
+ public double getExitProbability() {
+ return this.exitProbability;
+ }
+
private String defaultPolicy;
+ public String getDefaultPolicy() {
+ return this.defaultPolicy;
+ }
+
private String portList;
+ public String getPortList() {
+ return this.portList;
+ }
+
private SortedMap<Long, Set<String>> lastAddresses;
+ public SortedMap<Long, Set<String>> getLastAddresses() {
+ return this.lastAddresses == null ? null :
+ new TreeMap<Long, Set<String>>(this.lastAddresses);
+ }
+ public long getLastChangedOrAddress() {
+ long lastChangedAddressesMillis = -1L;
+ if (this.lastAddresses != null) {
+ Set<String> lastAddresses = null;
+ for (Map.Entry<Long, Set<String>> e : this.lastAddresses.entrySet()) {
+ if (lastAddresses != null) {
+ for (String address : e.getValue()) {
+ if (!lastAddresses.contains(address)) {
+ return lastChangedAddressesMillis;
+ }
+ }
+ }
+ lastChangedAddressesMillis = e.getKey();
+ lastAddresses = e.getValue();
+ }
+ }
+ return lastChangedAddressesMillis;
+ }
+
private String contact;
+ public void setContact(String contact) {
+ if (contact == null) {
+ this.contact = null;
+ } else {
+ StringBuilder sb = new StringBuilder();
+ for (char c : contact.toLowerCase().toCharArray()) {
+ if (c >= 32 && c < 127) {
+ sb.append(c);
+ } else {
+ sb.append(" ");
+ }
+ }
+ this.contact = sb.toString();
+ }
+ }
+ public String getContact() {
+ return this.contact;
+ }
+
private Boolean recommendedVersion;
+ public Boolean getRecommendedVersion() {
+ return this.recommendedVersion;
+ }
+
public NodeStatus(boolean isRelay, String nickname, String fingerprint,
String address, SortedSet<String> orAddressesAndPorts,
SortedSet<String> exitAddresses, long lastSeenMillis, int orPort,
@@ -259,7 +503,7 @@ public class NodeStatus extends Document {
this.lastAddresses.putAll(newNodeStatus.lastAddresses);
}
this.firstSeenMillis = Math.min(newNodeStatus.firstSeenMillis,
- this.getFirstSeenMillis());
+ this.firstSeenMillis);
}
public String toString() {
@@ -315,215 +559,5 @@ public class NodeStatus extends Document {
this.recommendedVersion ? "true" : "false"));
return sb.toString();
}
-
- public boolean isRelay() {
- return this.isRelay;
- }
- public String getFingerprint() {
- return this.fingerprint;
- }
- public String getHashedFingerprint() {
- return this.hashedFingerprint;
- }
- public String getNickname() {
- return this.nickname;
- }
- public String getAddress() {
- return this.address;
- }
- public SortedSet<String> getOrAddresses() {
- return new TreeSet<String>(this.orAddresses);
- }
- public void addOrAddressAndPort(String orAddressAndPort) {
- if (!orAddressAndPort.contains(":")) {
- System.err.println("Illegal OR address:port '" + orAddressAndPort
- + "'. Exiting.");
- System.exit(1);
- } else if (orAddressAndPort.length() > 0) {
- String orAddress = orAddressAndPort.substring(0,
- orAddressAndPort.lastIndexOf(':'));
- if (this.exitAddresses.contains(orAddress)) {
- this.exitAddresses.remove(orAddress);
- }
- this.orAddresses.add(orAddress);
- this.orAddressesAndPorts.add(orAddressAndPort);
- }
- }
- public SortedSet<String> getOrAddressesAndPorts() {
- return new TreeSet<String>(this.orAddressesAndPorts);
- }
- public void addExitAddress(String exitAddress) {
- if (exitAddress.length() > 0 && !this.address.equals(exitAddress) &&
- !this.orAddresses.contains(exitAddress)) {
- this.exitAddresses.add(exitAddress);
- }
- }
- public SortedSet<String> getExitAddresses() {
- return new TreeSet<String>(this.exitAddresses);
- }
- public void setLatitude(String latitude) {
- this.latitude = latitude;
- }
- public String getLatitude() {
- return this.latitude;
- }
- public void setLongitude(String longitude) {
- this.longitude = longitude;
- }
- public String getLongitude() {
- return this.longitude;
- }
- public void setCountryCode(String countryCode) {
- this.countryCode = countryCode;
- }
- public String getCountryCode() {
- return this.countryCode;
- }
- public void setCountryName(String countryName) {
- this.countryName = countryName;
- }
- public String getCountryName() {
- return this.countryName;
- }
- public void setRegionName(String regionName) {
- this.regionName = regionName;
- }
- public String getRegionName() {
- return this.regionName;
- }
- public void setCityName(String cityName) {
- this.cityName = cityName;
- }
- public String getCityName() {
- return this.cityName;
- }
- public void setASNumber(String aSNumber) {
- this.aSNumber = aSNumber;
- }
- public String getASNumber() {
- return this.aSNumber;
- }
- public void setASName(String aSName) {
- this.aSName = aSName;
- }
- public String getASName() {
- return this.aSName;
- }
- public long getFirstSeenMillis() {
- return this.firstSeenMillis;
- }
- public long getLastSeenMillis() {
- return this.lastSeenMillis;
- }
- public int getOrPort() {
- return this.orPort;
- }
- public int getDirPort() {
- return this.dirPort;
- }
- public SortedSet<String> getRelayFlags() {
- return this.relayFlags;
- }
- public long getConsensusWeight() {
- return this.consensusWeight;
- }
- public void setRunning(boolean running) {
- this.running = running;
- }
- public boolean getRunning() {
- return this.running;
- }
- public void setHostName(String hostName) {
- this.hostName = hostName;
- }
- public String getHostName() {
- return this.hostName;
- }
- public void setLastRdnsLookup(long lastRdnsLookup) {
- this.lastRdnsLookup = lastRdnsLookup;
- }
- public long getLastRdnsLookup() {
- return this.lastRdnsLookup;
- }
- public void setAdvertisedBandwidthFraction(
- double advertisedBandwidthFraction) {
- this.advertisedBandwidthFraction = advertisedBandwidthFraction;
- }
- public double getAdvertisedBandwidthFraction() {
- return this.advertisedBandwidthFraction;
- }
- public void setConsensusWeightFraction(double consensusWeightFraction) {
- this.consensusWeightFraction = consensusWeightFraction;
- }
- public double getConsensusWeightFraction() {
- return this.consensusWeightFraction;
- }
- public void setGuardProbability(double guardProbability) {
- this.guardProbability = guardProbability;
- }
- public double getGuardProbability() {
- return this.guardProbability;
- }
- public void setMiddleProbability(double middleProbability) {
- this.middleProbability = middleProbability;
- }
- public double getMiddleProbability() {
- return this.middleProbability;
- }
- public void setExitProbability(double exitProbability) {
- this.exitProbability = exitProbability;
- }
- public double getExitProbability() {
- return this.exitProbability;
- }
- public String getDefaultPolicy() {
- return this.defaultPolicy;
- }
- public String getPortList() {
- return this.portList;
- }
- public SortedMap<Long, Set<String>> getLastAddresses() {
- return this.lastAddresses == null ? null :
- new TreeMap<Long, Set<String>>(this.lastAddresses);
- }
- public long getLastChangedOrAddress() {
- long lastChangedAddressesMillis = -1L;
- if (this.lastAddresses != null) {
- Set<String> lastAddresses = null;
- for (Map.Entry<Long, Set<String>> e : this.lastAddresses.entrySet()) {
- if (lastAddresses != null) {
- for (String address : e.getValue()) {
- if (!lastAddresses.contains(address)) {
- return lastChangedAddressesMillis;
- }
- }
- }
- lastChangedAddressesMillis = e.getKey();
- lastAddresses = e.getValue();
- }
- }
- return lastChangedAddressesMillis;
- }
- public void setContact(String contact) {
- if (contact == null) {
- this.contact = null;
- } else {
- StringBuilder sb = new StringBuilder();
- for (char c : contact.toLowerCase().toCharArray()) {
- if (c >= 32 && c < 127) {
- sb.append(c);
- } else {
- sb.append(" ");
- }
- }
- this.contact = sb.toString();
- }
- }
- public String getContact() {
- return this.contact;
- }
- public Boolean getRecommendedVersion() {
- return this.recommendedVersion;
- }
}
diff --git a/src/org/torproject/onionoo/ResponseBuilder.java b/src/org/torproject/onionoo/ResponseBuilder.java
index bde8961..080af52 100644
--- a/src/org/torproject/onionoo/ResponseBuilder.java
+++ b/src/org/torproject/onionoo/ResponseBuilder.java
@@ -49,8 +49,9 @@ public class ResponseBuilder {
long newSummaryFileLastModified = -1L;
UpdateStatus updateStatus = documentStore.retrieve(UpdateStatus.class,
false);
- if (updateStatus != null && updateStatus.documentString != null) {
- String updateString = updateStatus.documentString;
+ if (updateStatus != null &&
+ updateStatus.getDocumentString() != null) {
+ String updateString = updateStatus.getDocumentString();
try {
newSummaryFileLastModified = Long.parseLong(updateString.trim());
} catch (NumberFormatException e) {
@@ -806,9 +807,9 @@ public class ResponseBuilder {
DetailsDocument detailsDocument = documentStore.retrieve(
DetailsDocument.class, false, fingerprint);
if (detailsDocument != null &&
- detailsDocument.documentString != null) {
+ detailsDocument.getDocumentString() != null) {
StringBuilder sb = new StringBuilder();
- Scanner s = new Scanner(detailsDocument.documentString);
+ Scanner s = new Scanner(detailsDocument.getDocumentString());
sb.append("{");
if (s.hasNextLine()) {
/* Skip version line. */
@@ -876,8 +877,8 @@ public class ResponseBuilder {
BandwidthDocument bandwidthDocument = documentStore.retrieve(
BandwidthDocument.class, false, fingerprint);
if (bandwidthDocument != null &&
- bandwidthDocument.documentString != null) {
- String bandwidthLines = bandwidthDocument.documentString;
+ bandwidthDocument.getDocumentString() != null) {
+ String bandwidthLines = bandwidthDocument.getDocumentString();
bandwidthLines = bandwidthLines.substring(0,
bandwidthLines.length() - 1);
return bandwidthLines;
@@ -900,8 +901,8 @@ public class ResponseBuilder {
WeightsDocument weightsDocument = documentStore.retrieve(
WeightsDocument.class, false, fingerprint);
if (weightsDocument != null &&
- weightsDocument.documentString != null) {
- String weightsLines = weightsDocument.documentString;
+ weightsDocument.getDocumentString() != null) {
+ String weightsLines = weightsDocument.getDocumentString();
weightsLines = weightsLines.substring(0, weightsLines.length() - 1);
return weightsLines;
} else {
@@ -923,8 +924,8 @@ public class ResponseBuilder {
ClientsDocument clientsDocument = documentStore.retrieve(
ClientsDocument.class, false, fingerprint);
if (clientsDocument != null &&
- clientsDocument.documentString != null) {
- String clientsLines = clientsDocument.documentString;
+ clientsDocument.getDocumentString() != null) {
+ String clientsLines = clientsDocument.getDocumentString();
clientsLines = clientsLines.substring(0, clientsLines.length() - 1);
return clientsLines;
} else {
@@ -949,8 +950,8 @@ public class ResponseBuilder {
UptimeDocument uptimeDocument = documentStore.retrieve(
UptimeDocument.class, false, fingerprint);
if (uptimeDocument != null &&
- uptimeDocument.documentString != null) {
- String uptimeLines = uptimeDocument.documentString;
+ uptimeDocument.getDocumentString() != null) {
+ String uptimeLines = uptimeDocument.getDocumentString();
uptimeLines = uptimeLines.substring(0, uptimeLines.length() - 1);
return uptimeLines;
} else {
diff --git a/src/org/torproject/onionoo/ReverseDomainNameResolver.java b/src/org/torproject/onionoo/ReverseDomainNameResolver.java
index 7f14460..e762811 100644
--- a/src/org/torproject/onionoo/ReverseDomainNameResolver.java
+++ b/src/org/torproject/onionoo/ReverseDomainNameResolver.java
@@ -55,9 +55,9 @@ public class ReverseDomainNameResolver {
}
private class RdnsLookupRequest extends Thread {
- RdnsLookupWorker parent;
- String address, hostName;
- long lookupStartedMillis = -1L, lookupCompletedMillis = -1L;
+ private RdnsLookupWorker parent;
+ private String address, hostName;
+ private long lookupStartedMillis = -1L, lookupCompletedMillis = -1L;
public RdnsLookupRequest(RdnsLookupWorker parent, String address) {
this.parent = parent;
this.address = address;
diff --git a/src/org/torproject/onionoo/UptimeDocumentWriter.java b/src/org/torproject/onionoo/UptimeDocumentWriter.java
index 06fde0f..a7b1bba 100644
--- a/src/org/torproject/onionoo/UptimeDocumentWriter.java
+++ b/src/org/torproject/onionoo/UptimeDocumentWriter.java
@@ -53,9 +53,9 @@ public class UptimeDocumentWriter implements FingerprintListener,
if (uptimeStatus == null) {
return;
}
- SortedSet<UptimeHistory> knownStatuses = uptimeStatus.history;
+ SortedSet<UptimeHistory> knownStatuses = uptimeStatus.getHistory();
for (UptimeHistory status : knownStatuses) {
- if (status.relay) {
+ if (status.isRelay()) {
knownRelayStatuses.add(status);
} else {
knownBridgeStatuses.add(status);
@@ -77,10 +77,10 @@ public class UptimeDocumentWriter implements FingerprintListener,
UptimeStatus uptimeStatus = this.documentStore.retrieve(
UptimeStatus.class, true, fingerprint);
if (uptimeStatus != null) {
- SortedSet<UptimeHistory> history = uptimeStatus.history;
+ SortedSet<UptimeHistory> history = uptimeStatus.getHistory();
UptimeDocument uptimeDocument = new UptimeDocument();
- uptimeDocument.documentString = this.formatHistoryString(relay,
- fingerprint, history, knownStatuses);
+ uptimeDocument.setDocumentString(this.formatHistoryString(relay,
+ fingerprint, history, knownStatuses));
this.documentStore.store(uptimeDocument, fingerprint);
this.writtenDocuments++;
}
@@ -142,15 +142,15 @@ public class UptimeDocumentWriter implements FingerprintListener,
/ dataPointInterval) * dataPointInterval;
int statusHours = 0;
for (UptimeHistory hist : knownStatuses) {
- if (hist.relay != relay) {
+ if (hist.isRelay() != relay) {
continue;
}
- long histEndMillis = hist.startMillis + DateTimeHelper.ONE_HOUR
- * hist.uptimeHours;
+ long histEndMillis = hist.getStartMillis() + DateTimeHelper.ONE_HOUR
+ * hist.getUptimeHours();
if (histEndMillis < intervalStartMillis) {
continue;
}
- while (hist.startMillis >= intervalStartMillis
+ while (hist.getStartMillis() >= intervalStartMillis
+ dataPointInterval) {
statusDataPoints.add(statusHours * 5 > dataPointIntervalHours
? statusHours : -1);
@@ -159,15 +159,16 @@ public class UptimeDocumentWriter implements FingerprintListener,
}
while (histEndMillis >= intervalStartMillis + dataPointInterval) {
statusHours += (int) ((intervalStartMillis + dataPointInterval
- - Math.max(hist.startMillis, intervalStartMillis))
+ - Math.max(hist.getStartMillis(), intervalStartMillis))
/ DateTimeHelper.ONE_HOUR);
statusDataPoints.add(statusHours * 5 > dataPointIntervalHours
? statusHours : -1);
statusHours = 0;
intervalStartMillis += dataPointInterval;
}
- statusHours += (int) ((histEndMillis - Math.max(hist.startMillis,
- intervalStartMillis)) / DateTimeHelper.ONE_HOUR);
+ statusHours += (int) ((histEndMillis - Math.max(
+ hist.getStartMillis(), intervalStartMillis))
+ / DateTimeHelper.ONE_HOUR);
}
statusDataPoints.add(statusHours * 5 > dataPointIntervalHours
? statusHours : -1);
@@ -177,18 +178,18 @@ public class UptimeDocumentWriter implements FingerprintListener,
int uptimeHours = 0;
long firstStatusStartMillis = -1L;
for (UptimeHistory hist : history) {
- if (hist.relay != relay) {
+ if (hist.isRelay() != relay) {
continue;
}
if (firstStatusStartMillis < 0L) {
- firstStatusStartMillis = hist.startMillis;
+ firstStatusStartMillis = hist.getStartMillis();
}
- long histEndMillis = hist.startMillis + DateTimeHelper.ONE_HOUR
- * hist.uptimeHours;
+ long histEndMillis = hist.getStartMillis() + DateTimeHelper.ONE_HOUR
+ * hist.getUptimeHours();
if (histEndMillis < intervalStartMillis) {
continue;
}
- while (hist.startMillis >= intervalStartMillis
+ while (hist.getStartMillis() >= intervalStartMillis
+ dataPointInterval) {
if (firstStatusStartMillis < intervalStartMillis
+ dataPointInterval) {
@@ -201,14 +202,15 @@ public class UptimeDocumentWriter implements FingerprintListener,
}
while (histEndMillis >= intervalStartMillis + dataPointInterval) {
uptimeHours += (int) ((intervalStartMillis + dataPointInterval
- - Math.max(hist.startMillis, intervalStartMillis))
+ - Math.max(hist.getStartMillis(), intervalStartMillis))
/ DateTimeHelper.ONE_HOUR);
uptimeDataPoints.add(uptimeHours);
uptimeHours = 0;
intervalStartMillis += dataPointInterval;
}
- uptimeHours += (int) ((histEndMillis - Math.max(hist.startMillis,
- intervalStartMillis)) / DateTimeHelper.ONE_HOUR);
+ uptimeHours += (int) ((histEndMillis - Math.max(
+ hist.getStartMillis(), intervalStartMillis))
+ / DateTimeHelper.ONE_HOUR);
}
uptimeDataPoints.add(uptimeHours);
List<Double> dataPoints = new ArrayList<Double>();
diff --git a/src/org/torproject/onionoo/UptimeStatus.java b/src/org/torproject/onionoo/UptimeStatus.java
index 0eb9dde..2e688b8 100644
--- a/src/org/torproject/onionoo/UptimeStatus.java
+++ b/src/org/torproject/onionoo/UptimeStatus.java
@@ -9,11 +9,20 @@ import java.util.TreeSet;
class UptimeHistory
implements Comparable<UptimeHistory> {
- boolean relay;
+ private boolean relay;
+ public boolean isRelay() {
+ return this.relay;
+ }
- long startMillis;
+ private long startMillis;
+ public long getStartMillis() {
+ return this.startMillis;
+ }
- int uptimeHours;
+ private int uptimeHours;
+ public int getUptimeHours() {
+ return this.uptimeHours;
+ }
UptimeHistory(boolean relay, long startMillis,
int uptimeHours) {
@@ -86,7 +95,13 @@ class UptimeHistory
class UptimeStatus extends Document {
- SortedSet<UptimeHistory> history = new TreeSet<UptimeHistory>();
+ private SortedSet<UptimeHistory> history = new TreeSet<UptimeHistory>();
+ public void setHistory(SortedSet<UptimeHistory> history) {
+ this.history = history;
+ }
+ public SortedSet<UptimeHistory> getHistory() {
+ return this.history;
+ }
public void fromDocumentString(String documentString) {
Scanner s = new Scanner(documentString);
diff --git a/src/org/torproject/onionoo/UptimeStatusUpdater.java b/src/org/torproject/onionoo/UptimeStatusUpdater.java
index 7bf20e5..f524ea3 100644
--- a/src/org/torproject/onionoo/UptimeStatusUpdater.java
+++ b/src/org/torproject/onionoo/UptimeStatusUpdater.java
@@ -126,21 +126,21 @@ public class UptimeStatusUpdater implements DescriptorListener,
private void addToHistory(UptimeStatus uptimeStatus, boolean relay,
SortedSet<Long> newIntervals) {
- SortedSet<UptimeHistory> history = uptimeStatus.history;
+ SortedSet<UptimeHistory> history = uptimeStatus.getHistory();
for (long startMillis : newIntervals) {
UptimeHistory interval = new UptimeHistory(relay, startMillis, 1);
if (!history.headSet(interval).isEmpty()) {
UptimeHistory prev = history.headSet(interval).last();
- if (prev.relay == interval.relay &&
- prev.startMillis + DateTimeHelper.ONE_HOUR
- * prev.uptimeHours > interval.startMillis) {
+ if (prev.isRelay() == interval.isRelay() &&
+ prev.getStartMillis() + DateTimeHelper.ONE_HOUR
+ * prev.getUptimeHours() > interval.getStartMillis()) {
continue;
}
}
if (!history.tailSet(interval).isEmpty()) {
UptimeHistory next = history.tailSet(interval).first();
- if (next.relay == interval.relay &&
- next.startMillis < interval.startMillis
+ if (next.isRelay() == interval.isRelay() &&
+ next.getStartMillis() < interval.getStartMillis()
+ DateTimeHelper.ONE_HOUR) {
continue;
}
@@ -150,15 +150,15 @@ public class UptimeStatusUpdater implements DescriptorListener,
}
private void compressHistory(UptimeStatus uptimeStatus) {
- SortedSet<UptimeHistory> history = uptimeStatus.history;
+ SortedSet<UptimeHistory> history = uptimeStatus.getHistory();
SortedSet<UptimeHistory> compressedHistory =
new TreeSet<UptimeHistory>();
UptimeHistory lastInterval = null;
for (UptimeHistory interval : history) {
if (lastInterval != null &&
- lastInterval.startMillis + DateTimeHelper.ONE_HOUR
- * lastInterval.uptimeHours == interval.startMillis &&
- lastInterval.relay == interval.relay) {
+ lastInterval.getStartMillis() + DateTimeHelper.ONE_HOUR
+ * lastInterval.getUptimeHours() == interval.getStartMillis() &&
+ lastInterval.isRelay() == interval.isRelay()) {
lastInterval.addUptime(interval);
} else {
if (lastInterval != null) {
@@ -170,7 +170,7 @@ public class UptimeStatusUpdater implements DescriptorListener,
if (lastInterval != null) {
compressedHistory.add(lastInterval);
}
- uptimeStatus.history = compressedHistory;
+ uptimeStatus.setHistory(compressedHistory);
}
private void writeHistory(String fingerprint,
diff --git a/src/org/torproject/onionoo/WeightsDocumentWriter.java b/src/org/torproject/onionoo/WeightsDocumentWriter.java
index 83fe872..8dcca0a 100644
--- a/src/org/torproject/onionoo/WeightsDocumentWriter.java
+++ b/src/org/torproject/onionoo/WeightsDocumentWriter.java
@@ -56,10 +56,10 @@ public class WeightsDocumentWriter implements FingerprintListener,
if (weightsStatus == null) {
continue;
}
- SortedMap<long[], double[]> history = weightsStatus.history;
+ SortedMap<long[], double[]> history = weightsStatus.getHistory();
WeightsDocument weightsDocument = new WeightsDocument();
- weightsDocument.documentString = this.formatHistoryString(
- fingerprint, history);
+ weightsDocument.setDocumentString(this.formatHistoryString(
+ fingerprint, history));
this.documentStore.store(weightsDocument, fingerprint);
}
}
diff --git a/src/org/torproject/onionoo/WeightsStatus.java b/src/org/torproject/onionoo/WeightsStatus.java
index 93f3087..872fd00 100644
--- a/src/org/torproject/onionoo/WeightsStatus.java
+++ b/src/org/torproject/onionoo/WeightsStatus.java
@@ -9,15 +9,24 @@ import java.util.TreeMap;
class WeightsStatus extends Document {
- SortedMap<long[], double[]> history = new TreeMap<long[], double[]>(
- new Comparator<long[]>() {
+ 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 void setHistory(SortedMap<long[], double[]> history) {
+ this.history = history;
+ }
+ public SortedMap<long[], double[]> getHistory() {
+ return this.history;
+ }
- Map<String, Integer> advertisedBandwidths =
+ private Map<String, Integer> advertisedBandwidths =
new HashMap<String, Integer>();
+ public Map<String, Integer> getAdvertisedBandwidths() {
+ return this.advertisedBandwidths;
+ }
public void fromDocumentString(String documentString) {
Scanner s = new Scanner(documentString);
diff --git a/src/org/torproject/onionoo/WeightsStatusUpdater.java b/src/org/torproject/onionoo/WeightsStatusUpdater.java
index fce1c3e..1e5d559 100644
--- a/src/org/torproject/onionoo/WeightsStatusUpdater.java
+++ b/src/org/torproject/onionoo/WeightsStatusUpdater.java
@@ -179,9 +179,9 @@ public class WeightsStatusUpdater implements DescriptorListener,
new HashSet<String>());
}
this.descriptorDigestsByFingerprint.get(fingerprint).addAll(
- weightsStatus.advertisedBandwidths.keySet());
+ weightsStatus.getAdvertisedBandwidths().keySet());
this.advertisedBandwidths.putAll(
- weightsStatus.advertisedBandwidths);
+ weightsStatus.getAdvertisedBandwidths());
}
}
if (this.advertisedBandwidths.containsKey(
@@ -245,7 +245,7 @@ public class WeightsStatusUpdater implements DescriptorListener,
if (weightsStatus == null) {
weightsStatus = new WeightsStatus();
}
- SortedMap<long[], double[]> history = weightsStatus.history;
+ SortedMap<long[], double[]> history = weightsStatus.getHistory();
long[] interval = new long[] { validAfterMillis, freshUntilMillis };
if ((history.headMap(interval).isEmpty() ||
history.headMap(interval).lastKey()[1] <= validAfterMillis) &&
@@ -267,7 +267,7 @@ public class WeightsStatusUpdater implements DescriptorListener,
if (this.advertisedBandwidths.containsKey(descriptorDigest)) {
int advertisedBandwidth =
this.advertisedBandwidths.get(descriptorDigest);
- weightsStatus.advertisedBandwidths.put(descriptorDigest,
+ weightsStatus.getAdvertisedBandwidths().put(descriptorDigest,
advertisedBandwidth);
}
}
@@ -275,7 +275,7 @@ public class WeightsStatusUpdater implements DescriptorListener,
}
private void compressHistory(WeightsStatus weightsStatus) {
- SortedMap<long[], double[]> history = weightsStatus.history;
+ SortedMap<long[], double[]> history = weightsStatus.getHistory();
SortedMap<long[], double[]> compressedHistory =
new TreeMap<long[], double[]>(history.comparator());
long lastStartMillis = 0L, lastEndMillis = 0L;
@@ -332,7 +332,7 @@ public class WeightsStatusUpdater implements DescriptorListener,
compressedHistory.put(new long[] { lastStartMillis, lastEndMillis },
lastWeights);
}
- weightsStatus.history = compressedHistory;
+ weightsStatus.setHistory(compressedHistory);
}
private void updateWeightsStatuses() {
diff --git a/test/org/torproject/onionoo/DummyDocumentStore.java b/test/org/torproject/onionoo/DummyDocumentStore.java
index 0fce5d9..2f32833 100644
--- a/test/org/torproject/onionoo/DummyDocumentStore.java
+++ b/test/org/torproject/onionoo/DummyDocumentStore.java
@@ -51,7 +51,7 @@ public class DummyDocumentStore extends DocumentStore {
boolean parse) {
if (documentType.equals(UpdateStatus.class)) {
UpdateStatus updateStatus = new UpdateStatus();
- updateStatus.documentString = String.valueOf(this.lastModified);
+ updateStatus.setDocumentString(String.valueOf(this.lastModified));
return documentType.cast(updateStatus);
}
throw new RuntimeException("Not implemented.");
diff --git a/test/org/torproject/onionoo/LookupServiceTest.java b/test/org/torproject/onionoo/LookupServiceTest.java
index ae220f8..e12ab2a 100644
--- a/test/org/torproject/onionoo/LookupServiceTest.java
+++ b/test/org/torproject/onionoo/LookupServiceTest.java
@@ -22,7 +22,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.torproject.onionoo.LookupService.LookupResult;
public class LookupServiceTest {
@@ -121,59 +120,59 @@ public class LookupServiceTest {
this.performLookups();
if (countryCode == null) {
assertTrue(!this.lookupResults.containsKey(addressString) ||
- this.lookupResults.get(addressString).countryCode == null);
+ this.lookupResults.get(addressString).getCountryCode() == null);
} else {
assertEquals(countryCode,
- this.lookupResults.get(addressString).countryCode);
+ this.lookupResults.get(addressString).getCountryCode());
}
if (countryName == null) {
assertTrue(!this.lookupResults.containsKey(addressString) ||
- this.lookupResults.get(addressString).countryName == null);
+ this.lookupResults.get(addressString).getCountryName() == null);
} else {
assertEquals(countryName,
- this.lookupResults.get(addressString).countryName);
+ this.lookupResults.get(addressString).getCountryName());
}
if (regionName == null) {
assertTrue(!this.lookupResults.containsKey(addressString) ||
- this.lookupResults.get(addressString).regionName == null);
+ this.lookupResults.get(addressString).getRegionName() == null);
} else {
assertEquals(regionName,
- this.lookupResults.get(addressString).regionName);
+ this.lookupResults.get(addressString).getRegionName());
}
if (cityName == null) {
assertTrue(!this.lookupResults.containsKey(addressString) ||
- this.lookupResults.get(addressString).cityName == null);
+ this.lookupResults.get(addressString).getCityName() == null);
} else {
assertEquals(cityName,
- this.lookupResults.get(addressString).cityName);
+ this.lookupResults.get(addressString).getCityName());
}
if (latitude == null) {
assertTrue(!this.lookupResults.containsKey(addressString) ||
- this.lookupResults.get(addressString).latitude == null);
+ this.lookupResults.get(addressString).getLatitude() == null);
} else {
assertEquals(latitude,
- this.lookupResults.get(addressString).latitude);
+ this.lookupResults.get(addressString).getLatitude());
}
if (longitude == null) {
assertTrue(!this.lookupResults.containsKey(addressString) ||
- this.lookupResults.get(addressString).longitude == null);
+ this.lookupResults.get(addressString).getLongitude() == null);
} else {
assertEquals(longitude,
- this.lookupResults.get(addressString).longitude);
+ this.lookupResults.get(addressString).getLongitude());
}
if (aSNumber == null) {
assertTrue(!this.lookupResults.containsKey(addressString) ||
- this.lookupResults.get(addressString).aSNumber == null);
+ this.lookupResults.get(addressString).getAsNumber() == null);
} else {
assertEquals(aSNumber,
- this.lookupResults.get(addressString).aSNumber);
+ this.lookupResults.get(addressString).getAsNumber());
}
if (aSName == null) {
assertTrue(!this.lookupResults.containsKey(addressString) ||
- this.lookupResults.get(addressString).aSName == null);
+ this.lookupResults.get(addressString).getAsName() == null);
} else {
assertEquals(aSName,
- this.lookupResults.get(addressString).aSName);
+ this.lookupResults.get(addressString).getAsName());
}
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits