[or-cvs] [tor/master 2/2] Add two fixes to the new geoip-db-digest line.

nickm at torproject.org nickm at torproject.org
Fri Nov 12 19:13:36 UTC 2010


Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Fri, 12 Nov 2010 09:06:27 +0100
Subject: Add two fixes to the new geoip-db-digest line.
Commit: 8833381d9c6ae274599b16fc11cec7527b12c465

---
 src/or/geoip.c  |    4 +++-
 src/or/router.c |   21 ++++++++++-----------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/src/or/geoip.c b/src/or/geoip.c
index b2a47aa..ae0776a 100644
--- a/src/or/geoip.c
+++ b/src/or/geoip.c
@@ -289,7 +289,9 @@ geoip_is_loaded(void)
   return geoip_countries != NULL && geoip_entries != NULL;
 }
 
-/** Return the hex-encoded SHA1 digest of the loaded GeoIP file. */
+/** Return the hex-encoded SHA1 digest of the loaded GeoIP file. The
+ * result does not need to be deallocated, but will be overwritten by the
+ * next call of hex_str(). */
 const char *
 geoip_db_digest(void)
 {
diff --git a/src/or/router.c b/src/or/router.c
index 85300a3..4d3c66f 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -2012,20 +2012,19 @@ extrainfo_dump_to_string(char *s, size_t maxlen, extrainfo_t *extrainfo,
   if (result<0)
     return -1;
 
+  if (geoip_is_loaded()) {
+    if (tor_snprintf(s + strlen(s), maxlen - strlen(s),
+                     "geoip-db-digest %s\n",
+                     geoip_db_digest()) < 0) {
+      log_warn(LD_DIR, "Could not write geoip-db-digest to extra-info "
+               "descriptor.");
+      return -1;
+    }
+  }
+
   if (options->ExtraInfoStatistics && write_stats_to_extrainfo) {
     char *contents = NULL;
     log_info(LD_GENERAL, "Adding stats to extra-info descriptor.");
-    if (geoip_is_loaded()) {
-      size_t pos = strlen(s);
-      if (tor_snprintf(s + pos, maxlen - strlen(s),
-                       "geoip-db-digest %s\n",
-                       geoip_db_digest()) < 0) {
-        log_warn(LD_DIR, "Could not write geoip-db-digest to extra-info "
-                 "descriptor.");
-        s[pos] = '\0';
-        write_stats_to_extrainfo = 0;
-      }
-    }
     if (options->DirReqStatistics &&
         load_stats_file("stats"PATH_SEPARATOR"dirreq-stats",
                         "dirreq-stats-end", now, &contents) > 0) {
-- 
1.7.1



More information about the tor-commits mailing list