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

[tor-commits] [tor/master] Minor tweaks and comments to nils' geoip v6 code.



commit c03e3d66a910d103d3cce50a3bc1b778f68c36f2
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Wed Mar 28 15:52:33 2012 +0200

    Minor tweaks and comments to nils' geoip v6 code.
---
 doc/tor.1.txt     |    4 ++--
 src/config/geoip6 |    2 +-
 src/or/config.c   |    5 +++--
 src/or/geoip.c    |   26 +++++++++++++++++++++++---
 src/test/test.c   |    4 +++-
 5 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/doc/tor.1.txt b/doc/tor.1.txt
index cd1fb90..6c02f45 100644
--- a/doc/tor.1.txt
+++ b/doc/tor.1.txt
@@ -1458,10 +1458,10 @@ is non-zero):
     does on behalf of clients. (Default: 1)
 
 **GeoIPFile** __filename__::
-    A filename containing IPv4 GeoIP data, for use with BridgeRecordUsageByCountry.
+    A filename containing IPv4 GeoIP data, for use with by-country statistics.
 
 **GeoIPv6File** __filename__::
-    A filename containing IPv6 GeoIP data, for use with BridgeRecordUsageByCountry.
+    A filename containing IPv6 GeoIP data, for use with by-country statistics.
 
 **CellStatistics** **0**|**1**::
     When this option is enabled, Tor writes statistics on the mean time that
diff --git a/src/config/geoip6 b/src/config/geoip6
index fb9cce5..a60868b 100644
--- a/src/config/geoip6
+++ b/src/config/geoip6
@@ -1,6 +1,6 @@
 # Last updated based on February 22 2012 Maxmind GeoLite IPv6 Country
 # wget http://geolite.maxmind.com/download/geoip/database/GeoIPv6.csv.gz
-# cut -d, -f1,2,6 < GeoIPv6.csv|sed 's/[ "]//g' > geoip6
+# cut -d, -f1,2,5 < GeoIPv6.csv|sed 's/[ "]//g' > geoip6
 2001:200::,2001:200:ffff:ffff:ffff:ffff:ffff:ffff,JP
 2001:208::,2001:208:ffff:ffff:ffff:ffff:ffff:ffff,SG
 2001:218::,2001:218:ffff:ffff:ffff:ffff:ffff:ffff,JP
