diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-09-27 10:15:39 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-09-27 10:15:39 -0400 |
commit | fa32574bdb7381f02abc68ad917ad79f354938a4 (patch) | |
tree | 77ef274275246db9506f713094eea61927ecf5bf /src/feature/stats | |
parent | f403af22076b0092807822ddc9890acdbd62f578 (diff) | |
download | tor-fa32574bdb7381f02abc68ad917ad79f354938a4.tar.gz tor-fa32574bdb7381f02abc68ad917ad79f354938a4.zip |
Remove excess dependencies from geoip.c
Diffstat (limited to 'src/feature/stats')
-rw-r--r-- | src/feature/stats/geoip.c | 41 | ||||
-rw-r--r-- | src/feature/stats/geoip.h | 12 |
2 files changed, 34 insertions, 19 deletions
diff --git a/src/feature/stats/geoip.c b/src/feature/stats/geoip.c index 885f26bc3c..4966150802 100644 --- a/src/feature/stats/geoip.c +++ b/src/feature/stats/geoip.c @@ -28,16 +28,32 @@ */ #define GEOIP_PRIVATE -#include "core/or/or.h" -#include "ht.h" -#include "lib/container/buffers.h" -#include "app/config/config.h" // XXXX -#include "feature/stats/geoip.h" -#include "feature/nodelist/routerlist.h" // XXXX +#include "lib/cc/torint.h" +/** A signed integer representing a country code. */ +typedef int16_t country_t; // XXXX duplicate in or.h + +#include "feature/stats/geoip.h" +#include "lib/container/map.h" #include "lib/container/order.h" +#include "lib/container/smartlist.h" +#include "lib/crypt_ops/crypto_digest.h" +#include "lib/ctime/di_ops.h" +#include "lib/encoding/binascii.h" +#include "lib/fs/files.h" +#include "lib/log/escape.h" +#include "lib/malloc/malloc.h" +#include "lib/net/address.h" //???? +#include "lib/net/inaddr.h" +#include "lib/string/compat_ctype.h" +#include "lib/string/compat_string.h" +#include "lib/string/scanf.h" +#include "lib/string/util_string.h" #include "lib/time/tvdiff.h" +#include <stdio.h> +#include <string.h> + static void init_geoip_countries(void); /** An entry from the GeoIP IPv4 file: maps an IPv4 range to a country. */ @@ -305,19 +321,16 @@ init_geoip_countries(void) * with '#' (comments). */ int -geoip_load_file(sa_family_t family, const char *filename) +geoip_load_file(sa_family_t family, const char *filename, int severity) { FILE *f; - const char *msg = ""; - const or_options_t *options = get_options(); - int severity = options_need_geoip_info(options, &msg) ? LOG_WARN : LOG_INFO; crypto_digest_t *geoip_digest_env = NULL; tor_assert(family == AF_INET || family == AF_INET6); if (!(f = tor_fopen_cloexec(filename, "r"))) { - log_fn(severity, LD_GENERAL, "Failed to open GEOIP file %s. %s", - filename, msg); + log_fn(severity, LD_GENERAL, "Failed to open GEOIP file %s.", + filename); return -1; } if (!geoip_countries) @@ -357,10 +370,6 @@ geoip_load_file(sa_family_t family, const char *filename) * our extra-info descriptors. */ if (family == AF_INET) { smartlist_sort(geoip_ipv4_entries, geoip_ipv4_compare_entries_); - /* Okay, now we need to maybe change our mind about what is in - * which country. We do this for IPv4 only since that's what we - * store in node->country. */ - refresh_all_country_info(); crypto_digest_get_digest(geoip_digest_env, geoip_digest, DIGEST_LEN); } else { /* AF_INET6 */ diff --git a/src/feature/stats/geoip.h b/src/feature/stats/geoip.h index 4adfc10fba..1ca04cdff6 100644 --- a/src/feature/stats/geoip.h +++ b/src/feature/stats/geoip.h @@ -12,13 +12,18 @@ #ifndef TOR_GEOIP_H #define TOR_GEOIP_H +#include "lib/net/nettypes.h" #include "lib/testsupport/testsupport.h" +#include "lib/cc/torint.h" #ifdef GEOIP_PRIVATE STATIC int geoip_parse_entry(const char *line, sa_family_t family); STATIC void clear_geoip_db(void); #endif /* defined(GEOIP_PRIVATE) */ +struct in6_addr; +struct tor_addr_t; + int geoip_get_country_by_ipv4(uint32_t ipaddr); int geoip_get_country_by_ipv6(const struct in6_addr *addr); @@ -27,10 +32,11 @@ typedef struct geoip_country_t { char countrycode[3]; } geoip_country_t; -const smartlist_t *geoip_get_countries(void); +struct smartlist_t; +const struct smartlist_t *geoip_get_countries(void); -int geoip_load_file(sa_family_t family, const char *filename); -MOCK_DECL(int, geoip_get_country_by_addr, (const tor_addr_t *addr)); +int geoip_load_file(sa_family_t family, const char *filename, int severity); +MOCK_DECL(int, geoip_get_country_by_addr, (const struct tor_addr_t *addr)); MOCK_DECL(int, geoip_get_n_countries, (void)); const char *geoip_get_country_name(country_t num); MOCK_DECL(int, geoip_is_loaded, (sa_family_t family)); |