[or-cvs] r21557: {projects} Add country codes to bridge nicknames as in UnnamedCC. (projects/archives/trunk/bridge-desc-sanitizer)

Karsten Loesing karsten.loesing at gmx.net
Thu Feb 4 15:12:36 UTC 2010


Author: kloesing
Date: 2010-02-04 15:12:36 +0000 (Thu, 04 Feb 2010)
New Revision: 21557

Modified:
   projects/archives/trunk/bridge-desc-sanitizer/ConvertBridgeDescs.java
   projects/archives/trunk/bridge-desc-sanitizer/HOWTO
Log:
Add country codes to bridge nicknames as in UnnamedCC.


Modified: projects/archives/trunk/bridge-desc-sanitizer/ConvertBridgeDescs.java
===================================================================
--- projects/archives/trunk/bridge-desc-sanitizer/ConvertBridgeDescs.java	2010-02-03 22:55:46 UTC (rev 21556)
+++ projects/archives/trunk/bridge-desc-sanitizer/ConvertBridgeDescs.java	2010-02-04 15:12:36 UTC (rev 21557)
@@ -88,6 +88,39 @@
         + " networkstatus-bridges files, covering approximately " + days
         + " days.");
 
+    System.out.print("Parsing server descriptors to find out country "
+        + "codes of bridges in extra-info descriptors");
+    Map<String, String> bridgeCountries = new HashMap<String, String>();
+    int parsed = 0;
+    for (File file : descriptors) {
+      if (parsed++ > descriptors.size() / days) {
+        System.out.print(".");
+        parsed = 0;
+      }
+      BufferedReader br = new BufferedReader(new FileReader(file));
+      String line = null, routerLine = null;
+      while ((line = br.readLine()) != null) {
+        if (line.startsWith("router ")) {
+          routerLine = line;
+        } else if (line.startsWith("opt extra-info-digest ")) {
+          String extraInfoDigest = line.split(" ")[2];
+          String countryCode = cl.getCountry(routerLine.split(" ")[2]).
+              getCode();
+          if (bridgeCountries.containsKey(extraInfoDigest) &&
+              !bridgeCountries.get(extraInfoDigest).
+              equals(countryCode)) {
+            System.out.println("Mapping already contains extra-info "
+                + "digest " + extraInfoDigest + " with different "
+                + "country. Exiting.");
+            System.exit(1);
+          }
+          bridgeCountries.put(extraInfoDigest, countryCode);
+        }
+      }
+    }
+    System.out.println("Mapping contains " + bridgeCountries.size()
+        + " entries.");
+
     System.out.print("Parsing extra-info descriptors");
     String[] hex = new String[] { "0", "1", "2", "3", "4", "5", "6", "7",
         "8", "9", "a", "b", "c", "d", "e", "f" };
@@ -97,7 +130,7 @@
             + x + File.separator + y).mkdirs();
     int writtenExtrainfos = 0;
     Map<String, String> extrainfoMapping = new HashMap<String, String>();
-    int parsed = 0;
+    parsed = 0;
     for (File file : extrainfos) {
       if (parsed++ > extrainfos.size() / days) {
         System.out.print(".");
@@ -112,20 +145,26 @@
           continue;
         } else if (line.startsWith("extra-info ")) {
           original = new StringBuilder(line + "\n");
-          scrubbed = new StringBuilder("extra-info Unnamed "
-              + DigestUtils.shaHex(Hex.decodeHex(
+          scrubbed = new StringBuilder(DigestUtils.shaHex(Hex.decodeHex(
               line.split(" ")[2].toCharArray())).toUpperCase() + "\n");
         } else if (line.startsWith("published ")
             || line.startsWith("write-history ")
             || line.startsWith("read-history ")
             || line.startsWith("geoip-start-time ")
-            || line.startsWith("geoip-client-origins ")) {
+            || line.startsWith("geoip-client-origins ")
+            || line.startsWith("bridge-stats-end ") 
+            || line.startsWith("bridge-ips ")) {
           original.append(line + "\n");
           scrubbed.append(line + "\n");
         } else if (line.startsWith("router-signature")) {
           String originalDesc = original.toString() + line + "\n";
           String originalHash = DigestUtils.shaHex(originalDesc);
-          String scrubbedDesc = scrubbed.toString();
+          String countryCode = "ZZ";
+          if (bridgeCountries.containsKey(originalHash.toUpperCase())) {
+            countryCode = bridgeCountries.get(originalHash.toUpperCase());
+          }
+          String scrubbedDesc = "extra-info Unnamed" + countryCode + " "
+              + scrubbed.toString();
           String scrubbedHash = DigestUtils.shaHex(scrubbedDesc);
           if (extrainfoMapping.containsKey(originalHash) &&
               !extrainfoMapping.get(originalHash).equals(scrubbedHash)) {
@@ -149,6 +188,9 @@
           skipSignature = true;
         } else if (line.equals("-----END SIGNATURE-----")) {
           skipSignature = false;
+        } else if (line.startsWith("dirreq-") || line.startsWith("cell-")
+            || line.startsWith("exit-")) {
+          original.append(line + "\n");
         } else {
           System.out.println("Unrecognized line '" + line + "'. Exiting");
           System.exit(1);
@@ -189,7 +231,8 @@
           if (unresolved.contains(country)) {
             country = "zz";
           }
-          scrubbed = new StringBuilder("router Unnamed 127.0.0.1 "
+          scrubbed = new StringBuilder("router Unnamed"
+              + country.toUpperCase() + " 127.0.0.1 "
               + line.split(" ")[3] + " " + line.split(" ")[4] + " "
               + line.split(" ")[5] + "\n");
           contactWritten = false;
@@ -349,7 +392,13 @@
                 Hex.decodeHex(descriptorMapping.get(hexDescIdentifier).
                 toCharArray())).substring(0, 27);
           }
-          scrubbed.append("r Unnamed " + hashedBridgeIdentity
+          String country = cl.getCountry(parts[6]).getCode().
+              toLowerCase();
+          if (unresolved.contains(country)) {
+            country = "zz";
+          }
+          scrubbed.append("r Unnamed" + country.toUpperCase() + " "
+              + hashedBridgeIdentity
               + " " + replacementDescIdentifier + " " + parts[4] + " "
               + parts[5] + " 127.0.0.1 " + parts[7] + " " + parts[8]
               + "\n");

Modified: projects/archives/trunk/bridge-desc-sanitizer/HOWTO
===================================================================
--- projects/archives/trunk/bridge-desc-sanitizer/HOWTO	2010-02-03 22:55:46 UTC (rev 21556)
+++ projects/archives/trunk/bridge-desc-sanitizer/HOWTO	2010-02-04 15:12:36 UTC (rev 21557)
@@ -58,13 +58,13 @@
    bridge's IP address cannot be resolved to a country, the unassigned
    country code "zz" is written to the contact line.
 
-5. Replace nickname with Unnamed
+5. Replace nickname with UnnamedCC
 
    The bridge nicknames might give hints on the location of the bridge if
    chosen without care; e.g. a bridge nickname might be very similar to the
    operators' relay nicknames which might be located on adjacent IP
    addresses. All bridge nicknames are therefore replaced with the string
-   Unnamed.
+   UnnamedCC with CC being the upper-case country code.
 
 6. Replace references to descriptors
 



More information about the tor-commits mailing list