[or-cvs] r18100: {tor} Refactor MIN_IPS_TO_NOTE_* macros in geoip.c: simplify code. (tor/trunk/src/or)

nickm at seul.org nickm at seul.org
Wed Jan 14 06:20:59 UTC 2009


Author: nickm
Date: 2009-01-14 01:20:57 -0500 (Wed, 14 Jan 2009)
New Revision: 18100

Modified:
   tor/trunk/src/or/geoip.c
Log:
Refactor MIN_IPS_TO_NOTE_* macros in geoip.c: simplify code.

It was dumb to have an "announce the value if it's over 0" version of
the code coexisting with an "announce the value if it's at least N"
version.  Retain the latter only, with N set to 1.

Incidentally, this should fix a Coverity REVERSE_INULL warning.

Modified: tor/trunk/src/or/geoip.c
===================================================================
--- tor/trunk/src/or/geoip.c	2009-01-14 04:03:24 UTC (rev 18099)
+++ tor/trunk/src/or/geoip.c	2009-01-14 06:20:57 UTC (rev 18100)
@@ -395,10 +395,10 @@
 /** Do not mention any country from which fewer than this number of IPs have
  * connected.  This conceivably avoids reporting information that could
  * deanonymize users, though analysis is lacking. */
-#define MIN_IPS_TO_NOTE_COUNTRY 0
+#define MIN_IPS_TO_NOTE_COUNTRY 1
 /** Do not report any geoip data at all if we have fewer than this number of
  * IPs to report about. */
-#define MIN_IPS_TO_NOTE_ANYTHING 0
+#define MIN_IPS_TO_NOTE_ANYTHING 1
 /** When reporting geoip data about countries, round up to the nearest
  * multiple of this value. */
 #define IP_GRANULARITY 8
@@ -482,10 +482,8 @@
       ++total;
     }
     /* Don't record anything if we haven't seen enough IPs. */
-#if (MIN_IPS_TO_NOTE_ANYTHING > 0)
     if (total < MIN_IPS_TO_NOTE_ANYTHING)
       goto done;
-#endif
     /* Make a list of c_hist_t */
     entries = smartlist_create();
     for (i = 0; i < n_countries; ++i) {
@@ -493,11 +491,7 @@
       const char *countrycode;
       c_hist_t *ent;
       /* Only report a country if it has a minimum number of IPs. */
-#if (MIN_IPS_TO_NOTE_COUNTRY > 0)
       if (c >= MIN_IPS_TO_NOTE_COUNTRY) {
-#else
-      if (c > 0) {
-#endif
         c = round_to_next_multiple_of(c, granularity);
         countrycode = geoip_get_country_name(i);
         ent = tor_malloc(sizeof(c_hist_t));
@@ -517,9 +511,7 @@
         smartlist_add(chunks, tor_strdup(buf));
       });
     result = smartlist_join_strings(chunks, ",", 0, NULL);
-#if (MIN_IPS_TO_NOTE_ANYTHING > 0)
   done:
-#endif
     tor_free(counts);
     if (chunks) {
       SMARTLIST_FOREACH(chunks, char *, c, tor_free(c));



More information about the tor-commits mailing list