[or-cvs] [tor/master] Merge remote branch 'origin/maint-0.2.2'
nickm at torproject.org
nickm at torproject.org
Tue Jan 25 20:58:00 UTC 2011
commit 991b50c5a321070f9c61653c9509ffbf251b6410
Merge: 36880b3 7a446e6
Author: Nick Mathewson <nickm at torproject.org>
Date: Tue Jan 25 15:58:01 2011 -0500
Merge remote branch 'origin/maint-0.2.2'
Conflicts:
src/or/geoip.c
changes/bug2432 | 5 +++++
src/or/geoip.c | 2 +-
2 files changed, 6 insertions(+), 1 deletions(-)
diff --combined src/or/geoip.c
index 7f0c5c3,e5694b9..c99758e
--- a/src/or/geoip.c
+++ b/src/or/geoip.c
@@@ -44,9 -44,6 +44,9 @@@ static strmap_t *country_idxplus1_by_lc
/** A list of all known geoip_entry_t, sorted by ip_low. */
static smartlist_t *geoip_entries = NULL;
+/** SHA1 digest of the GeoIP file to include in extra-info descriptors. */
+static char geoip_digest[DIGEST_LEN];
+
/** Return the index of the <b>country</b>'s entry in the GeoIP DB
* if it is a valid 2-letter country code, otherwise return -1.
*/
@@@ -204,9 -201,8 +204,9 @@@ geoip_load_file(const char *filename, o
FILE *f;
const char *msg = "";
int severity = options_need_geoip_info(options, &msg) ? LOG_WARN : LOG_INFO;
+ crypto_digest_env_t *geoip_digest_env = NULL;
clear_geoip_db();
- if (!(f = fopen(filename, "r"))) {
+ if (!(f = tor_fopen_cloexec(filename, "r"))) {
log_fn(severity, LD_GENERAL, "Failed to open GEOIP file %s. %s",
filename, msg);
return -1;
@@@ -218,13 -214,11 +218,13 @@@
smartlist_free(geoip_entries);
}
geoip_entries = smartlist_create();
+ geoip_digest_env = crypto_new_digest_env();
- log_notice(LD_GENERAL, "Parsing GEOIP file.");
+ log_notice(LD_GENERAL, "Parsing GEOIP file %s.", filename);
while (!feof(f)) {
char buf[512];
if (fgets(buf, (int)sizeof(buf), f) == NULL)
break;
+ crypto_digest_add_bytes(geoip_digest_env, buf, strlen(buf));
/* FFFF track full country name. */
geoip_parse_entry(buf);
}
@@@ -237,11 -231,6 +237,11 @@@
* country. */
refresh_all_country_info();
+ /* Remember file digest so that we can include it in our extra-info
+ * descriptors. */
+ crypto_digest_get_digest(geoip_digest_env, geoip_digest, DIGEST_LEN);
+ crypto_free_digest_env(geoip_digest_env);
+
return 0;
}
@@@ -289,15 -278,6 +289,15 @@@ geoip_is_loaded(void
return geoip_countries != NULL && geoip_entries != NULL;
}
+/** 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)
+{
+ return hex_str(geoip_digest, DIGEST_LEN);
+}
+
/** Entry in a map from IP address to the last time we've seen an incoming
* connection from that IP address. Used by bridges only, to track which
* countries have them blocked. */
More information about the tor-commits
mailing list