[tor-commits] [onionoo/master] Include country/region/city names in details documents.

karsten at torproject.org karsten at torproject.org
Tue Feb 28 08:57:47 UTC 2012


commit adf2c042a50f92e3e4991568a5e3d118c570b79f
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Sun Feb 26 00:45:13 2012 +0100

    Include country/region/city names in details documents.
    
    Implements #5250.
    
    It's unclear if the Unicode-to-UTF-8 conversion works correctly on
    non-UTF-8 systems.  A quick test with a file written on Mac OS X and read
    on Linux resulted in a <?> instead of a u-umlaut.  Someone should run
    Tomcat on Mac OS X and find out.
---
 src/org/torproject/onionoo/CurrentNodes.java     |    5 +++++
 src/org/torproject/onionoo/DetailDataWriter.java |   12 ++++++++++++
 src/org/torproject/onionoo/Node.java             |   21 +++++++++++++++++++++
 src/org/torproject/onionoo/ResourceServlet.java  |    1 +
 4 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/src/org/torproject/onionoo/CurrentNodes.java b/src/org/torproject/onionoo/CurrentNodes.java
index 0721ec4..33e048a 100644
--- a/src/org/torproject/onionoo/CurrentNodes.java
+++ b/src/org/torproject/onionoo/CurrentNodes.java
@@ -29,6 +29,7 @@ import org.torproject.descriptor.RelayNetworkStatusConsensus;
 
 import com.maxmind.geoip.Location;
 import com.maxmind.geoip.LookupService;
+import com.maxmind.geoip.regionName;
 
 /* Store relays and bridges that have been running in the past seven
  * days. */
@@ -240,6 +241,10 @@ public class CurrentNodes {
           relay.setLongitude(String.format(Locale.US, "%.6f",
               location.longitude));
           relay.setCountryCode(location.countryCode);
+          relay.setCountryName(location.countryName);
+          relay.setRegionName(regionName.regionNameByCode(
+              location.countryCode, location.region));
+          relay.setCityName(location.city);
         }
       }
       ls.close();
diff --git a/src/org/torproject/onionoo/DetailDataWriter.java b/src/org/torproject/onionoo/DetailDataWriter.java
index a0d3a4f..5af8688 100644
--- a/src/org/torproject/onionoo/DetailDataWriter.java
+++ b/src/org/torproject/onionoo/DetailDataWriter.java
@@ -306,6 +306,9 @@ public class DetailDataWriter {
       String countryCode = entry.getCountryCode();
       String latitude = entry.getLatitude();
       String longitude = entry.getLongitude();
+      String countryName = entry.getCountryName();
+      String regionName = entry.getRegionName();
+      String cityName = entry.getCityName();
       StringBuilder sb = new StringBuilder();
       sb.append("{\"version\":1,\n"
           + "\"nickname\":\"" + nickname + "\",\n"
@@ -334,6 +337,15 @@ public class DetailDataWriter {
       if (longitude != null) {
         sb.append(",\n\"longitude\":" + longitude);
       }
+      if (countryName != null) {
+        sb.append(",\n\"country_name\":\"" + countryName + "\"");
+      }
+      if (regionName != null) {
+        sb.append(",\n\"region_name\":\"" + regionName + "\"");
+      }
+      if (cityName != null) {
+        sb.append(",\n\"city_name\":\"" + cityName + "\"");
+      }
 
       /* 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 5dc3131..dd4fc8e 100644
--- a/src/org/torproject/onionoo/Node.java
+++ b/src/org/torproject/onionoo/Node.java
@@ -13,6 +13,9 @@ public class Node {
   private String latitude;
   private String longitude;
   private String countryCode;
+  private String countryName;
+  private String regionName;
+  private String cityName;
   private long lastSeenMillis;
   private int orPort;
   private int dirPort;
@@ -56,6 +59,24 @@ public class Node {
   public String getCountryCode() {
     return this.countryCode;
   }
+  public void setCountryName(String countryName) {
+    this.countryName = countryName;
+  }
+  public String getCountryName() {
+    return this.countryName;
+  }
+  public void setRegionName(String regionName) {
+    this.regionName = regionName;
+  }
+  public String getRegionName() {
+    return this.regionName;
+  }
+  public void setCityName(String cityName) {
+    this.cityName = cityName;
+  }
+  public String getCityName() {
+    return this.cityName;
+  }
   public long getLastSeenMillis() {
     return this.lastSeenMillis;
   }
diff --git a/src/org/torproject/onionoo/ResourceServlet.java b/src/org/torproject/onionoo/ResourceServlet.java
index 4da06a2..529ed2b 100644
--- a/src/org/torproject/onionoo/ResourceServlet.java
+++ b/src/org/torproject/onionoo/ResourceServlet.java
@@ -126,6 +126,7 @@ public class ResourceServlet extends HttpServlet {
     /* Set response headers and start writing the response. */
     response.setHeader("Access-Control-Allow-Origin", "*");
     response.setContentType("application/json");
+    response.setCharacterEncoding("utf-8");
     PrintWriter pw = response.getWriter();
     if (uri.equals("/" + resourceType + "/all")) {
       this.writeHeader(pw);



More information about the tor-commits mailing list