commit ff2db949e57f35df8cfffe691e2caeece8fdeccc Author: Karsten Loesing karsten.loesing@gmx.net Date: Sun Jan 26 12:01:50 2020 +0100
Add bridgedb_distributor field.
Implements #33008. --- CHANGELOG.md | 4 +++ .../metrics/onionoo/docs/DetailsDocument.java | 10 ++++++ .../metrics/onionoo/docs/DetailsStatus.java | 21 +++++++++++++ .../metrics/onionoo/server/ResponseBuilder.java | 4 +++ .../metrics/onionoo/updater/DescriptorHistory.java | 1 + .../metrics/onionoo/updater/DescriptorSource.java | 6 ++++ .../metrics/onionoo/updater/DescriptorType.java | 3 +- .../onionoo/updater/NodeDetailsStatusUpdater.java | 36 ++++++++++++++++++++++ .../onionoo/writer/DetailsDocumentWriter.java | 2 ++ .../onionoo/updater/DummyDescriptorSource.java | 1 + 10 files changed, 87 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bf4466..4d1b084 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changes in version 7.0-1.2?.? - 20??-??-??
+ * Medium changes + - Process bridge pool assignments to include the BridgeDB + distributor in bridge details documents. + * Minor changes - Make Jetty host and port configurable.
diff --git a/src/main/java/org/torproject/metrics/onionoo/docs/DetailsDocument.java b/src/main/java/org/torproject/metrics/onionoo/docs/DetailsDocument.java index bb90089..81892fc 100644 --- a/src/main/java/org/torproject/metrics/onionoo/docs/DetailsDocument.java +++ b/src/main/java/org/torproject/metrics/onionoo/docs/DetailsDocument.java @@ -571,5 +571,15 @@ public class DetailsDocument extends Document { public List<String> getUnreachableOrAddresses() { return this.unreachableOrAddresses; } + + private String bridgedbDistributor; + + public void setBridgedbDistributor(String bridgedbDistributor) { + this.bridgedbDistributor = bridgedbDistributor; + } + + public String getBridgedbDistributor() { + return this.bridgedbDistributor; + } }
diff --git a/src/main/java/org/torproject/metrics/onionoo/docs/DetailsStatus.java b/src/main/java/org/torproject/metrics/onionoo/docs/DetailsStatus.java index 8f09b52..33fef6d 100644 --- a/src/main/java/org/torproject/metrics/onionoo/docs/DetailsStatus.java +++ b/src/main/java/org/torproject/metrics/onionoo/docs/DetailsStatus.java @@ -252,6 +252,27 @@ public class DetailsStatus extends Document { this.orAddressesAndPorts; }
+ private Long bridgePoolAssignmentPublished; + + public void setBridgePoolAssignmentPublished( + Long bridgePoolAssignmentPublished) { + this.bridgePoolAssignmentPublished = bridgePoolAssignmentPublished; + } + + public java.lang.Long getBridgePoolAssignmentPublished() { + return bridgePoolAssignmentPublished; + } + + private String bridgedbDistributor; + + public void setBridgedbDistributor(String bridgedbDistributor) { + this.bridgedbDistributor = bridgedbDistributor; + } + + public String getBridgedbDistributor() { + return bridgedbDistributor; + } + /** Returns all addresses used for the onion-routing protocol which * includes the primary address and all additionally configured * onion-routing addresses. */ diff --git a/src/main/java/org/torproject/metrics/onionoo/server/ResponseBuilder.java b/src/main/java/org/torproject/metrics/onionoo/server/ResponseBuilder.java index 04ba2cc..2358ddd 100644 --- a/src/main/java/org/torproject/metrics/onionoo/server/ResponseBuilder.java +++ b/src/main/java/org/torproject/metrics/onionoo/server/ResponseBuilder.java @@ -392,6 +392,10 @@ public class ResponseBuilder { case "version_status": dd.setVersionStatus(detailsDocument.getVersionStatus()); break; + case "bridgedb_distributor": + dd.setBridgedbDistributor( + detailsDocument.getBridgedbDistributor()); + break; default: /* Not a field that we know of. Ignore. */ break; diff --git a/src/main/java/org/torproject/metrics/onionoo/updater/DescriptorHistory.java b/src/main/java/org/torproject/metrics/onionoo/updater/DescriptorHistory.java index 481ed9d..91febc4 100644 --- a/src/main/java/org/torproject/metrics/onionoo/updater/DescriptorHistory.java +++ b/src/main/java/org/torproject/metrics/onionoo/updater/DescriptorHistory.java @@ -12,6 +12,7 @@ public enum DescriptorHistory { BRIDGE_STATUS_HISTORY("bridge-status-history"), BRIDGE_SERVER_HISTORY("bridge-server-history"), BRIDGE_EXTRAINFO_HISTORY("bridge-extrainfo-history"), + BRIDGE_POOL_ASSIGNMENTS_HISTORY("bridge-pool-assignments-history"), ARCHIVED_HISTORY("archived-history");
private String fileName; diff --git a/src/main/java/org/torproject/metrics/onionoo/updater/DescriptorSource.java b/src/main/java/org/torproject/metrics/onionoo/updater/DescriptorSource.java index d8cfb82..27be94d 100644 --- a/src/main/java/org/torproject/metrics/onionoo/updater/DescriptorSource.java +++ b/src/main/java/org/torproject/metrics/onionoo/updater/DescriptorSource.java @@ -133,6 +133,9 @@ public class DescriptorSource { log.debug("Reading recent {} ...", DescriptorType.BRIDGE_STATUSES); this.readDescriptors(DescriptorType.BRIDGE_STATUSES, DescriptorHistory.BRIDGE_STATUS_HISTORY, false); + log.debug("Reading recent {} ...", DescriptorType.BRIDGE_POOL_ASSIGNMENTS); + this.readDescriptors(DescriptorType.BRIDGE_POOL_ASSIGNMENTS, + DescriptorHistory.BRIDGE_POOL_ASSIGNMENTS_HISTORY, false); }
private void readDescriptors(DescriptorType descriptorType, @@ -195,6 +198,9 @@ public class DescriptorSource { } else if (annotation.startsWith("@type bridge-extra-info 1.")) { descriptorType = DescriptorType.BRIDGE_EXTRA_INFOS; relay = false; + } else if (annotation.startsWith("@type bridge-pool-assignment 1.")) { + descriptorType = DescriptorType.BRIDGE_POOL_ASSIGNMENTS; + relay = false; } } if (descriptorType == null) { diff --git a/src/main/java/org/torproject/metrics/onionoo/updater/DescriptorType.java b/src/main/java/org/torproject/metrics/onionoo/updater/DescriptorType.java index 1af3b57..61f61d1 100644 --- a/src/main/java/org/torproject/metrics/onionoo/updater/DescriptorType.java +++ b/src/main/java/org/torproject/metrics/onionoo/updater/DescriptorType.java @@ -10,7 +10,8 @@ public enum DescriptorType { EXIT_LISTS("exit-lists"), BRIDGE_STATUSES("bridge-descriptors/statuses"), BRIDGE_SERVER_DESCRIPTORS("bridge-descriptors/server-descriptors"), - BRIDGE_EXTRA_INFOS("bridge-descriptors/extra-infos"); + BRIDGE_EXTRA_INFOS("bridge-descriptors/extra-infos"), + BRIDGE_POOL_ASSIGNMENTS("bridge-pool-assignments");
private final String dir; DescriptorType(String dir) { diff --git a/src/main/java/org/torproject/metrics/onionoo/updater/NodeDetailsStatusUpdater.java b/src/main/java/org/torproject/metrics/onionoo/updater/NodeDetailsStatusUpdater.java index 60dd915..ce809aa 100644 --- a/src/main/java/org/torproject/metrics/onionoo/updater/NodeDetailsStatusUpdater.java +++ b/src/main/java/org/torproject/metrics/onionoo/updater/NodeDetailsStatusUpdater.java @@ -4,6 +4,7 @@ package org.torproject.metrics.onionoo.updater;
import org.torproject.descriptor.BridgeNetworkStatus; +import org.torproject.descriptor.BridgePoolAssignment; import org.torproject.descriptor.Descriptor; import org.torproject.descriptor.ExitList; import org.torproject.descriptor.ExtraInfoDescriptor; @@ -120,6 +121,8 @@ public class NodeDetailsStatusUpdater implements DescriptorListener, DescriptorType.BRIDGE_EXTRA_INFOS); this.descriptorSource.registerDescriptorListener(this, DescriptorType.EXIT_LISTS); + this.descriptorSource.registerDescriptorListener(this, + DescriptorType.BRIDGE_POOL_ASSIGNMENTS); }
/* Step 1: parse descriptors. */ @@ -140,6 +143,8 @@ public class NodeDetailsStatusUpdater implements DescriptorListener, (ExtraInfoDescriptor) descriptor); } else if (descriptor instanceof BridgeNetworkStatus) { this.processBridgeNetworkStatus((BridgeNetworkStatus) descriptor); + } else if (descriptor instanceof BridgePoolAssignment) { + this.processBridgePoolAssignment((BridgePoolAssignment) descriptor); } }
@@ -384,6 +389,17 @@ public class NodeDetailsStatusUpdater implements DescriptorListener, this.bridgeStatusesProcessed++; }
+ private BridgePoolAssignment latestBridgePoolAssignments = null; + + private void processBridgePoolAssignment( + BridgePoolAssignment bridgePoolAssignment) { + if (null == this.latestBridgePoolAssignments + || this.latestBridgePoolAssignments.getPublishedMillis() + < bridgePoolAssignment.getPublishedMillis()) { + this.latestBridgePoolAssignments = bridgePoolAssignment; + } + } + @Override public void updateStatuses() { this.readNodeStatuses(); @@ -847,6 +863,26 @@ public class NodeDetailsStatusUpdater implements DescriptorListener, detailsStatus.setExitAddresses(exitAddresses); nodeStatus.setExitAddresses(new TreeSet<>(exitAddresses.keySet()));
+ if (null != this.latestBridgePoolAssignments + && (null == detailsStatus.getBridgePoolAssignmentPublished() + || detailsStatus.getBridgePoolAssignmentPublished() + < this.latestBridgePoolAssignments.getPublishedMillis())) { + if (this.latestBridgePoolAssignments.getEntries() + .containsKey(fingerprint)) { + detailsStatus.setBridgePoolAssignmentPublished( + this.latestBridgePoolAssignments.getPublishedMillis()); + String assignment = this.latestBridgePoolAssignments.getEntries() + .get(fingerprint); + if (null != assignment && !assignment.isEmpty()) { + String bridgedbDistributor = assignment.split(" ")[0]; + detailsStatus.setBridgedbDistributor(bridgedbDistributor); + } + } else { + detailsStatus.setBridgePoolAssignmentPublished(0L); + detailsStatus.setBridgedbDistributor(null); + } + } + detailsStatus.setAllegedFamily(nodeStatus.getAllegedFamily()); detailsStatus.setEffectiveFamily(nodeStatus.getEffectiveFamily()); detailsStatus.setIndirectFamily(nodeStatus.getIndirectFamily()); diff --git a/src/main/java/org/torproject/metrics/onionoo/writer/DetailsDocumentWriter.java b/src/main/java/org/torproject/metrics/onionoo/writer/DetailsDocumentWriter.java index 81fcb64..29d9244 100644 --- a/src/main/java/org/torproject/metrics/onionoo/writer/DetailsDocumentWriter.java +++ b/src/main/java/org/torproject/metrics/onionoo/writer/DetailsDocumentWriter.java @@ -186,6 +186,8 @@ public class DetailsDocumentWriter implements DocumentWriter { detailsDocument.setTransports(detailsStatus.getTransports()); detailsDocument.setVersion(detailsStatus.getVersion()); detailsDocument.setVersionStatus(detailsStatus.getVersionStatus()); + detailsDocument.setBridgedbDistributor( + detailsStatus.getBridgedbDistributor()); this.documentStore.store(detailsDocument, fingerprint); }
diff --git a/src/test/java/org/torproject/metrics/onionoo/updater/DummyDescriptorSource.java b/src/test/java/org/torproject/metrics/onionoo/updater/DummyDescriptorSource.java index 24d456b..22d834a 100644 --- a/src/test/java/org/torproject/metrics/onionoo/updater/DummyDescriptorSource.java +++ b/src/test/java/org/torproject/metrics/onionoo/updater/DummyDescriptorSource.java @@ -61,6 +61,7 @@ public class DummyDescriptorSource extends DescriptorSource { case BRIDGE_STATUSES: case BRIDGE_SERVER_DESCRIPTORS: case BRIDGE_EXTRA_INFOS: + case BRIDGE_POOL_ASSIGNMENTS: default: relay = false; break;