Commit ff2db949 authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Add bridgedb_distributor field.

Implements #33008.
parent 79626a16
# 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.
......
......@@ -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;
}
}
......@@ -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. */
......
......@@ -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;
......
......@@ -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;
......
......@@ -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) {
......
......@@ -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) {
......
......@@ -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());
......
......@@ -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);
}
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment