commit 5dfeedd8d7a65e3159133acbfff42e249042c864 Author: Karsten Loesing karsten.loesing@gmx.net Date: Wed Aug 1 10:09:55 2012 +0200
Add four fields to details documents for #6498. --- src/org/torproject/onionoo/CurrentNodes.java | 41 ++++++++++++++++----- src/org/torproject/onionoo/DetailDataWriter.java | 24 +++++++++++-- src/org/torproject/onionoo/Node.java | 13 ++++++- web/index.html | 24 +++++++++++++ 4 files changed, 88 insertions(+), 14 deletions(-)
diff --git a/src/org/torproject/onionoo/CurrentNodes.java b/src/org/torproject/onionoo/CurrentNodes.java index 7ef1473..a34cbb7 100644 --- a/src/org/torproject/onionoo/CurrentNodes.java +++ b/src/org/torproject/onionoo/CurrentNodes.java @@ -104,16 +104,27 @@ public class CurrentNodes { hostName = parts[11].equals("null") ? null : parts[11]; lastRdnsLookup = Long.parseLong(parts[12]); } + String defaultPolicy = null, portList = null; + if (parts.length > 14) { + if (!parts[13].equals("null")) { + defaultPolicy = parts[13]; + } + if (!parts[14].equals("null")) { + portList = parts[14]; + } + } if (isRelay) { this.addRelay(nickname, fingerprint, address, orAddressesAndPorts, exitAddresses, publishedOrValidAfterMillis, orPort, dirPort, relayFlags, - consensusWeight, countryCode, hostName, lastRdnsLookup); + consensusWeight, countryCode, hostName, lastRdnsLookup, + defaultPolicy, portList); } else { this.addBridge(nickname, fingerprint, address, orAddressesAndPorts, exitAddresses, publishedOrValidAfterMillis, orPort, dirPort, relayFlags, - consensusWeight, countryCode, hostName, lastRdnsLookup); + consensusWeight, countryCode, hostName, lastRdnsLookup, + defaultPolicy, portList); } } br.close(); @@ -175,11 +186,16 @@ public class CurrentNodes { String hostName = entry.getHostName() != null ? entry.getHostName() : "null"; long lastRdnsLookup = entry.getLastRdnsLookup(); + String defaultPolicy = entry.getDefaultPolicy() != null + ? entry.getDefaultPolicy() : "null"; + String portList = entry.getPortList() != null + ? entry.getPortList() : "null"; bw.write("r " + nickname + " " + fingerprint + " " + addressesBuilder.toString() + " " + validAfter + " " + orPort + " " + dirPort + " " + relayFlags + " " + consensusWeight + " " + countryCode + " " + hostName + " " - + String.valueOf(lastRdnsLookup) + "\n"); + + String.valueOf(lastRdnsLookup) + " " + defaultPolicy + " " + + portList + "\n"); } for (Node entry : this.currentBridges.values()) { String nickname = entry.getNickname(); @@ -204,7 +220,8 @@ public class CurrentNodes { String relayFlags = sb.toString().substring(1); bw.write("b " + nickname + " " + fingerprint + " " + addressesBuilder.toString() + " " + published + " " + orPort - + " " + dirPort + " " + relayFlags + " -1 ?? null -1\n"); + + " " + dirPort + " " + relayFlags + " -1 ?? null -1 null " + + "null\n"); } bw.close(); } catch (IOException e) { @@ -268,9 +285,11 @@ public class CurrentNodes { int dirPort = entry.getDirPort(); SortedSet<String> relayFlags = entry.getFlags(); long consensusWeight = entry.getBandwidth(); + String defaultPolicy = entry.getDefaultPolicy(); + String portList = entry.getPortList(); this.addRelay(nickname, fingerprint, address, orAddressesAndPorts, null, validAfterMillis, orPort, dirPort, relayFlags, - consensusWeight, null, null, -1L); + consensusWeight, null, null, -1L, defaultPolicy, portList); } if (this.lastValidAfterMillis == validAfterMillis) { this.lastBandwidthWeights = consensus.getBandwidthWeights(); @@ -281,7 +300,8 @@ public class CurrentNodes { String address, SortedSet<String> orAddressesAndPorts, SortedSet<String> exitAddresses, long validAfterMillis, int orPort, int dirPort, SortedSet<String> relayFlags, long consensusWeight, - String countryCode, String hostName, long lastRdnsLookup) { + String countryCode, String hostName, long lastRdnsLookup, + String defaultPolicy, String portList) { if (validAfterMillis >= cutoff && (!this.currentRelays.containsKey(fingerprint) || this.currentRelays.get(fingerprint).getLastSeenMillis() < @@ -296,7 +316,7 @@ public class CurrentNodes { Node entry = new Node(nickname, fingerprint, address, orAddressesAndPorts, exitAddresses, validAfterMillis, orPort, dirPort, relayFlags, consensusWeight, countryCode, hostName, - lastRdnsLookup); + lastRdnsLookup, defaultPolicy, portList); this.currentRelays.put(fingerprint, entry); if (validAfterMillis > this.lastValidAfterMillis) { this.lastValidAfterMillis = validAfterMillis; @@ -394,7 +414,7 @@ public class CurrentNodes { SortedSet<String> relayFlags = entry.getFlags(); this.addBridge(nickname, fingerprint, address, orAddressesAndPorts, null, publishedMillis, orPort, dirPort, relayFlags, -1, "??", - null, -1L); + null, -1L, null, null); } }
@@ -402,7 +422,8 @@ public class CurrentNodes { String address, SortedSet<String> orAddressesAndPorts, SortedSet<String> exitAddresses, long publishedMillis, int orPort, int dirPort, SortedSet<String> relayFlags, long consensusWeight, - String countryCode, String hostname, long lastRdnsLookup) { + String countryCode, String hostname, long lastRdnsLookup, + String defaultPolicy, String portList) { if (publishedMillis >= cutoff && (!this.currentBridges.containsKey(fingerprint) || this.currentBridges.get(fingerprint).getLastSeenMillis() < @@ -410,7 +431,7 @@ public class CurrentNodes { Node entry = new Node(nickname, fingerprint, address, orAddressesAndPorts, exitAddresses, publishedMillis, orPort, dirPort, relayFlags, consensusWeight, countryCode, hostname, - lastRdnsLookup); + lastRdnsLookup, defaultPolicy, portList); 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 2961de9..43d1206 100644 --- a/src/org/torproject/onionoo/DetailDataWriter.java +++ b/src/org/torproject/onionoo/DetailDataWriter.java @@ -494,11 +494,16 @@ public class DetailDataWriter { String lastRestartedString = dateTimeFormat.format( descriptor.getPublishedMillis() - descriptor.getUptime() * 1000L); - int advertisedBandwidth = Math.min(descriptor.getBandwidthRate(), - Math.min(descriptor.getBandwidthBurst(), - descriptor.getBandwidthObserved())); + int bandwidthRate = descriptor.getBandwidthRate(); + int bandwidthBurst = descriptor.getBandwidthBurst(); + int observedBandwidth = descriptor.getBandwidthObserved(); + int advertisedBandwidth = Math.min(bandwidthRate, + Math.min(bandwidthBurst, observedBandwidth)); sb.append(""desc_published":"" + publishedDateTime + "",\n" + ""last_restarted":"" + lastRestartedString + "",\n" + + ""bandwidth_rate":" + bandwidthRate + ",\n" + + ""bandwidth_burst":" + bandwidthBurst + ",\n" + + ""observed_bandwidth":" + observedBandwidth + ",\n" + ""advertised_bandwidth":" + advertisedBandwidth + ",\n" + ""exit_policy":["); int written = 0; @@ -560,6 +565,8 @@ public class DetailDataWriter { double guardProbability = entry.getGuardProbability(); double middleProbability = entry.getMiddleProbability(); double exitProbability = entry.getExitProbability(); + String defaultPolicy = entry.getDefaultPolicy(); + String portList = entry.getPortList(); StringBuilder sb = new StringBuilder(); sb.append("{"version":1,\n" + ""nickname":"" + nickname + "",\n" @@ -638,6 +645,17 @@ public class DetailDataWriter { sb.append(String.format(",\n"exit_probability":%.9f", exitProbability)); } + if (defaultPolicy != null && (defaultPolicy.equals("accept") || + defaultPolicy.equals("reject")) && portList != null) { + sb.append(",\n"exit_policy_summary":{"" + defaultPolicy + + "":["); + int portsWritten = 0; + for (String portOrPortRange : portList.split(",")) { + sb.append((portsWritten++ > 0 ? "," : "") + + """ + portOrPortRange + """); + } + sb.append("]}"); + }
/* 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 61a26ed..1bf984d 100644 --- a/src/org/torproject/onionoo/Node.java +++ b/src/org/torproject/onionoo/Node.java @@ -40,11 +40,14 @@ public class Node { private double guardProbability = -1.0; private double middleProbability = -1.0; private double exitProbability = -1.0; + private String defaultPolicy; + private String portList; public Node(String nickname, String fingerprint, String address, SortedSet<String> orAddressesAndPorts, SortedSet<String> exitAddresses, long lastSeenMillis, int orPort, int dirPort, SortedSet<String> relayFlags, long consensusWeight, - String countryCode, String hostName, long lastRdnsLookup) { + String countryCode, String hostName, long lastRdnsLookup, + String defaultPolicy, String portList) { this.nickname = nickname; this.fingerprint = fingerprint; try { @@ -75,6 +78,8 @@ public class Node { this.countryCode = countryCode; this.hostName = hostName; this.lastRdnsLookup = lastRdnsLookup; + this.defaultPolicy = defaultPolicy; + this.portList = portList; } public String getFingerprint() { return this.fingerprint; @@ -230,5 +235,11 @@ public class Node { public double getExitProbability() { return this.exitProbability; } + public String getDefaultPolicy() { + return this.defaultPolicy; + } + public String getPortList() { + return this.portList; + } }
diff --git a/web/index.html b/web/index.html index e80a99e..a74feac 100755 --- a/web/index.html +++ b/web/index.html @@ -256,6 +256,22 @@ was successful yet.</li> <li><b>"last_restarted":</b> UTC timestamp (YYYY-MM-DD hh:mm:ss) when the relay was last (re-)started. Optional field.</li> +<li><b><font color="blue">"bandwidth_rate":</font></b> Average bandwidth +in bytes per second that this relay is willing to sustain over long +periods. +Required field. +<font color="blue">Added field on August 1, 2012.</font></li> +<li><b><font color="blue">"bandwidth_burst":</font></b> Bandwidth in bytes +per second that this relay is willing to sustain in very short intervals. +Required field. +<font color="blue">Added field on August 1, 2012.</font></li> +<li><b><font color="blue">"observed_bandwidth":</font></b> Bandwidth +estimate in bytes per second of the capacity this relay can handle. +The relay remembers the maximum bandwidth sustained output over any ten +second period in the past day, and another sustained input. +The "observed_bandwidth" value is the lesser of these two numbers. +Required field. +<font color="blue">Added field on August 1, 2012.</font></li> <li><b>"advertised_bandwidth":</b> Bandwidth in bytes per second that this relay is willing and capable to provide. Optional field. @@ -265,6 +281,14 @@ found.</li> Optional field. Missing if router descriptor containing this information cannot be found.</li> +<li><b><font color="blue">"exit_policy_summary":</font></b> Summary +version of the relay's exit policy containing a dictionary with either an +"accept" or a "reject" element. +If there is an "accept" ("reject") element, the relay accepts (rejects) +all TCP ports or port ranges in the given list for most IP addresses and +rejects (accepts) all other ports. +Optional field. +<font color="blue">Added field on August 1, 2012.</font></li> <li><b>"contact":</b> Contact address of the relay operator. Omitted if empty or if descriptor containing this information cannot be found.</li>