commit ba812299c1569989cc0f20a34491ceedf95ba233
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Tue Apr 3 13:24:51 2012 +0200
Add consensus_weight field to relay details.
---
src/org/torproject/onionoo/CurrentNodes.java | 26 ++++++++++++++-------
src/org/torproject/onionoo/DetailDataWriter.java | 5 ++++
src/org/torproject/onionoo/Node.java | 7 +++++-
web/index.html | 6 +++++
4 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/src/org/torproject/onionoo/CurrentNodes.java b/src/org/torproject/onionoo/CurrentNodes.java
index 6c3798b..5732cb9 100644
--- a/src/org/torproject/onionoo/CurrentNodes.java
+++ b/src/org/torproject/onionoo/CurrentNodes.java
@@ -67,8 +67,13 @@ public class CurrentNodes {
int dirPort = Integer.parseInt(parts[7]);
SortedSet<String> relayFlags = new TreeSet<String>(
Arrays.asList(parts[8].split(",")));
+ long consensusWeight = -1L;
+ if (parts.length > 9) {
+ consensusWeight = Long.parseLong(parts[9]);
+ }
this.addRelay(nickname, fingerprint, address,
- validAfterMillis, orPort, dirPort, relayFlags);
+ validAfterMillis, orPort, dirPort, relayFlags,
+ consensusWeight);
} else if (line.startsWith("b ")) {
String[] parts = line.split(" ");
if (parts.length < 9) {
@@ -128,9 +133,11 @@ public class CurrentNodes {
sb.append("," + relayFlag);
}
String relayFlags = sb.toString().substring(1);
+ String consensusWeight = String.valueOf(
+ entry.getConsensusWeight());
bw.write("r " + nickname + " " + fingerprint + " " + address + " "
+ validAfter + " " + orPort + " " + dirPort + " " + relayFlags
- + "\n");
+ + " " + consensusWeight + "\n");
}
for (Node entry : this.currentBridges.values()) {
String fingerprint = entry.getFingerprint();
@@ -146,7 +153,7 @@ public class CurrentNodes {
String relayFlags = sb.toString().substring(1);
bw.write("b Unnamed " + fingerprint + " " + address + " "
+ published + " " + orPort + " " + dirPort + " " + relayFlags
- + "\n");
+ + " -1\n");
}
bw.close();
} catch (IOException e) {
@@ -175,8 +182,8 @@ public class CurrentNodes {
if (descriptorFile.getDescriptors() != null) {
for (Descriptor descriptor : descriptorFile.getDescriptors()) {
if (descriptor instanceof RelayNetworkStatusConsensus) {
- updateRelayNetworkStatusConsensus((RelayNetworkStatusConsensus)
- descriptor);
+ updateRelayNetworkStatusConsensus(
+ (RelayNetworkStatusConsensus) descriptor);
}
}
}
@@ -203,20 +210,21 @@ public class CurrentNodes {
int orPort = entry.getOrPort();
int dirPort = entry.getDirPort();
SortedSet<String> relayFlags = entry.getFlags();
+ long consensusWeight = entry.getBandwidth();
this.addRelay(nickname, fingerprint, address, validAfterMillis,
- orPort, dirPort, relayFlags);
+ orPort, dirPort, relayFlags, consensusWeight);
}
}
public void addRelay(String nickname, String fingerprint,
String address, long validAfterMillis, int orPort, int dirPort,
- SortedSet<String> relayFlags) {
+ SortedSet<String> relayFlags, long consensusWeight) {
if (validAfterMillis >= cutoff &&
(!this.currentRelays.containsKey(fingerprint) ||
this.currentRelays.get(fingerprint).getLastSeenMillis() <
validAfterMillis)) {
Node entry = new Node(nickname, fingerprint, address,
- validAfterMillis, orPort, dirPort, relayFlags);
+ validAfterMillis, orPort, dirPort, relayFlags, consensusWeight);
this.currentRelays.put(fingerprint, entry);
if (validAfterMillis > this.lastValidAfterMillis) {
this.lastValidAfterMillis = validAfterMillis;
@@ -322,7 +330,7 @@ public class CurrentNodes {
this.currentBridges.get(fingerprint).getLastSeenMillis() <
publishedMillis)) {
Node entry = new Node("Unnamed", fingerprint, address,
- publishedMillis, orPort, dirPort, relayFlags);
+ publishedMillis, orPort, dirPort, relayFlags, -1L);
this.currentBridges.put(fingerprint, entry);
if (publishedMillis > this.lastPublishedMillis) {
this.lastPublishedMillis = publishedMillis;
diff --git a/src/org/torproject/onionoo/DetailDataWriter.java b/src/org/torproject/onionoo/DetailDataWriter.java
index c18f7d2..d107299 100644
--- a/src/org/torproject/onionoo/DetailDataWriter.java
+++ b/src/org/torproject/onionoo/DetailDataWriter.java
@@ -321,6 +321,7 @@ public class DetailDataWriter {
String cityName = entry.getCityName();
String aSNumber = entry.getASNumber();
String aSName = entry.getASName();
+ long consensusWeight = entry.getConsensusWeight();
StringBuilder sb = new StringBuilder();
sb.append("{\"version\":1,\n"
+ "\"nickname\":\"" + nickname + "\",\n"
@@ -366,6 +367,10 @@ public class DetailDataWriter {
sb.append(",\n\"as_name\":\""
+ StringEscapeUtils.escapeJavaScript(aSName) + "\"");
}
+ if (consensusWeight > 0L) {
+ sb.append(",\n\"consensus_weight\":"
+ + String.valueOf(consensusWeight));
+ }
/* Add exit addresses if at least one of them is distinct from the
* onion-routing addresses. */
diff --git a/src/org/torproject/onionoo/Node.java b/src/org/torproject/onionoo/Node.java
index ad26746..3daa4be 100644
--- a/src/org/torproject/onionoo/Node.java
+++ b/src/org/torproject/onionoo/Node.java
@@ -22,10 +22,11 @@ public class Node {
private int orPort;
private int dirPort;
private SortedSet<String> relayFlags;
+ private long consensusWeight;
private boolean running;
public Node(String nickname, String fingerprint, String address,
long lastSeenMillis, int orPort, int dirPort,
- SortedSet<String> relayFlags) {
+ SortedSet<String> relayFlags, long consensusWeight) {
this.nickname = nickname;
this.fingerprint = fingerprint;
this.address = address;
@@ -33,6 +34,7 @@ public class Node {
this.orPort = orPort;
this.dirPort = dirPort;
this.relayFlags = relayFlags;
+ this.consensusWeight = consensusWeight;
}
public String getFingerprint() {
return this.fingerprint;
@@ -103,6 +105,9 @@ public class Node {
public SortedSet<String> getRelayFlags() {
return this.relayFlags;
}
+ public long getConsensusWeight() {
+ return this.consensusWeight;
+ }
public void setRunning(boolean running) {
this.running = running;
}
diff --git a/web/index.html b/web/index.html
index 848e416..c4c154c 100755
--- a/web/index.html
+++ b/web/index.html
@@ -215,6 +215,12 @@ relay's first onion-routing IP address.
Optional field.
Omitted if the relay IP address could not be found in the AS
database.</li>
+<li><b><font color="blue">"consensus_weight":</font></b> Bandwidth weight
+assigned to this relay by the directory authorities.
+The unit is arbitrary; currently it's kilobytes per second, but that might
+change in the future.
+Required field.
+Added on April 3, 2012.</li>
<li><b>"last_restarted":</b> UTC timestamp (YYYY-MM-DD hh:mm:ss) when the
relay was last (re-)started.
<font color="red">Optional field.</font>