diff --git a/src/or/config.c b/src/or/config.c
index fd6224e..d5df5e7 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -1535,8 +1535,9 @@ options_act(const or_options_t *old_options)
       ((!old_options || !opt_streq(old_options->GeoIPv6File, options->GeoIPv6File))
        || !geoip_is_loaded())) {
     /* XXXX Don't use this "<default>" junk; make our filename options
-     * understand prefixes somehow. -NM */
-    /* XXXX023 Reload GeoIPFile on SIGHUP. -NM */
+     * understand prefixes somehow.  See also comment for GeoIPFile. */
+    /* XXXX024 Reload GeoIPV6File on SIGHUP.  See also comment for
+     * GeoIPFile. */
     char *actual_fname = tor_strdup(options->GeoIPv6File);
 #ifdef _WIN32
     if (!strcmp(actual_fname, "<default>")) {
diff --git a/src/or/geoip.c b/src/or/geoip.c
index 4c28eeb..e19b62a 100644
--- a/src/or/geoip.c
+++ b/src/or/geoip.c
@@ -48,7 +48,8 @@ static smartlist_t *geoip_countries = NULL;
  * The index is encoded in the pointer, and 1 is added so that NULL can mean
  * not found. */
 static strmap_t *country_idxplus1_by_lc_code = NULL;
-/** A list of all known geoip_ipv4_entry_t, sorted by ip_low. */
+/** Lists of all known geoip_ipv4_entry_t and geoip_ipv6_entry_t, sorted
+ * by their respective ip_low. */
 static smartlist_t *geoip_ipv4_entries = NULL, *geoip_ipv6_entries = NULL;
 
 /** SHA1 digest of the GeoIP file to include in extra-info descriptors. */
@@ -203,7 +204,11 @@ geoip_ipv6_add_entry(struct in6_addr low, struct in6_addr high, const char *coun
 }
 
 /** Add an entry to the GeoIP ipv6 table, parsing it from <b>line</b>.  The
- * format is as for geoip_ipv6_load_file(). */
+ * format is as for geoip_load_file(). */
+/* XXX5053 Should this code also support parsing Maxmind's GeoIPv6.csv
+ * format directly, similar to how their v4 format is also accepted?  That
+ * would enable people to use their commercial IPv6 databases instead of
+ * our free one, if they wanted. -KL */
 /*private*/ int
 geoip_ipv6_parse_entry(const char *line)
 {
@@ -260,10 +265,13 @@ _geoip_ipv6_compare_entries(const void **_a, const void **_b)
 }
 
 /** bsearch helper: return -1, 1, or 0 based on comparison of an IPv6 (a pointer
- * to a in6_addr in host order) to a geoip_ipv4_entry_t */
+ * to a in6_addr in host order) to a geoip_ipv6_entry_t */
 static int
 _geoip_ipv6_compare_key_to_entry(const void *_key, const void **_member)
 {
+  /* XXX5053 The following comment isn't correct anymore and I'm not 100%
+   * certain how to fix it, because I don't know what alignment issues
+   * there could be. -KL */
   /* No alignment issue here, since _key really is a pointer to uint32_t */
   const struct in6_addr *addr = (struct in6_addr *)_key;
   const geoip_ipv6_entry_t *entry = *_member;
@@ -374,6 +382,10 @@ geoip_load_file(sa_family_t family, const char *filename, const or_options_t *op
 
   /* Remember file digest so that we can include it in our extra-info
    * descriptors. */
+  /* XXX5053 This is a bug!  We overwrite geoip_digest with whichever file
+   * we parse last.  We'll want to add a separate geoip6_digest and write
+   * a geoip6-db-digest line to our extra-info descriptor.  Needs a
+   * dir-spec.txt patch, too. -KL */
   crypto_digest_get_digest(geoip_digest_env, geoip_digest, DIGEST_LEN);
   crypto_digest_free(geoip_digest_env);
 
@@ -396,6 +408,11 @@ geoip_get_country_by_ipv4(uint32_t ipaddr)
   return ent ? (int)ent->country : 0;
 }
 
+/** Given an IPv6 address, return a number representing the country to
+ * which that address belongs, -1 for "No geoip information available", or
+ * 0 for the 'unknown country'.  The return value will always be less than
+ * geoip_get_n_countries().  To decode it, call geoip_get_country_name().
+ */
 int
 geoip_get_country_by_ipv6(const struct in6_addr *addr)
 {
@@ -450,6 +467,9 @@ geoip_get_country_name(country_t num)
 int
 geoip_is_loaded(void)
 {
+  /* XXX5053 Saying that we have loaded a GeoIP database if have _either_
+   * a v4 or v6 database might be problematic.  Maybe we need to add an
+   * address parameter to this function? -KL */
   return geoip_countries != NULL && (geoip_ipv4_entries != NULL || geoip_ipv6_entries != NULL);
 }
 
diff --git a/src/test/test.c b/src/test/test.c
index df0edda..a1806fc 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -1483,6 +1483,8 @@ test_geoip(void)
   test_eq(0, geoip_ipv6_parse_entry("::a,::32,AB"));
   test_eq(0, geoip_ipv6_parse_entry("::34,::5a,XY"));
   test_eq(0, geoip_ipv6_parse_entry("::5f,::64,AB"));
+  /* XXX5053 If we plan to support parsing Maxmind's GeoIPv6.csv format,
+   * we should test it here.  If not, remove this comment. -KL */
   test_eq(0, geoip_ipv6_parse_entry("::69,::8c,ZZ"));
   test_eq(0, geoip_ipv6_parse_entry("::96,::be,XY"));
   test_eq(0, geoip_ipv6_parse_entry("::c8,::fa,AB"));
@@ -1535,7 +1537,7 @@ test_geoip(void)
     SET_TEST_ADDRESS(i);
     geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, now-7200);
   }
-  SET_TEST_ADDRESS(i);
+  SET_TEST_ADDRESS(225);
   geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, now-7200);
   /* and 3 observations in XY, several times. */
   for (j=0; j < 10; ++j)



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