[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [onionoo/master] Include AS information in relay details documents.



commit 03ca53d307ba33221fe18068c65a6b2d7c2ff02c
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Tue Feb 28 10:52:17 2012 +0100

    Include AS information in relay details documents.
    
    Implements #5252.
---
 .gitignore                                       |    2 ++
 src/org/torproject/onionoo/CurrentNodes.java     |   21 +++++++++++++++++++++
 src/org/torproject/onionoo/DetailDataWriter.java |    8 ++++++++
 src/org/torproject/onionoo/Main.java             |    1 +
 src/org/torproject/onionoo/Node.java             |   14 ++++++++++++++
 5 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore
index 7eb45ce..4ee5771 100755
--- a/.gitignore
+++ b/.gitignore
@@ -7,5 +7,7 @@ out/
 onionoo.war
 etc/context.xml
 GeoIP.dat
+GeoIPASNum.dat
+GeoLiteCity.dat
 log
 
diff --git a/src/org/torproject/onionoo/CurrentNodes.java b/src/org/torproject/onionoo/CurrentNodes.java
index 33e048a..2264510 100644
--- a/src/org/torproject/onionoo/CurrentNodes.java
+++ b/src/org/torproject/onionoo/CurrentNodes.java
@@ -253,6 +253,27 @@ public class CurrentNodes {
     }
   }
 
+  public void lookUpASes() {
+    File geoIPASNumDatFile = new File("GeoIPASNum.dat");
+    if (!geoIPASNumDatFile.exists()) {
+      System.err.println("No GeoIPASNum.dat file in /.");
+      return;
+    }
+    try {
+      LookupService ls = new LookupService(geoIPASNumDatFile);
+      for (Node relay : currentRelays.values()) {
+        String org = ls.getOrg(relay.getAddress());
+        if (org != null && org.indexOf(" ") > 0 && org.startsWith("AS")) {
+          relay.setASNumber(org.substring(0, org.indexOf(" ")));
+          relay.setASName(org.substring(org.indexOf(" ") + 1));
+        }
+      }
+      ls.close();
+    } catch (IOException e) {
+      System.err.println("Could not look up ASes for relays.");
+    }
+  }
+
   public void readBridgeNetworkStatuses() {
     DescriptorReader reader =
         DescriptorSourceFactory.createDescriptorReader();
diff --git a/src/org/torproject/onionoo/DetailDataWriter.java b/src/org/torproject/onionoo/DetailDataWriter.java
index 5af8688..e6bdcdd 100644
--- a/src/org/torproject/onionoo/DetailDataWriter.java
+++ b/src/org/torproject/onionoo/DetailDataWriter.java
@@ -309,6 +309,8 @@ public class DetailDataWriter {
       String countryName = entry.getCountryName();
       String regionName = entry.getRegionName();
       String cityName = entry.getCityName();
+      String aSNumber = entry.getASNumber();
+      String aSName = entry.getASName();
       StringBuilder sb = new StringBuilder();
       sb.append("{\"version\":1,\n"
           + "\"nickname\":\"" + nickname + "\",\n"
@@ -346,6 +348,12 @@ public class DetailDataWriter {
       if (cityName != null) {
         sb.append(",\n\"city_name\":\"" + cityName + "\"");
       }
+      if (aSNumber != null) {
+        sb.append(",\n\"as_number\":\"" + aSNumber + "\"");
+      }
+      if (cityName != null) {
+        sb.append(",\n\"as_name\":\"" + aSName + "\"");
+      }
 
       /* Add exit addresses if at least one of them is distinct from the
        * onion-routing addresses. */
diff --git a/src/org/torproject/onionoo/Main.java b/src/org/torproject/onionoo/Main.java
index 7517a23..8c4497d 100644
--- a/src/org/torproject/onionoo/Main.java
+++ b/src/org/torproject/onionoo/Main.java
@@ -12,6 +12,7 @@ public class Main {
     cn.readRelayNetworkConsensuses();
     cn.setRelayRunningBits();
     cn.lookUpCountries();
+    cn.lookUpASes();
     cn.readBridgeNetworkStatuses();
     cn.setBridgeRunningBits();
     cn.writeRelaySearchDataFile();
diff --git a/src/org/torproject/onionoo/Node.java b/src/org/torproject/onionoo/Node.java
index dd4fc8e..ad26746 100644
--- a/src/org/torproject/onionoo/Node.java
+++ b/src/org/torproject/onionoo/Node.java
@@ -16,6 +16,8 @@ public class Node {
   private String countryName;
   private String regionName;
   private String cityName;
+  private String aSName;
+  private String aSNumber;
   private long lastSeenMillis;
   private int orPort;
   private int dirPort;
@@ -77,6 +79,18 @@ public class Node {
   public String getCityName() {
     return this.cityName;
   }
+  public void setASNumber(String aSNumber) {
+    this.aSNumber = aSNumber;
+  }
+  public String getASNumber() {
+    return this.aSNumber;
+  }
+  public void setASName(String aSName) {
+    this.aSName = aSName;
+  }
+  public String getASName() {
+    return this.aSName;
+  }
   public long getLastSeenMillis() {
     return this.lastSeenMillis;
   }

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits