commit c6c0a74859bfb11887e44b2fb82245fb75744118 Author: Karsten Loesing karsten.loesing@gmx.net Date: Fri Aug 24 14:46:02 2012 +0200
Merge families based on all recently running relays (#6662). --- task-6662/.gitignore | 3 +++ task-6662/Eval.java | 41 +++++++++++++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/task-6662/.gitignore b/task-6662/.gitignore new file mode 100644 index 0000000..1f27701 --- /dev/null +++ b/task-6662/.gitignore @@ -0,0 +1,3 @@ +*.class +details.json + diff --git a/task-6662/Eval.java b/task-6662/Eval.java index 5359fba..1c6651a 100644 --- a/task-6662/Eval.java +++ b/task-6662/Eval.java @@ -1,7 +1,7 @@ import java.io.*; import java.util.*; public class Eval { - /* curl "https://onionoo.torproject.org/details?running=true&type=relay" > details.json */ + /* curl "https://onionoo.torproject.org/details?type=relay" > details.json */ public static void main(String[] args) throws Exception {
/* Parse relays and their families from details.json. Also create a @@ -16,7 +16,8 @@ public class Eval { new TreeMap<String, Set<String>>(); Map<String, String> nicknames = new HashMap<String, String>(); Map<String, String> namedRelays = new HashMap<String, String>(); - Set<String> unnamedRelays = new HashSet<String>(); + Set<String> runningRelays = new HashSet<String>(), + unnamedRelays = new HashSet<String>(); while ((line = br.readLine()) != null) { if (isParsingFamily) { if (line.startsWith(" ")) { @@ -32,6 +33,10 @@ public class Eval { } else if (line.startsWith(""fingerprint":")) { fingerprint = "$" + line.split(":")[1].split(""")[1]; nicknames.put(fingerprint, nickname); + } else if (line.startsWith(""running":")) { + if (line.endsWith("true,")) { + runningRelays.add(nickname + "~" + fingerprint.substring(1, 5)); + } } else if (line.startsWith(""flags":")) { if (line.contains(""Named"")) { if (namedRelays.containsKey(nickname)) { @@ -54,7 +59,8 @@ public class Eval { SortedSet<String> unconfirmedFamilyStrings = new TreeSet<String>(); System.out.println("Complete family relationships as reported by " + "running relays, not mutually confirmed and possibly " - + "containing nicknames of unnamed relays:"); + + "containing nicknames of unnamed relays, including non-running " + + "relays:"); for (Map.Entry<String, Set<String>> e : listedRelays.entrySet()) { StringBuilder sb = new StringBuilder(); sb.append(nicknames.get(e.getKey()) + "~" @@ -131,7 +137,8 @@ public class Eval { confirmedFamilyStrings.add(sb.toString()); } System.out.println("Mutually confirmed families with two or more " - + "family members, without reporting relay itself"); + + "family members, without reporting relay itself, including " + + "non-running relays"); for (String s : confirmedFamilyStrings) { System.out.println(s); } @@ -162,7 +169,7 @@ public class Eval { overlappingFamilyStrings.add(sb.toString()); } System.out.println("Possibly overlapping families with two or more " - + "family members:"); + + "family members, including non-running relays:"); for (String s : overlappingFamilyStrings) { System.out.println(s); } @@ -206,10 +213,32 @@ public class Eval { extendedFamilyStrings.add(sb.toString()); } System.out.println("Extended families based on merging possibly " - + "overlapping families:"); + + "overlapping families, including non-running relays:"); for (String s : extendedFamilyStrings) { System.out.println(s); } + System.out.println(); + + /* Filter non-running relays from extended families. */ + SortedSet<String> extendedFamilyRunningRelaysStrings = + new TreeSet<String>(); + for (SortedSet<String> extendedFamily : extendedFamilies) { + StringBuilder sb = new StringBuilder(); + int written = 0; + for (String relay : extendedFamily) { + if (runningRelays.contains(relay)) { + sb.append((written++ > 0 ? " " : "") + relay); + } + } + if (written > 1) { + extendedFamilyRunningRelaysStrings.add(sb.toString()); + } + } + System.out.println("Extended families, excluding non-running relays " + + "that may previously have helped merge overlapping families:"); + for (String s : extendedFamilyRunningRelaysStrings) { + System.out.println(s); + } } }