implement more fine-tuning options for stats code
[tor.git] / src / or / geoip.c
blobb795bccee7b4982863e8a659ba021c9bb0faeb1e
1 /* Copyright (c) 2007-2008, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 /* $Id: /tor/trunk/src/or/networkstatus.c 15493 2007-12-16T18:33:25.055570Z nickm $ */
4 const char geoip_c_id[] =
5 "$Id: /tor/trunk/src/or/networkstatus.c 15493 2007-12-16T18:33:25.055570Z nickm $";
7 /**
8 * \file geoip.c
9 * \brief Functions related to maintaining an IP-to-country database and to
10 * summarizing client connections by country.
13 #define GEOIP_PRIVATE
14 #include "or.h"
15 #include "ht.h"
17 static void clear_geoip_db(void);
19 /** An entry from the GeoIP file: maps an IP range to a country. */
20 typedef struct geoip_entry_t {
21 uint32_t ip_low; /**< The lowest IP in the range, in host order */
22 uint32_t ip_high; /**< The highest IP in the range, in host order */
23 intptr_t country; /**< An index into geoip_countries */
24 } geoip_entry_t;
26 /** DOCDOC */
27 #define REQUEST_HIST_LEN 3
28 #define REQUEST_HIST_PERIOD (8*60*60)
30 typedef struct geoip_country_t {
31 char countrycode[3];
32 uint32_t n_v2_ns_requests[REQUEST_HIST_LEN];
33 uint32_t n_v3_ns_requests[REQUEST_HIST_LEN];
34 } geoip_country_t;
36 /** A list of geoip_country_t */
37 static smartlist_t *geoip_countries = NULL;
38 /** A map from lowercased country codes to their position in geoip_countries.
39 * The index is encoded in the pointer, and 1 is added so that NULL can mean
40 * not found. */
41 static strmap_t *country_idxplus1_by_lc_code = NULL;
42 /** A list of all known geoip_entry_t, sorted by ip_low. */
43 static smartlist_t *geoip_entries = NULL;
45 /** Add an entry to the GeoIP table, mapping all IPs between <b>low</b> and
46 * <b>high</b>, inclusive, to the 2-letter country code <b>country</b>.
48 static void
49 geoip_add_entry(uint32_t low, uint32_t high, const char *country)
51 intptr_t idx;
52 geoip_entry_t *ent;
53 void *_idxplus1;
55 if (high < low)
56 return;
58 _idxplus1 = strmap_get_lc(country_idxplus1_by_lc_code, country);
60 if (!_idxplus1) {
61 geoip_country_t *c = tor_malloc_zero(sizeof(geoip_country_t));
62 strlcpy(c->countrycode, country, sizeof(c->countrycode));
63 tor_strlower(c->countrycode);
64 smartlist_add(geoip_countries, c);
65 idx = smartlist_len(geoip_countries) - 1;
66 strmap_set_lc(country_idxplus1_by_lc_code, country, (void*)(idx+1));
67 } else {
68 idx = ((uintptr_t)_idxplus1)-1;
71 geoip_country_t *c = smartlist_get(geoip_countries, idx);
72 tor_assert(!strcasecmp(c->countrycode, country));
74 ent = tor_malloc_zero(sizeof(geoip_entry_t));
75 ent->ip_low = low;
76 ent->ip_high = high;
77 ent->country = idx;
78 smartlist_add(geoip_entries, ent);
81 /** Add an entry to the GeoIP table, parsing it from <b>line</b>. The
82 * format is as for geoip_load_file(). */
83 /*private*/ int
84 geoip_parse_entry(const char *line)
86 unsigned int low, high;
87 char b[3];
88 if (!geoip_countries) {
89 geoip_countries = smartlist_create();
90 geoip_entries = smartlist_create();
91 country_idxplus1_by_lc_code = strmap_new();
93 while (TOR_ISSPACE(*line))
94 ++line;
95 if (*line == '#')
96 return 0;
97 if (sscanf(line,"%u,%u,%2s", &low, &high, b) == 3) {
98 geoip_add_entry(low, high, b);
99 return 0;
100 } else if (sscanf(line,"\"%u\",\"%u\",\"%2s\",", &low, &high, b) == 3) {
101 geoip_add_entry(low, high, b);
102 return 0;
103 } else {
104 log_warn(LD_GENERAL, "Unable to parse line from GEOIP file: %s",
105 escaped(line));
106 return -1;
110 /** Sorting helper: return -1, 1, or 0 based on comparison of two
111 * geoip_entry_t */
112 static int
113 _geoip_compare_entries(const void **_a, const void **_b)
115 const geoip_entry_t *a = *_a, *b = *_b;
116 if (a->ip_low < b->ip_low)
117 return -1;
118 else if (a->ip_low > b->ip_low)
119 return 1;
120 else
121 return 0;
124 /** bsearch helper: return -1, 1, or 0 based on comparison of an IP (a pointer
125 * to a uint32_t in host order) to a geoip_entry_t */
126 static int
127 _geoip_compare_key_to_entry(const void *_key, const void **_member)
129 const uint32_t addr = *(uint32_t *)_key;
130 const geoip_entry_t *entry = *_member;
131 if (addr < entry->ip_low)
132 return -1;
133 else if (addr > entry->ip_high)
134 return 1;
135 else
136 return 0;
139 /** Return 1 if we should collect geoip stats on bridge users, and
140 * include them in our extrainfo descriptor. Else return 0. */
142 should_record_bridge_info(or_options_t *options)
144 return options->BridgeRelay && options->BridgeRecordUsageByCountry;
147 /** Clear the GeoIP database and reload it from the file
148 * <b>filename</b>. Return 0 on success, -1 on failure.
150 * Recognized line formats are:
151 * INTIPLOW,INTIPHIGH,CC
152 * and
153 * "INTIPLOW","INTIPHIGH","CC","CC3","COUNTRY NAME"
154 * where INTIPLOW and INTIPHIGH are IPv4 addresses encoded as 4-byte unsigned
155 * integers, and CC is a country code.
157 * It also recognizes, and skips over, blank lines and lines that start
158 * with '#' (comments).
161 geoip_load_file(const char *filename, or_options_t *options)
163 FILE *f;
164 int severity = should_record_bridge_info(options) ? LOG_WARN : LOG_INFO;
165 clear_geoip_db();
166 if (!(f = fopen(filename, "r"))) {
167 log_fn(severity, LD_GENERAL, "Failed to open GEOIP file %s.", filename);
168 return -1;
170 geoip_countries = smartlist_create();
171 geoip_entries = smartlist_create();
172 country_idxplus1_by_lc_code = strmap_new();
173 log_info(LD_GENERAL, "Parsing GEOIP file.");
174 while (!feof(f)) {
175 char buf[512];
176 if (fgets(buf, (int)sizeof(buf), f) == NULL)
177 break;
178 /* FFFF track full country name. */
179 geoip_parse_entry(buf);
181 /*XXXX020 abort and return -1 if no entries/illformed?*/
182 fclose(f);
184 smartlist_sort(geoip_entries, _geoip_compare_entries);
185 return 0;
188 /** Given an IP address in host order, return a number representing the
189 * country to which that address belongs, or -1 for unknown. The return value
190 * will always be less than geoip_get_n_countries(). To decode it,
191 * call geoip_get_country_name().
194 geoip_get_country_by_ip(uint32_t ipaddr)
196 geoip_entry_t *ent;
197 if (!geoip_entries)
198 return -1;
199 ent = smartlist_bsearch(geoip_entries, &ipaddr, _geoip_compare_key_to_entry);
200 return ent ? (int)ent->country : -1;
203 /** Return the number of countries recognized by the GeoIP database. */
205 geoip_get_n_countries(void)
207 return (int) smartlist_len(geoip_countries);
210 /** Return the two-letter country code associated with the number <b>num</b>,
211 * or "??" for an unknown value. */
212 const char *
213 geoip_get_country_name(int num)
215 if (geoip_countries && num >= 0 && num < smartlist_len(geoip_countries)) {
216 geoip_country_t *c = smartlist_get(geoip_countries, num);
217 return c->countrycode;
218 } else
219 return "??";
222 /** Return true iff we have loaded a GeoIP database.*/
224 geoip_is_loaded(void)
226 return geoip_countries != NULL && geoip_entries != NULL;
229 /** Entry in a map from IP address to the last time we've seen an incoming
230 * connection from that IP address. Used by bridges only, to track which
231 * countries have them blocked. */
232 typedef struct clientmap_entry_t {
233 HT_ENTRY(clientmap_entry_t) node;
234 uint32_t ipaddr;
235 time_t last_seen; /* The last 2 bits of this value hold the client
236 * operation. */
237 } clientmap_entry_t;
239 #define ACTION_MASK 3
241 /** Map from client IP address to last time seen. */
242 static HT_HEAD(clientmap, clientmap_entry_t) client_history =
243 HT_INITIALIZER();
244 /** Time at which we started tracking client IP history. */
245 static time_t client_history_starts = 0;
247 /** DOCDOC */
248 static time_t current_request_period_starts = 0;
249 static int n_old_request_periods = 0;
251 /** Hashtable helper: compute a hash of a clientmap_entry_t. */
252 static INLINE unsigned
253 clientmap_entry_hash(const clientmap_entry_t *a)
255 return ht_improve_hash((unsigned) a->ipaddr);
257 /** Hashtable helper: compare two clientmap_entry_t values for equality. */
258 static INLINE int
259 clientmap_entries_eq(const clientmap_entry_t *a, const clientmap_entry_t *b)
261 return a->ipaddr == b->ipaddr;
264 HT_PROTOTYPE(clientmap, clientmap_entry_t, node, clientmap_entry_hash,
265 clientmap_entries_eq);
266 HT_GENERATE(clientmap, clientmap_entry_t, node, clientmap_entry_hash,
267 clientmap_entries_eq, 0.6, malloc, realloc, free);
269 /** Note that we've seen a client connect from the IP <b>addr</b> (host order)
270 * at time <b>now</b>. Ignored by all but bridges. */
271 void
272 geoip_note_client_seen(geoip_client_action_t action,
273 uint32_t addr, time_t now)
275 or_options_t *options = get_options();
276 clientmap_entry_t lookup, *ent;
277 if (action == GEOIP_CLIENT_CONNECT) {
278 if (!(options->BridgeRelay && options->BridgeRecordUsageByCountry))
279 return;
280 } else {
281 #ifndef ENABLE_GEOIP_STATS
282 return;
283 #else
284 if (options->BridgeRelay || options->BridgeAuthoritativeDir ||
285 !options->DirRecordUsageByCountry)
286 return;
287 #endif
290 /* DOCDOC */
291 while (current_request_period_starts + REQUEST_HIST_PERIOD < now) {
292 if (!geoip_countries)
293 geoip_countries = smartlist_create();
294 if (!current_request_period_starts) {
295 current_request_period_starts = now;
296 break;
298 SMARTLIST_FOREACH(geoip_countries, geoip_country_t *, c, {
299 memmove(&c->n_v2_ns_requests[0], &c->n_v2_ns_requests[1],
300 sizeof(uint32_t)*(REQUEST_HIST_LEN-1));
301 memmove(&c->n_v3_ns_requests[0], &c->n_v3_ns_requests[1],
302 sizeof(uint32_t)*(REQUEST_HIST_LEN-1));
303 c->n_v2_ns_requests[REQUEST_HIST_LEN-1] = 0;
304 c->n_v3_ns_requests[REQUEST_HIST_LEN-1] = 0;
306 current_request_period_starts += REQUEST_HIST_PERIOD;
307 if (n_old_request_periods < REQUEST_HIST_LEN-1)
308 ++n_old_request_periods;
311 /* We use the low 3 bits of the time to encode the action. Since we're
312 * potentially remembering tons of clients, we don't want to make
313 * clientmap_entry_t larger than it has to be. */
314 now = (now & ~ACTION_MASK) | (((int)action) & ACTION_MASK);
315 lookup.ipaddr = addr;
316 ent = HT_FIND(clientmap, &client_history, &lookup);
317 if (ent) {
318 ent->last_seen = now;
319 } else {
320 ent = tor_malloc_zero(sizeof(clientmap_entry_t));
321 ent->ipaddr = addr;
322 ent->last_seen = now;
323 HT_INSERT(clientmap, &client_history, ent);
326 if (action == GEOIP_CLIENT_NETWORKSTATUS ||
327 action == GEOIP_CLIENT_NETWORKSTATUS_V2) {
328 int country_idx = geoip_get_country_by_ip(addr);
329 if (country_idx >= 0 && country_idx < smartlist_len(geoip_countries)) {
330 geoip_country_t *country = smartlist_get(geoip_countries, country_idx);
331 if (action == GEOIP_CLIENT_NETWORKSTATUS)
332 ++country->n_v3_ns_requests[REQUEST_HIST_LEN-1];
333 else
334 ++country->n_v2_ns_requests[REQUEST_HIST_LEN-1];
338 if (!client_history_starts) {
339 client_history_starts = now;
340 current_request_period_starts = now;
344 /** HT_FOREACH helper: remove a clientmap_entry_t from the hashtable if it's
345 * older than a certain time. */
346 static int
347 _remove_old_client_helper(struct clientmap_entry_t *ent, void *_cutoff)
349 time_t cutoff = *(time_t*)_cutoff;
350 if (ent->last_seen < cutoff) {
351 tor_free(ent);
352 return 1;
353 } else {
354 return 0;
358 /** Forget about all clients that haven't connected since <b>cutoff</b>. */
359 void
360 geoip_remove_old_clients(time_t cutoff)
362 clientmap_HT_FOREACH_FN(&client_history,
363 _remove_old_client_helper,
364 &cutoff);
365 if (client_history_starts < cutoff)
366 client_history_starts = cutoff;
369 /** Do not mention any country from which fewer than this number of IPs have
370 * connected. This conceivably avoids reporting information that could
371 * deanonymize users, though analysis is lacking. */
372 #define MIN_IPS_TO_NOTE_COUNTRY 0
373 /** Do not report any geoip data at all if we have fewer than this number of
374 * IPs to report about. */
375 #define MIN_IPS_TO_NOTE_ANYTHING 0
376 /** When reporting geoip data about countries, round up to the nearest
377 * multiple of this value. */
378 #define IP_GRANULARITY 8
380 /** Return the time at which we started recording geoip data. */
381 time_t
382 geoip_get_history_start(void)
384 return client_history_starts;
387 /** Helper type: used to sort per-country totals by value. */
388 typedef struct c_hist_t {
389 char country[3]; /**< Two-letter country code. */
390 unsigned total; /**< Total IP addresses seen in this country. */
391 } c_hist_t;
393 /** Sorting helper: return -1, 1, or 0 based on comparison of two
394 * geoip_entry_t. Sort in descending order of total, and then by country
395 * code. */
396 static int
397 _c_hist_compare(const void **_a, const void **_b)
399 const c_hist_t *a = *_a, *b = *_b;
400 if (a->total > b->total)
401 return -1;
402 else if (a->total < b->total)
403 return 1;
404 else
405 return strcmp(a->country, b->country);
408 /*DOCDOC*/
409 #define GEOIP_MIN_OBSERVATION_TIME (12*60*60)
411 static INLINE unsigned
412 round_to_next_multiple_of(unsigned number, unsigned divisor)
414 number += divisor - 1;
415 number -= number % divisor;
416 return number;
419 /** Return a newly allocated comma-separated string containing entries for all
420 * the countries from which we've seen enough clients connect. The entry
421 * format is cc=num where num is the number of IPs we've seen connecting from
422 * that country, and cc is a lowercased country code. Returns NULL if we don't
423 * want to export geoip data yet. */
424 char *
425 geoip_get_client_history(time_t now, geoip_client_action_t action)
427 char *result = NULL;
428 if (!geoip_is_loaded())
429 return NULL;
430 if (client_history_starts < (now - GEOIP_MIN_OBSERVATION_TIME)) {
431 char buf[32];
432 smartlist_t *chunks = NULL;
433 smartlist_t *entries = NULL;
434 int n_countries = geoip_get_n_countries();
435 int i;
436 clientmap_entry_t **ent;
437 unsigned *counts = tor_malloc_zero(sizeof(unsigned)*n_countries);
438 unsigned total = 0;
439 unsigned granularity = IP_GRANULARITY;
440 #ifdef ENABLE_GEOIP_STATS
441 if (get_options()->DirRecordUsageByCountry)
442 granularity = get_options()->DirRecordUsageGranularity;
443 #endif
444 HT_FOREACH(ent, clientmap, &client_history) {
445 int country;
446 if (((*ent)->last_seen & ACTION_MASK) != action)
447 continue;
448 country = geoip_get_country_by_ip((*ent)->ipaddr);
449 if (country < 0)
450 continue;
451 tor_assert(0 <= country && country < n_countries);
452 ++counts[country];
453 ++total;
455 /* Don't record anything if we haven't seen enough IPs. */
456 #if (MIN_IPS_TO_NOTE_ANYTHING > 0)
457 if (total < MIN_IPS_TO_NOTE_ANYTHING)
458 goto done;
459 #endif
460 /* Make a list of c_hist_t */
461 entries = smartlist_create();
462 for (i = 0; i < n_countries; ++i) {
463 unsigned c = counts[i];
464 const char *countrycode;
465 c_hist_t *ent;
466 /* Only report a country if it has a minimum number of IPs. */
467 #if (MIN_IPS_TO_NOTE_COUNTRY > 0)
468 if (c >= MIN_IPS_TO_NOTE_COUNTRY) {
469 #else
470 if (c > 0) {
471 #endif
472 c = round_to_next_multiple_of(c, granularity);
473 countrycode = geoip_get_country_name(i);
474 ent = tor_malloc(sizeof(c_hist_t));
475 strlcpy(ent->country, countrycode, sizeof(ent->country));
476 ent->total = c;
477 smartlist_add(entries, ent);
480 /* Sort entries. Note that we must do this _AFTER_ rounding, or else
481 * the sort order could leak info. */
482 smartlist_sort(entries, _c_hist_compare);
484 /* Build the result. */
485 chunks = smartlist_create();
486 SMARTLIST_FOREACH(entries, c_hist_t *, ch, {
487 tor_snprintf(buf, sizeof(buf), "%s=%u", ch->country, ch->total);
488 smartlist_add(chunks, tor_strdup(buf));
490 result = smartlist_join_strings(chunks, ",", 0, NULL);
491 #if (MIN_IPS_TO_NOTE_ANYTHING > 0)
492 done:
493 #endif
494 tor_free(counts);
495 if (chunks) {
496 SMARTLIST_FOREACH(chunks, char *, c, tor_free(c));
497 smartlist_free(chunks);
499 if (entries) {
500 SMARTLIST_FOREACH(entries, c_hist_t *, c, tor_free(c));
501 smartlist_free(entries);
504 return result;
507 /**DOCDOC*/
508 char *
509 geoip_get_request_history(time_t now, geoip_client_action_t action)
511 smartlist_t *entries, *strings;
512 char *result;
513 unsigned granularity = IP_GRANULARITY;
514 #ifdef ENABLE_GEOIP_STATS
515 if (get_options()->DirRecordUsageByCountry)
516 granularity = get_options()->DirRecordUsageGranularity;
517 #endif
519 if (client_history_starts >= (now - GEOIP_MIN_OBSERVATION_TIME))
520 return NULL;
521 if (action != GEOIP_CLIENT_NETWORKSTATUS &&
522 action != GEOIP_CLIENT_NETWORKSTATUS_V2)
523 return NULL;
524 if (!geoip_countries)
525 return NULL;
527 entries = smartlist_create();
528 SMARTLIST_FOREACH(geoip_countries, geoip_country_t *, c, {
529 uint32_t *n = (action == GEOIP_CLIENT_NETWORKSTATUS)
530 ? c->n_v3_ns_requests : c->n_v2_ns_requests;
531 uint32_t tot = 0;
532 int i;
533 c_hist_t *ent;
534 for (i=0; i < REQUEST_HIST_LEN; ++i)
535 tot += n[i];
536 if (!tot)
537 continue;
538 ent = tor_malloc_zero(sizeof(c_hist_t));
539 strlcpy(ent->country, c->countrycode, sizeof(ent->country));
540 ent->total = round_to_next_multiple_of(tot, granularity);
541 smartlist_add(entries, ent);
543 smartlist_sort(entries, _c_hist_compare);
545 strings = smartlist_create();
546 SMARTLIST_FOREACH(entries, c_hist_t *, ent, {
547 char buf[32];
548 tor_snprintf(buf, sizeof(buf), "%s=%u", ent->country, ent->total);
549 smartlist_add(strings, tor_strdup(buf));
551 result = smartlist_join_strings(strings, ",", 0, NULL);
552 SMARTLIST_FOREACH(strings, char *, cp, tor_free(cp));
553 SMARTLIST_FOREACH(entries, c_hist_t *, ent, tor_free(ent));
554 smartlist_free(strings);
555 smartlist_free(entries);
556 return result;
559 void
560 dump_geoip_stats(void)
562 #ifdef ENABLE_GEOIP_STATS
563 time_t now = time(NULL);
564 time_t request_start;
565 char *filename = get_datadir_fname("geoip-stats");
566 char *data_v2 = NULL, *data_v3 = NULL;
567 char since[ISO_TIME_LEN+1], written[ISO_TIME_LEN+1];
568 open_file_t *open_file = NULL;
569 double v2_share = 0.0, v3_share = 0.0;
570 FILE *out;
572 data_v2 = geoip_get_client_history(now, GEOIP_CLIENT_NETWORKSTATUS_V2);
573 data_v3 = geoip_get_client_history(now, GEOIP_CLIENT_NETWORKSTATUS);
574 format_iso_time(since, geoip_get_history_start());
575 format_iso_time(written, now);
576 out = start_writing_to_stdio_file(filename, OPEN_FLAGS_REPLACE,
577 0600, &open_file);
578 if (!out)
579 goto done;
580 if (fprintf(out, "written %s\nstarted-at %s\nns-ips %s\nns-v2-ips %s\n",
581 written, since,
582 data_v3 ? data_v3 : "", data_v2 ? data_v2 : "") < 0)
583 goto done;
584 tor_free(data_v2);
585 tor_free(data_v3);
587 request_start = current_request_period_starts -
588 (n_old_request_periods * REQUEST_HIST_PERIOD);
589 format_iso_time(since, request_start);
590 data_v2 = geoip_get_request_history(now, GEOIP_CLIENT_NETWORKSTATUS_V2);
591 data_v3 = geoip_get_request_history(now, GEOIP_CLIENT_NETWORKSTATUS);
592 if (fprintf(out, "requests-start %s\nn-ns-reqs %s\nn-v2-ns-reqs %s\n",
593 since,
594 data_v3 ? data_v3 : "", data_v2 ? data_v2 : "") < 0)
595 goto done;
596 if (!router_get_my_share_of_directory_requests(&v2_share, &v3_share)) {
597 if (fprintf(out, "v2-ns-share %0.2lf%%\n", v2_share*100) < 0)
598 goto done;
599 if (fprintf(out, "v3-ns-share %0.2lf%%\n", v3_share*100) < 0)
600 goto done;
603 finish_writing_to_file(open_file);
604 open_file = NULL;
605 done:
606 if (open_file)
607 abort_writing_to_file(open_file);
608 tor_free(filename);
609 tor_free(data_v2);
610 tor_free(data_v3);
611 #endif
614 /** Helper used to implement GETINFO ip-to-country/... controller command. */
616 getinfo_helper_geoip(control_connection_t *control_conn,
617 const char *question, char **answer)
619 (void)control_conn;
620 if (geoip_is_loaded() && !strcmpstart(question, "ip-to-country/")) {
621 int c;
622 uint32_t ip;
623 struct in_addr in;
624 question += strlen("ip-to-country/");
625 if (tor_inet_aton(question, &in) != 0) {
626 ip = ntohl(in.s_addr);
627 c = geoip_get_country_by_ip(ip);
628 *answer = tor_strdup(geoip_get_country_name(c));
631 return 0;
634 /** Release all storage held by the GeoIP database. */
635 static void
636 clear_geoip_db(void)
638 if (geoip_countries) {
639 SMARTLIST_FOREACH(geoip_countries, geoip_country_t *, c, tor_free(c));
640 smartlist_free(geoip_countries);
642 if (country_idxplus1_by_lc_code)
643 strmap_free(country_idxplus1_by_lc_code, NULL);
644 if (geoip_entries) {
645 SMARTLIST_FOREACH(geoip_entries, geoip_entry_t *, ent, tor_free(ent));
646 smartlist_free(geoip_entries);
648 geoip_countries = NULL;
649 country_idxplus1_by_lc_code = NULL;
650 geoip_entries = NULL;
653 /** Release all storage held in this file. */
654 void
655 geoip_free_all(void)
657 clientmap_entry_t **ent, **next, *this;
658 for (ent = HT_START(clientmap, &client_history); ent != NULL; ent = next) {
659 this = *ent;
660 next = HT_NEXT_RMV(clientmap, &client_history, ent);
661 tor_free(this);
663 HT_CLEAR(clientmap, &client_history);
665 clear_geoip_db();