1 /* Copyright (c) 2007-2010, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
6 * \brief Functions related to maintaining an IP-to-country database;
7 * to summarizing client connections by country to entry guards, bridges,
8 * and directory servers; and for statistics on answering network status
19 #include "routerlist.h"
21 static void clear_geoip_db(void);
22 static void init_geoip_countries(void);
24 /** An entry from the GeoIP file: maps an IP range to a country. */
25 typedef struct geoip_entry_t
{
26 uint32_t ip_low
; /**< The lowest IP in the range, in host order */
27 uint32_t ip_high
; /**< The highest IP in the range, in host order */
28 intptr_t country
; /**< An index into geoip_countries */
31 /** A per-country record for GeoIP request history. */
32 typedef struct geoip_country_t
{
34 uint32_t n_v2_ns_requests
;
35 uint32_t n_v3_ns_requests
;
38 /** A list of geoip_country_t */
39 static smartlist_t
*geoip_countries
= NULL
;
40 /** A map from lowercased country codes to their position in geoip_countries.
41 * The index is encoded in the pointer, and 1 is added so that NULL can mean
43 static strmap_t
*country_idxplus1_by_lc_code
= NULL
;
44 /** A list of all known geoip_entry_t, sorted by ip_low. */
45 static smartlist_t
*geoip_entries
= NULL
;
47 /** Return the index of the <b>country</b>'s entry in the GeoIP DB
48 * if it is a valid 2-letter country code, otherwise return -1.
51 geoip_get_country(const char *country
)
56 _idxplus1
= strmap_get_lc(country_idxplus1_by_lc_code
, country
);
60 idx
= ((uintptr_t)_idxplus1
)-1;
61 return (country_t
)idx
;
64 /** Add an entry to the GeoIP table, mapping all IPs between <b>low</b> and
65 * <b>high</b>, inclusive, to the 2-letter country code <b>country</b>.
68 geoip_add_entry(uint32_t low
, uint32_t high
, const char *country
)
77 _idxplus1
= strmap_get_lc(country_idxplus1_by_lc_code
, country
);
80 geoip_country_t
*c
= tor_malloc_zero(sizeof(geoip_country_t
));
81 strlcpy(c
->countrycode
, country
, sizeof(c
->countrycode
));
82 tor_strlower(c
->countrycode
);
83 smartlist_add(geoip_countries
, c
);
84 idx
= smartlist_len(geoip_countries
) - 1;
85 strmap_set_lc(country_idxplus1_by_lc_code
, country
, (void*)(idx
+1));
87 idx
= ((uintptr_t)_idxplus1
)-1;
90 geoip_country_t
*c
= smartlist_get(geoip_countries
, idx
);
91 tor_assert(!strcasecmp(c
->countrycode
, country
));
93 ent
= tor_malloc_zero(sizeof(geoip_entry_t
));
97 smartlist_add(geoip_entries
, ent
);
100 /** Add an entry to the GeoIP table, parsing it from <b>line</b>. The
101 * format is as for geoip_load_file(). */
103 geoip_parse_entry(const char *line
)
105 unsigned int low
, high
;
107 if (!geoip_countries
)
108 init_geoip_countries();
110 geoip_entries
= smartlist_create();
112 while (TOR_ISSPACE(*line
))
116 if (sscanf(line
,"%u,%u,%2s", &low
, &high
, b
) == 3) {
117 geoip_add_entry(low
, high
, b
);
119 } else if (sscanf(line
,"\"%u\",\"%u\",\"%2s\",", &low
, &high
, b
) == 3) {
120 geoip_add_entry(low
, high
, b
);
123 log_warn(LD_GENERAL
, "Unable to parse line from GEOIP file: %s",
129 /** Sorting helper: return -1, 1, or 0 based on comparison of two
132 _geoip_compare_entries(const void **_a
, const void **_b
)
134 const geoip_entry_t
*a
= *_a
, *b
= *_b
;
135 if (a
->ip_low
< b
->ip_low
)
137 else if (a
->ip_low
> b
->ip_low
)
143 /** bsearch helper: return -1, 1, or 0 based on comparison of an IP (a pointer
144 * to a uint32_t in host order) to a geoip_entry_t */
146 _geoip_compare_key_to_entry(const void *_key
, const void **_member
)
148 /* No alignment issue here, since _key really is a pointer to uint32_t */
149 const uint32_t addr
= *(uint32_t *)_key
;
150 const geoip_entry_t
*entry
= *_member
;
151 if (addr
< entry
->ip_low
)
153 else if (addr
> entry
->ip_high
)
159 /** Return 1 if we should collect geoip stats on bridge users, and
160 * include them in our extrainfo descriptor. Else return 0. */
162 should_record_bridge_info(or_options_t
*options
)
164 return options
->BridgeRelay
&& options
->BridgeRecordUsageByCountry
;
167 /** Set up a new list of geoip countries with no countries (yet) set in it,
168 * except for the unknown country.
171 init_geoip_countries(void)
173 geoip_country_t
*geoip_unresolved
;
174 geoip_countries
= smartlist_create();
175 /* Add a geoip_country_t for requests that could not be resolved to a
176 * country as first element (index 0) to geoip_countries. */
177 geoip_unresolved
= tor_malloc_zero(sizeof(geoip_country_t
));
178 strlcpy(geoip_unresolved
->countrycode
, "??",
179 sizeof(geoip_unresolved
->countrycode
));
180 smartlist_add(geoip_countries
, geoip_unresolved
);
181 country_idxplus1_by_lc_code
= strmap_new();
182 strmap_set_lc(country_idxplus1_by_lc_code
, "??", (void*)(1));
185 /** Clear the GeoIP database and reload it from the file
186 * <b>filename</b>. Return 0 on success, -1 on failure.
188 * Recognized line formats are:
189 * INTIPLOW,INTIPHIGH,CC
191 * "INTIPLOW","INTIPHIGH","CC","CC3","COUNTRY NAME"
192 * where INTIPLOW and INTIPHIGH are IPv4 addresses encoded as 4-byte unsigned
193 * integers, and CC is a country code.
195 * It also recognizes, and skips over, blank lines and lines that start
196 * with '#' (comments).
199 geoip_load_file(const char *filename
, or_options_t
*options
)
202 const char *msg
= "";
203 int severity
= options_need_geoip_info(options
, &msg
) ? LOG_WARN
: LOG_INFO
;
205 if (!(f
= fopen(filename
, "r"))) {
206 log_fn(severity
, LD_GENERAL
, "Failed to open GEOIP file %s. %s",
210 if (!geoip_countries
)
211 init_geoip_countries();
213 SMARTLIST_FOREACH(geoip_entries
, geoip_entry_t
*, e
, tor_free(e
));
214 smartlist_free(geoip_entries
);
216 geoip_entries
= smartlist_create();
217 log_notice(LD_GENERAL
, "Parsing GEOIP file.");
220 if (fgets(buf
, (int)sizeof(buf
), f
) == NULL
)
222 /* FFFF track full country name. */
223 geoip_parse_entry(buf
);
225 /*XXXX abort and return -1 if no entries/illformed?*/
228 smartlist_sort(geoip_entries
, _geoip_compare_entries
);
230 /* Okay, now we need to maybe change our mind about what is in which
232 refresh_all_country_info();
237 /** Given an IP address in host order, return a number representing the
238 * country to which that address belongs, -1 for "No geoip information
239 * available", or 0 for the 'unknown country'. The return value will always
240 * be less than geoip_get_n_countries(). To decode it, call
241 * geoip_get_country_name().
244 geoip_get_country_by_ip(uint32_t ipaddr
)
249 ent
= smartlist_bsearch(geoip_entries
, &ipaddr
, _geoip_compare_key_to_entry
);
250 return ent
? (int)ent
->country
: 0;
253 /** Return the number of countries recognized by the GeoIP database. */
255 geoip_get_n_countries(void)
257 if (!geoip_countries
)
258 init_geoip_countries();
259 return (int) smartlist_len(geoip_countries
);
262 /** Return the two-letter country code associated with the number <b>num</b>,
263 * or "??" for an unknown value. */
265 geoip_get_country_name(country_t num
)
267 if (geoip_countries
&& num
>= 0 && num
< smartlist_len(geoip_countries
)) {
268 geoip_country_t
*c
= smartlist_get(geoip_countries
, num
);
269 return c
->countrycode
;
274 /** Return true iff we have loaded a GeoIP database.*/
276 geoip_is_loaded(void)
278 return geoip_countries
!= NULL
&& geoip_entries
!= NULL
;
281 /** Entry in a map from IP address to the last time we've seen an incoming
282 * connection from that IP address. Used by bridges only, to track which
283 * countries have them blocked. */
284 typedef struct clientmap_entry_t
{
285 HT_ENTRY(clientmap_entry_t
) node
;
287 unsigned int last_seen_in_minutes
:30;
288 unsigned int action
:2;
291 #define ACTION_MASK 3
293 /** Map from client IP address to last time seen. */
294 static HT_HEAD(clientmap
, clientmap_entry_t
) client_history
=
297 /** Hashtable helper: compute a hash of a clientmap_entry_t. */
298 static INLINE
unsigned
299 clientmap_entry_hash(const clientmap_entry_t
*a
)
301 return ht_improve_hash((unsigned) a
->ipaddr
);
303 /** Hashtable helper: compare two clientmap_entry_t values for equality. */
305 clientmap_entries_eq(const clientmap_entry_t
*a
, const clientmap_entry_t
*b
)
307 return a
->ipaddr
== b
->ipaddr
&& a
->action
== b
->action
;
310 HT_PROTOTYPE(clientmap
, clientmap_entry_t
, node
, clientmap_entry_hash
,
311 clientmap_entries_eq
);
312 HT_GENERATE(clientmap
, clientmap_entry_t
, node
, clientmap_entry_hash
,
313 clientmap_entries_eq
, 0.6, malloc
, realloc
, free
);
315 /** Clear history of connecting clients used by entry and bridge stats. */
317 client_history_clear(void)
319 clientmap_entry_t
**ent
, **next
, *this;
320 for (ent
= HT_START(clientmap
, &client_history
); ent
!= NULL
;
322 if ((*ent
)->action
== GEOIP_CLIENT_CONNECT
) {
324 next
= HT_NEXT_RMV(clientmap
, &client_history
, ent
);
327 next
= HT_NEXT(clientmap
, &client_history
, ent
);
332 /** How often do we update our estimate which share of v2 and v3 directory
333 * requests is sent to us? We could as well trigger updates of shares from
334 * network status updates, but that means adding a lot of calls into code
335 * that is independent from geoip stats (and keeping them up-to-date). We
336 * are perfectly fine with an approximation of 15-minute granularity. */
337 #define REQUEST_SHARE_INTERVAL (15 * 60)
339 /** When did we last determine which share of v2 and v3 directory requests
341 static time_t last_time_determined_shares
= 0;
343 /** Sum of products of v2 shares times the number of seconds for which we
344 * consider these shares as valid. */
345 static double v2_share_times_seconds
;
347 /** Sum of products of v3 shares times the number of seconds for which we
348 * consider these shares as valid. */
349 static double v3_share_times_seconds
;
351 /** Number of seconds we are determining v2 and v3 shares. */
352 static int share_seconds
;
354 /** Try to determine which fraction of v2 and v3 directory requests aimed at
355 * caches will be sent to us at time <b>now</b> and store that value in
356 * order to take a mean value later on. */
358 geoip_determine_shares(time_t now
)
360 double v2_share
= 0.0, v3_share
= 0.0;
361 if (router_get_my_share_of_directory_requests(&v2_share
, &v3_share
) < 0)
363 if (last_time_determined_shares
) {
364 v2_share_times_seconds
+= v2_share
*
365 ((double) (now
- last_time_determined_shares
));
366 v3_share_times_seconds
+= v3_share
*
367 ((double) (now
- last_time_determined_shares
));
368 share_seconds
+= (int)(now
- last_time_determined_shares
);
370 last_time_determined_shares
= now
;
373 /** Calculate which fraction of v2 and v3 directory requests aimed at caches
374 * have been sent to us since the last call of this function up to time
375 * <b>now</b>. Set *<b>v2_share_out</b> and *<b>v3_share_out</b> to the
376 * fractions of v2 and v3 protocol shares we expect to have seen. Reset
377 * counters afterwards. Return 0 on success, -1 on failure (e.g. when zero
378 * seconds have passed since the last call).*/
380 geoip_get_mean_shares(time_t now
, double *v2_share_out
,
381 double *v3_share_out
)
383 geoip_determine_shares(now
);
386 *v2_share_out
= v2_share_times_seconds
/ ((double) share_seconds
);
387 *v3_share_out
= v3_share_times_seconds
/ ((double) share_seconds
);
388 v2_share_times_seconds
= v3_share_times_seconds
= 0.0;
393 /** Note that we've seen a client connect from the IP <b>addr</b> (host order)
394 * at time <b>now</b>. Ignored by all but bridges and directories if
395 * configured accordingly. */
397 geoip_note_client_seen(geoip_client_action_t action
,
398 uint32_t addr
, time_t now
)
400 or_options_t
*options
= get_options();
401 clientmap_entry_t lookup
, *ent
;
402 if (action
== GEOIP_CLIENT_CONNECT
) {
403 /* Only remember statistics as entry guard or as bridge. */
404 if (!options
->EntryStatistics
&&
405 (!(options
->BridgeRelay
&& options
->BridgeRecordUsageByCountry
)))
408 if (options
->BridgeRelay
|| options
->BridgeAuthoritativeDir
||
409 !options
->DirReqStatistics
)
413 lookup
.ipaddr
= addr
;
414 lookup
.action
= (int)action
;
415 ent
= HT_FIND(clientmap
, &client_history
, &lookup
);
417 ent
->last_seen_in_minutes
= now
/ 60;
419 ent
= tor_malloc_zero(sizeof(clientmap_entry_t
));
421 ent
->last_seen_in_minutes
= now
/ 60;
422 ent
->action
= (int)action
;
423 HT_INSERT(clientmap
, &client_history
, ent
);
426 if (action
== GEOIP_CLIENT_NETWORKSTATUS
||
427 action
== GEOIP_CLIENT_NETWORKSTATUS_V2
) {
428 int country_idx
= geoip_get_country_by_ip(addr
);
430 country_idx
= 0; /** unresolved requests are stored at index 0. */
431 if (country_idx
>= 0 && country_idx
< smartlist_len(geoip_countries
)) {
432 geoip_country_t
*country
= smartlist_get(geoip_countries
, country_idx
);
433 if (action
== GEOIP_CLIENT_NETWORKSTATUS
)
434 ++country
->n_v3_ns_requests
;
436 ++country
->n_v2_ns_requests
;
439 /* Periodically determine share of requests that we should see */
440 if (last_time_determined_shares
+ REQUEST_SHARE_INTERVAL
< now
)
441 geoip_determine_shares(now
);
445 /** HT_FOREACH helper: remove a clientmap_entry_t from the hashtable if it's
446 * older than a certain time. */
448 _remove_old_client_helper(struct clientmap_entry_t
*ent
, void *_cutoff
)
450 time_t cutoff
= *(time_t*)_cutoff
/ 60;
451 if (ent
->last_seen_in_minutes
< cutoff
) {
459 /** Forget about all clients that haven't connected since <b>cutoff</b>. */
461 geoip_remove_old_clients(time_t cutoff
)
463 clientmap_HT_FOREACH_FN(&client_history
,
464 _remove_old_client_helper
,
468 /** How many responses are we giving to clients requesting v2 network
470 static uint32_t ns_v2_responses
[GEOIP_NS_RESPONSE_NUM
];
472 /** How many responses are we giving to clients requesting v3 network
474 static uint32_t ns_v3_responses
[GEOIP_NS_RESPONSE_NUM
];
476 /** Note that we've rejected a client's request for a v2 or v3 network
477 * status, encoded in <b>action</b> for reason <b>reason</b> at time
480 geoip_note_ns_response(geoip_client_action_t action
,
481 geoip_ns_response_t response
)
483 static int arrays_initialized
= 0;
484 if (!get_options()->DirReqStatistics
)
486 if (!arrays_initialized
) {
487 memset(ns_v2_responses
, 0, sizeof(ns_v2_responses
));
488 memset(ns_v3_responses
, 0, sizeof(ns_v3_responses
));
489 arrays_initialized
= 1;
491 tor_assert(action
== GEOIP_CLIENT_NETWORKSTATUS
||
492 action
== GEOIP_CLIENT_NETWORKSTATUS_V2
);
493 tor_assert(response
< GEOIP_NS_RESPONSE_NUM
);
494 if (action
== GEOIP_CLIENT_NETWORKSTATUS
)
495 ns_v3_responses
[response
]++;
497 ns_v2_responses
[response
]++;
500 /** Do not mention any country from which fewer than this number of IPs have
501 * connected. This conceivably avoids reporting information that could
502 * deanonymize users, though analysis is lacking. */
503 #define MIN_IPS_TO_NOTE_COUNTRY 1
504 /** Do not report any geoip data at all if we have fewer than this number of
505 * IPs to report about. */
506 #define MIN_IPS_TO_NOTE_ANYTHING 1
507 /** When reporting geoip data about countries, round up to the nearest
508 * multiple of this value. */
509 #define IP_GRANULARITY 8
511 /** Helper type: used to sort per-country totals by value. */
512 typedef struct c_hist_t
{
513 char country
[3]; /**< Two-letter country code. */
514 unsigned total
; /**< Total IP addresses seen in this country. */
517 /** Sorting helper: return -1, 1, or 0 based on comparison of two
518 * geoip_entry_t. Sort in descending order of total, and then by country
521 _c_hist_compare(const void **_a
, const void **_b
)
523 const c_hist_t
*a
= *_a
, *b
= *_b
;
524 if (a
->total
> b
->total
)
526 else if (a
->total
< b
->total
)
529 return strcmp(a
->country
, b
->country
);
532 /** When there are incomplete directory requests at the end of a 24-hour
533 * period, consider those requests running for longer than this timeout as
534 * failed, the others as still running. */
535 #define DIRREQ_TIMEOUT (10*60)
537 /** Entry in a map from either conn->global_identifier for direct requests
538 * or a unique circuit identifier for tunneled requests to request time,
539 * response size, and completion time of a network status request. Used to
540 * measure download times of requests to derive average client
542 typedef struct dirreq_map_entry_t
{
543 HT_ENTRY(dirreq_map_entry_t
) node
;
544 /** Unique identifier for this network status request; this is either the
545 * conn->global_identifier of the dir conn (direct request) or a new
546 * locally unique identifier of a circuit (tunneled request). This ID is
547 * only unique among other direct or tunneled requests, respectively. */
549 unsigned int state
:3; /**< State of this directory request. */
550 unsigned int type
:1; /**< Is this a direct or a tunneled request? */
551 unsigned int completed
:1; /**< Is this request complete? */
552 unsigned int action
:2; /**< Is this a v2 or v3 request? */
553 /** When did we receive the request and started sending the response? */
554 struct timeval request_time
;
555 size_t response_size
; /**< What is the size of the response in bytes? */
556 struct timeval completion_time
; /**< When did the request succeed? */
557 } dirreq_map_entry_t
;
559 /** Map of all directory requests asking for v2 or v3 network statuses in
560 * the current geoip-stats interval. Values are
561 * of type *<b>dirreq_map_entry_t</b>. */
562 static HT_HEAD(dirreqmap
, dirreq_map_entry_t
) dirreq_map
=
566 dirreq_map_ent_eq(const dirreq_map_entry_t
*a
,
567 const dirreq_map_entry_t
*b
)
569 return a
->dirreq_id
== b
->dirreq_id
&& a
->type
== b
->type
;
573 dirreq_map_ent_hash(const dirreq_map_entry_t
*entry
)
575 unsigned u
= (unsigned) entry
->dirreq_id
;
576 u
+= entry
->type
<< 20;
580 HT_PROTOTYPE(dirreqmap
, dirreq_map_entry_t
, node
, dirreq_map_ent_hash
,
582 HT_GENERATE(dirreqmap
, dirreq_map_entry_t
, node
, dirreq_map_ent_hash
,
583 dirreq_map_ent_eq
, 0.6, malloc
, realloc
, free
);
585 /** Helper: Put <b>entry</b> into map of directory requests using
586 * <b>type</b> and <b>dirreq_id</b> as key parts. If there is
587 * already an entry for that key, print out a BUG warning and return. */
589 _dirreq_map_put(dirreq_map_entry_t
*entry
, dirreq_type_t type
,
592 dirreq_map_entry_t
*old_ent
;
593 tor_assert(entry
->type
== type
);
594 tor_assert(entry
->dirreq_id
== dirreq_id
);
596 /* XXXX022 once we're sure the bug case never happens, we can switch
598 old_ent
= HT_REPLACE(dirreqmap
, &dirreq_map
, entry
);
599 if (old_ent
&& old_ent
!= entry
) {
600 log_warn(LD_BUG
, "Error when putting directory request into local "
601 "map. There was already an entry for the same identifier.");
606 /** Helper: Look up and return an entry in the map of directory requests
607 * using <b>type</b> and <b>dirreq_id</b> as key parts. If there
608 * is no such entry, return NULL. */
609 static dirreq_map_entry_t
*
610 _dirreq_map_get(dirreq_type_t type
, uint64_t dirreq_id
)
612 dirreq_map_entry_t lookup
;
614 lookup
.dirreq_id
= dirreq_id
;
615 return HT_FIND(dirreqmap
, &dirreq_map
, &lookup
);
618 /** Note that an either direct or tunneled (see <b>type</b>) directory
619 * request for a network status with unique ID <b>dirreq_id</b> of size
620 * <b>response_size</b> and action <b>action</b> (either v2 or v3) has
623 geoip_start_dirreq(uint64_t dirreq_id
, size_t response_size
,
624 geoip_client_action_t action
, dirreq_type_t type
)
626 dirreq_map_entry_t
*ent
;
627 if (!get_options()->DirReqStatistics
)
629 ent
= tor_malloc_zero(sizeof(dirreq_map_entry_t
));
630 ent
->dirreq_id
= dirreq_id
;
631 tor_gettimeofday(&ent
->request_time
);
632 ent
->response_size
= response_size
;
633 ent
->action
= action
;
635 _dirreq_map_put(ent
, type
, dirreq_id
);
638 /** Change the state of the either direct or tunneled (see <b>type</b>)
639 * directory request with <b>dirreq_id</b> to <b>new_state</b> and
640 * possibly mark it as completed. If no entry can be found for the given
641 * key parts (e.g., if this is a directory request that we are not
642 * measuring, or one that was started in the previous measurement period),
643 * or if the state cannot be advanced to <b>new_state</b>, do nothing. */
645 geoip_change_dirreq_state(uint64_t dirreq_id
, dirreq_type_t type
,
646 dirreq_state_t new_state
)
648 dirreq_map_entry_t
*ent
;
649 if (!get_options()->DirReqStatistics
)
651 ent
= _dirreq_map_get(type
, dirreq_id
);
654 if (new_state
== DIRREQ_IS_FOR_NETWORK_STATUS
)
656 if (new_state
- 1 != ent
->state
)
658 ent
->state
= new_state
;
659 if ((type
== DIRREQ_DIRECT
&&
660 new_state
== DIRREQ_FLUSHING_DIR_CONN_FINISHED
) ||
661 (type
== DIRREQ_TUNNELED
&&
662 new_state
== DIRREQ_OR_CONN_BUFFER_FLUSHED
)) {
663 tor_gettimeofday(&ent
->completion_time
);
668 /** Return a newly allocated comma-separated string containing statistics
669 * on network status downloads. The string contains the number of completed
670 * requests, timeouts, and still running requests as well as the download
671 * times by deciles and quartiles. Return NULL if we have not observed
672 * requests for long enough. */
674 geoip_get_dirreq_history(geoip_client_action_t action
,
678 smartlist_t
*dirreq_completed
= NULL
;
679 uint32_t complete
= 0, timeouts
= 0, running
= 0;
680 int bufsize
= 1024, written
;
681 dirreq_map_entry_t
**ptr
, **next
, *ent
;
684 tor_gettimeofday(&now
);
685 if (action
!= GEOIP_CLIENT_NETWORKSTATUS
&&
686 action
!= GEOIP_CLIENT_NETWORKSTATUS_V2
)
688 dirreq_completed
= smartlist_create();
689 for (ptr
= HT_START(dirreqmap
, &dirreq_map
); ptr
; ptr
= next
) {
691 if (ent
->action
!= action
|| ent
->type
!= type
) {
692 next
= HT_NEXT(dirreqmap
, &dirreq_map
, ptr
);
695 if (ent
->completed
) {
696 smartlist_add(dirreq_completed
, ent
);
698 next
= HT_NEXT_RMV(dirreqmap
, &dirreq_map
, ptr
);
700 if (tv_mdiff(&ent
->request_time
, &now
) / 1000 > DIRREQ_TIMEOUT
)
704 next
= HT_NEXT_RMV(dirreqmap
, &dirreq_map
, ptr
);
709 #define DIR_REQ_GRANULARITY 4
710 complete
= round_uint32_to_next_multiple_of(complete
,
711 DIR_REQ_GRANULARITY
);
712 timeouts
= round_uint32_to_next_multiple_of(timeouts
,
713 DIR_REQ_GRANULARITY
);
714 running
= round_uint32_to_next_multiple_of(running
,
715 DIR_REQ_GRANULARITY
);
716 result
= tor_malloc_zero(bufsize
);
717 written
= tor_snprintf(result
, bufsize
, "complete=%u,timeout=%u,"
718 "running=%u", complete
, timeouts
, running
);
724 #define MIN_DIR_REQ_RESPONSES 16
725 if (complete
>= MIN_DIR_REQ_RESPONSES
) {
727 /* We may have rounded 'completed' up. Here we want to use the
729 complete
= smartlist_len(dirreq_completed
);
730 dltimes
= tor_malloc_zero(sizeof(uint32_t) * complete
);
731 SMARTLIST_FOREACH_BEGIN(dirreq_completed
, dirreq_map_entry_t
*, ent
) {
732 uint32_t bytes_per_second
;
733 uint32_t time_diff
= (uint32_t) tv_mdiff(&ent
->request_time
,
734 &ent
->completion_time
);
736 time_diff
= 1; /* Avoid DIV/0; "instant" answers are impossible
737 * by law of nature or something, but a milisecond
738 * is a bit greater than "instantly" */
739 bytes_per_second
= (uint32_t)(1000 * ent
->response_size
/ time_diff
);
740 dltimes
[ent_sl_idx
] = bytes_per_second
;
741 } SMARTLIST_FOREACH_END(ent
);
742 median_uint32(dltimes
, complete
); /* sorts as a side effect. */
743 written
= tor_snprintf(result
+ written
, bufsize
- written
,
744 ",min=%u,d1=%u,d2=%u,q1=%u,d3=%u,d4=%u,md=%u,"
745 "d6=%u,d7=%u,q3=%u,d8=%u,d9=%u,max=%u",
747 dltimes
[1*complete
/10-1],
748 dltimes
[2*complete
/10-1],
749 dltimes
[1*complete
/4-1],
750 dltimes
[3*complete
/10-1],
751 dltimes
[4*complete
/10-1],
752 dltimes
[5*complete
/10-1],
753 dltimes
[6*complete
/10-1],
754 dltimes
[7*complete
/10-1],
755 dltimes
[3*complete
/4-1],
756 dltimes
[8*complete
/10-1],
757 dltimes
[9*complete
/10-1],
758 dltimes
[complete
-1]);
764 SMARTLIST_FOREACH(dirreq_completed
, dirreq_map_entry_t
*, ent
,
766 smartlist_free(dirreq_completed
);
770 /** Return a newly allocated comma-separated string containing entries for
771 * all the countries from which we've seen enough clients connect as a
772 * bridge, directory server, or entry guard. The entry format is cc=num
773 * where num is the number of IPs we've seen connecting from that country,
774 * and cc is a lowercased country code. Returns NULL if we don't want
775 * to export geoip data yet. */
777 geoip_get_client_history(geoip_client_action_t action
)
780 unsigned granularity
= IP_GRANULARITY
;
781 smartlist_t
*chunks
= NULL
;
782 smartlist_t
*entries
= NULL
;
783 int n_countries
= geoip_get_n_countries();
785 clientmap_entry_t
**ent
;
786 unsigned *counts
= NULL
;
789 if (!geoip_is_loaded())
792 counts
= tor_malloc_zero(sizeof(unsigned)*n_countries
);
793 HT_FOREACH(ent
, clientmap
, &client_history
) {
795 if ((*ent
)->action
!= (int)action
)
797 country
= geoip_get_country_by_ip((*ent
)->ipaddr
);
799 country
= 0; /** unresolved requests are stored at index 0. */
800 tor_assert(0 <= country
&& country
< n_countries
);
804 /* Don't record anything if we haven't seen enough IPs. */
805 if (total
< MIN_IPS_TO_NOTE_ANYTHING
)
807 /* Make a list of c_hist_t */
808 entries
= smartlist_create();
809 for (i
= 0; i
< n_countries
; ++i
) {
810 unsigned c
= counts
[i
];
811 const char *countrycode
;
813 /* Only report a country if it has a minimum number of IPs. */
814 if (c
>= MIN_IPS_TO_NOTE_COUNTRY
) {
815 c
= round_to_next_multiple_of(c
, granularity
);
816 countrycode
= geoip_get_country_name(i
);
817 ent
= tor_malloc(sizeof(c_hist_t
));
818 strlcpy(ent
->country
, countrycode
, sizeof(ent
->country
));
820 smartlist_add(entries
, ent
);
823 /* Sort entries. Note that we must do this _AFTER_ rounding, or else
824 * the sort order could leak info. */
825 smartlist_sort(entries
, _c_hist_compare
);
827 /* Build the result. */
828 chunks
= smartlist_create();
829 SMARTLIST_FOREACH(entries
, c_hist_t
*, ch
, {
831 tor_asprintf(&buf
, "%s=%u", ch
->country
, ch
->total
);
832 smartlist_add(chunks
, buf
);
834 result
= smartlist_join_strings(chunks
, ",", 0, NULL
);
838 SMARTLIST_FOREACH(chunks
, char *, c
, tor_free(c
));
839 smartlist_free(chunks
);
842 SMARTLIST_FOREACH(entries
, c_hist_t
*, c
, tor_free(c
));
843 smartlist_free(entries
);
848 /** Return a newly allocated string holding the per-country request history
849 * for <b>action</b> in a format suitable for an extra-info document, or NULL
852 geoip_get_request_history(geoip_client_action_t action
)
854 smartlist_t
*entries
, *strings
;
856 unsigned granularity
= IP_GRANULARITY
;
858 if (action
!= GEOIP_CLIENT_NETWORKSTATUS
&&
859 action
!= GEOIP_CLIENT_NETWORKSTATUS_V2
)
861 if (!geoip_countries
)
864 entries
= smartlist_create();
865 SMARTLIST_FOREACH(geoip_countries
, geoip_country_t
*, c
, {
868 tot
= (action
== GEOIP_CLIENT_NETWORKSTATUS
) ?
869 c
->n_v3_ns_requests
: c
->n_v2_ns_requests
;
872 ent
= tor_malloc_zero(sizeof(c_hist_t
));
873 strlcpy(ent
->country
, c
->countrycode
, sizeof(ent
->country
));
874 ent
->total
= round_to_next_multiple_of(tot
, granularity
);
875 smartlist_add(entries
, ent
);
877 smartlist_sort(entries
, _c_hist_compare
);
879 strings
= smartlist_create();
880 SMARTLIST_FOREACH(entries
, c_hist_t
*, ent
, {
882 tor_asprintf(&buf
, "%s=%u", ent
->country
, ent
->total
);
883 smartlist_add(strings
, buf
);
885 result
= smartlist_join_strings(strings
, ",", 0, NULL
);
886 SMARTLIST_FOREACH(strings
, char *, cp
, tor_free(cp
));
887 SMARTLIST_FOREACH(entries
, c_hist_t
*, ent
, tor_free(ent
));
888 smartlist_free(strings
);
889 smartlist_free(entries
);
893 /** Start time of directory request stats or 0 if we're not collecting
894 * directory request statistics. */
895 static time_t start_of_dirreq_stats_interval
;
897 /** Initialize directory request stats. */
899 geoip_dirreq_stats_init(time_t now
)
901 start_of_dirreq_stats_interval
= now
;
904 /** Stop collecting directory request stats in a way that we can re-start
905 * doing so in geoip_dirreq_stats_init(). */
907 geoip_dirreq_stats_term(void)
909 SMARTLIST_FOREACH(geoip_countries
, geoip_country_t
*, c
, {
910 c
->n_v2_ns_requests
= c
->n_v3_ns_requests
= 0;
913 clientmap_entry_t
**ent
, **next
, *this;
914 for (ent
= HT_START(clientmap
, &client_history
); ent
!= NULL
;
916 if ((*ent
)->action
== GEOIP_CLIENT_NETWORKSTATUS
||
917 (*ent
)->action
== GEOIP_CLIENT_NETWORKSTATUS_V2
) {
919 next
= HT_NEXT_RMV(clientmap
, &client_history
, ent
);
922 next
= HT_NEXT(clientmap
, &client_history
, ent
);
926 v2_share_times_seconds
= v3_share_times_seconds
= 0.0;
927 last_time_determined_shares
= 0;
929 memset(ns_v2_responses
, 0, sizeof(ns_v2_responses
));
930 memset(ns_v3_responses
, 0, sizeof(ns_v3_responses
));
932 dirreq_map_entry_t
**ent
, **next
, *this;
933 for (ent
= HT_START(dirreqmap
, &dirreq_map
); ent
!= NULL
; ent
= next
) {
935 next
= HT_NEXT_RMV(dirreqmap
, &dirreq_map
, ent
);
939 start_of_dirreq_stats_interval
= 0;
942 /** Write dirreq statistics to $DATADIR/stats/dirreq-stats and return when
943 * we would next want to write. */
945 geoip_dirreq_stats_write(time_t now
)
947 char *statsdir
= NULL
, *filename
= NULL
;
948 char *data_v2
= NULL
, *data_v3
= NULL
;
949 char written
[ISO_TIME_LEN
+1];
950 open_file_t
*open_file
= NULL
;
951 double v2_share
= 0.0, v3_share
= 0.0;
955 if (!start_of_dirreq_stats_interval
)
956 return 0; /* Not initialized. */
957 if (start_of_dirreq_stats_interval
+ WRITE_STATS_INTERVAL
> now
)
958 goto done
; /* Not ready to write. */
960 /* Discard all items in the client history that are too old. */
961 geoip_remove_old_clients(start_of_dirreq_stats_interval
);
963 statsdir
= get_datadir_fname("stats");
964 if (check_private_dir(statsdir
, CPD_CREATE
) < 0)
966 filename
= get_datadir_fname2("stats", "dirreq-stats");
967 data_v2
= geoip_get_client_history(GEOIP_CLIENT_NETWORKSTATUS_V2
);
968 data_v3
= geoip_get_client_history(GEOIP_CLIENT_NETWORKSTATUS
);
969 format_iso_time(written
, now
);
970 out
= start_writing_to_stdio_file(filename
, OPEN_FLAGS_APPEND
,
974 if (fprintf(out
, "dirreq-stats-end %s (%d s)\ndirreq-v3-ips %s\n"
975 "dirreq-v2-ips %s\n", written
,
976 (unsigned) (now
- start_of_dirreq_stats_interval
),
977 data_v3
? data_v3
: "", data_v2
? data_v2
: "") < 0)
982 data_v2
= geoip_get_request_history(GEOIP_CLIENT_NETWORKSTATUS_V2
);
983 data_v3
= geoip_get_request_history(GEOIP_CLIENT_NETWORKSTATUS
);
984 if (fprintf(out
, "dirreq-v3-reqs %s\ndirreq-v2-reqs %s\n",
985 data_v3
? data_v3
: "", data_v2
? data_v2
: "") < 0)
989 SMARTLIST_FOREACH(geoip_countries
, geoip_country_t
*, c
, {
990 c
->n_v2_ns_requests
= c
->n_v3_ns_requests
= 0;
992 #define RESPONSE_GRANULARITY 8
993 for (i
= 0; i
< GEOIP_NS_RESPONSE_NUM
; i
++) {
994 ns_v2_responses
[i
] = round_uint32_to_next_multiple_of(
995 ns_v2_responses
[i
], RESPONSE_GRANULARITY
);
996 ns_v3_responses
[i
] = round_uint32_to_next_multiple_of(
997 ns_v3_responses
[i
], RESPONSE_GRANULARITY
);
999 #undef RESPONSE_GRANULARITY
1000 if (fprintf(out
, "dirreq-v3-resp ok=%u,not-enough-sigs=%u,unavailable=%u,"
1001 "not-found=%u,not-modified=%u,busy=%u\n",
1002 ns_v3_responses
[GEOIP_SUCCESS
],
1003 ns_v3_responses
[GEOIP_REJECT_NOT_ENOUGH_SIGS
],
1004 ns_v3_responses
[GEOIP_REJECT_UNAVAILABLE
],
1005 ns_v3_responses
[GEOIP_REJECT_NOT_FOUND
],
1006 ns_v3_responses
[GEOIP_REJECT_NOT_MODIFIED
],
1007 ns_v3_responses
[GEOIP_REJECT_BUSY
]) < 0)
1009 if (fprintf(out
, "dirreq-v2-resp ok=%u,unavailable=%u,"
1010 "not-found=%u,not-modified=%u,busy=%u\n",
1011 ns_v2_responses
[GEOIP_SUCCESS
],
1012 ns_v2_responses
[GEOIP_REJECT_UNAVAILABLE
],
1013 ns_v2_responses
[GEOIP_REJECT_NOT_FOUND
],
1014 ns_v2_responses
[GEOIP_REJECT_NOT_MODIFIED
],
1015 ns_v2_responses
[GEOIP_REJECT_BUSY
]) < 0)
1017 memset(ns_v2_responses
, 0, sizeof(ns_v2_responses
));
1018 memset(ns_v3_responses
, 0, sizeof(ns_v3_responses
));
1019 if (!geoip_get_mean_shares(now
, &v2_share
, &v3_share
)) {
1020 if (fprintf(out
, "dirreq-v2-share %0.2lf%%\n", v2_share
*100) < 0)
1022 if (fprintf(out
, "dirreq-v3-share %0.2lf%%\n", v3_share
*100) < 0)
1026 data_v2
= geoip_get_dirreq_history(GEOIP_CLIENT_NETWORKSTATUS_V2
,
1028 data_v3
= geoip_get_dirreq_history(GEOIP_CLIENT_NETWORKSTATUS
,
1030 if (fprintf(out
, "dirreq-v3-direct-dl %s\ndirreq-v2-direct-dl %s\n",
1031 data_v3
? data_v3
: "", data_v2
? data_v2
: "") < 0)
1035 data_v2
= geoip_get_dirreq_history(GEOIP_CLIENT_NETWORKSTATUS_V2
,
1037 data_v3
= geoip_get_dirreq_history(GEOIP_CLIENT_NETWORKSTATUS
,
1039 if (fprintf(out
, "dirreq-v3-tunneled-dl %s\ndirreq-v2-tunneled-dl %s\n",
1040 data_v3
? data_v3
: "", data_v2
? data_v2
: "") < 0)
1043 finish_writing_to_file(open_file
);
1046 start_of_dirreq_stats_interval
= now
;
1050 abort_writing_to_file(open_file
);
1055 return start_of_dirreq_stats_interval
+ WRITE_STATS_INTERVAL
;
1058 /** Start time of bridge stats or 0 if we're not collecting bridge
1060 static time_t start_of_bridge_stats_interval
;
1062 /** Initialize bridge stats. */
1064 geoip_bridge_stats_init(time_t now
)
1066 start_of_bridge_stats_interval
= now
;
1069 /** Stop collecting bridge stats in a way that we can re-start doing so in
1070 * geoip_bridge_stats_init(). */
1072 geoip_bridge_stats_term(void)
1074 client_history_clear();
1075 start_of_bridge_stats_interval
= 0;
1078 /** Parse the bridge statistics as they are written to extra-info
1079 * descriptors for being returned to controller clients. Return the
1080 * controller string if successful, or NULL otherwise. */
1082 parse_bridge_stats_controller(const char *stats_str
, time_t now
)
1084 char stats_end_str
[ISO_TIME_LEN
+1], stats_start_str
[ISO_TIME_LEN
+1],
1085 *controller_str
, *eos
, *eol
, *summary
;
1087 const char *BRIDGE_STATS_END
= "bridge-stats-end ";
1088 const char *BRIDGE_IPS
= "bridge-ips ";
1089 const char *BRIDGE_IPS_EMPTY_LINE
= "bridge-ips\n";
1091 time_t stats_end_time
;
1093 tor_assert(stats_str
);
1095 /* Parse timestamp and number of seconds from
1096 "bridge-stats-end YYYY-MM-DD HH:MM:SS (N s)" */
1097 tmp
= find_str_at_start_of_line(stats_str
, BRIDGE_STATS_END
);
1100 tmp
+= strlen(BRIDGE_STATS_END
);
1102 if (strlen(tmp
) < ISO_TIME_LEN
+ 6)
1104 strlcpy(stats_end_str
, tmp
, sizeof(stats_end_str
));
1105 if (parse_iso_time(stats_end_str
, &stats_end_time
) < 0)
1107 if (stats_end_time
< now
- (25*60*60) ||
1108 stats_end_time
> now
+ (1*60*60))
1110 seconds
= (int)strtol(tmp
+ ISO_TIME_LEN
+ 2, &eos
, 10);
1111 if (!eos
|| seconds
< 23*60*60)
1113 format_iso_time(stats_start_str
, stats_end_time
- seconds
);
1115 /* Parse: "bridge-ips CC=N,CC=N,..." */
1116 tmp
= find_str_at_start_of_line(stats_str
, BRIDGE_IPS
);
1118 tmp
+= strlen(BRIDGE_IPS
);
1119 tmp
= eat_whitespace_no_nl(tmp
);
1120 eol
= strchr(tmp
, '\n');
1122 summary
= tor_strndup(tmp
, eol
-tmp
);
1124 summary
= tor_strdup(tmp
);
1126 /* Look if there is an empty "bridge-ips" line */
1127 tmp
= find_str_at_start_of_line(stats_str
, BRIDGE_IPS_EMPTY_LINE
);
1130 summary
= tor_strdup("");
1133 tor_asprintf(&controller_str
,
1134 "TimeStarted=\"%s\" CountrySummary=%s",
1135 stats_start_str
, summary
);
1137 return controller_str
;
1140 /** Most recent bridge statistics formatted to be written to extra-info
1142 static char *bridge_stats_extrainfo
= NULL
;
1144 /** Most recent bridge statistics formatted to be returned to controller
1146 static char *bridge_stats_controller
= NULL
;
1148 /** Write bridge statistics to $DATADIR/stats/bridge-stats and return
1149 * when we should next try to write statistics. */
1151 geoip_bridge_stats_write(time_t now
)
1153 char *statsdir
= NULL
, *filename
= NULL
, *data
= NULL
,
1154 written
[ISO_TIME_LEN
+1], *out
= NULL
, *controller_str
;
1157 /* Check if 24 hours have passed since starting measurements. */
1158 if (now
< start_of_bridge_stats_interval
+ WRITE_STATS_INTERVAL
)
1159 return start_of_bridge_stats_interval
+ WRITE_STATS_INTERVAL
;
1161 /* Discard all items in the client history that are too old. */
1162 geoip_remove_old_clients(start_of_bridge_stats_interval
);
1164 statsdir
= get_datadir_fname("stats");
1165 if (check_private_dir(statsdir
, CPD_CREATE
) < 0)
1167 filename
= get_datadir_fname2("stats", "bridge-stats");
1168 data
= geoip_get_client_history(GEOIP_CLIENT_CONNECT
);
1169 format_iso_time(written
, now
);
1170 len
= strlen("bridge-stats-end (999999 s)\nbridge-ips \n") +
1171 ISO_TIME_LEN
+ (data
? strlen(data
) : 0) + 42;
1172 out
= tor_malloc(len
);
1173 if (tor_snprintf(out
, len
, "bridge-stats-end %s (%u s)\nbridge-ips %s\n",
1174 written
, (unsigned) (now
- start_of_bridge_stats_interval
),
1175 data
? data
: "") < 0)
1177 write_str_to_file(filename
, out
, 0);
1178 controller_str
= parse_bridge_stats_controller(out
, now
);
1179 if (!controller_str
)
1181 start_of_bridge_stats_interval
= now
;
1182 tor_free(bridge_stats_extrainfo
);
1183 tor_free(bridge_stats_controller
);
1184 bridge_stats_extrainfo
= out
;
1186 bridge_stats_controller
= controller_str
;
1187 control_event_clients_seen(controller_str
);
1193 return start_of_bridge_stats_interval
+
1194 WRITE_STATS_INTERVAL
;
1197 /** Try to load the most recent bridge statistics from disk, unless we
1198 * have finished a measurement interval lately. */
1200 load_bridge_stats(time_t now
)
1202 char *statsdir
, *fname
=NULL
, *contents
, *controller_str
;
1203 if (bridge_stats_extrainfo
)
1205 statsdir
= get_datadir_fname("stats");
1206 if (check_private_dir(statsdir
, CPD_CREATE
) < 0)
1208 fname
= get_datadir_fname2("stats", "bridge-stats");
1209 contents
= read_file_to_str(fname
, RFTS_IGNORE_MISSING
, NULL
);
1211 controller_str
= parse_bridge_stats_controller(contents
, now
);
1212 if (controller_str
) {
1213 bridge_stats_extrainfo
= contents
;
1214 bridge_stats_controller
= controller_str
;
1224 /** Return most recent bridge statistics for inclusion in extra-info
1225 * descriptors, or NULL if we don't have recent bridge statistics. */
1227 geoip_get_bridge_stats_extrainfo(time_t now
)
1229 load_bridge_stats(now
);
1230 return bridge_stats_extrainfo
;
1233 /** Return most recent bridge statistics to be returned to controller
1234 * clients, or NULL if we don't have recent bridge statistics. */
1236 geoip_get_bridge_stats_controller(time_t now
)
1238 load_bridge_stats(now
);
1239 return bridge_stats_controller
;
1242 /** Start time of entry stats or 0 if we're not collecting entry
1244 static time_t start_of_entry_stats_interval
;
1246 /** Initialize entry stats. */
1248 geoip_entry_stats_init(time_t now
)
1250 start_of_entry_stats_interval
= now
;
1253 /** Stop collecting entry stats in a way that we can re-start doing so in
1254 * geoip_entry_stats_init(). */
1256 geoip_entry_stats_term(void)
1258 client_history_clear();
1259 start_of_entry_stats_interval
= 0;
1262 /** Write entry statistics to $DATADIR/stats/entry-stats and return time
1263 * when we would next want to write. */
1265 geoip_entry_stats_write(time_t now
)
1267 char *statsdir
= NULL
, *filename
= NULL
;
1269 char written
[ISO_TIME_LEN
+1];
1270 open_file_t
*open_file
= NULL
;
1273 if (!start_of_entry_stats_interval
)
1274 return 0; /* Not initialized. */
1275 if (start_of_entry_stats_interval
+ WRITE_STATS_INTERVAL
> now
)
1276 goto done
; /* Not ready to write. */
1278 /* Discard all items in the client history that are too old. */
1279 geoip_remove_old_clients(start_of_entry_stats_interval
);
1281 statsdir
= get_datadir_fname("stats");
1282 if (check_private_dir(statsdir
, CPD_CREATE
) < 0)
1284 filename
= get_datadir_fname2("stats", "entry-stats");
1285 data
= geoip_get_client_history(GEOIP_CLIENT_CONNECT
);
1286 format_iso_time(written
, now
);
1287 out
= start_writing_to_stdio_file(filename
, OPEN_FLAGS_APPEND
,
1291 if (fprintf(out
, "entry-stats-end %s (%u s)\nentry-ips %s\n",
1292 written
, (unsigned) (now
- start_of_entry_stats_interval
),
1293 data
? data
: "") < 0)
1296 start_of_entry_stats_interval
= now
;
1298 finish_writing_to_file(open_file
);
1302 abort_writing_to_file(open_file
);
1306 return start_of_entry_stats_interval
+ WRITE_STATS_INTERVAL
;
1309 /** Helper used to implement GETINFO ip-to-country/... controller command. */
1311 getinfo_helper_geoip(control_connection_t
*control_conn
,
1312 const char *question
, char **answer
,
1313 const char **errmsg
)
1316 if (!geoip_is_loaded()) {
1317 *errmsg
= "GeoIP data not loaded";
1320 if (!strcmpstart(question
, "ip-to-country/")) {
1324 question
+= strlen("ip-to-country/");
1325 if (tor_inet_aton(question
, &in
) != 0) {
1326 ip
= ntohl(in
.s_addr
);
1327 c
= geoip_get_country_by_ip(ip
);
1328 *answer
= tor_strdup(geoip_get_country_name(c
));
1334 /** Release all storage held by the GeoIP database. */
1336 clear_geoip_db(void)
1338 if (geoip_countries
) {
1339 SMARTLIST_FOREACH(geoip_countries
, geoip_country_t
*, c
, tor_free(c
));
1340 smartlist_free(geoip_countries
);
1343 strmap_free(country_idxplus1_by_lc_code
, NULL
);
1344 if (geoip_entries
) {
1345 SMARTLIST_FOREACH(geoip_entries
, geoip_entry_t
*, ent
, tor_free(ent
));
1346 smartlist_free(geoip_entries
);
1348 geoip_countries
= NULL
;
1349 country_idxplus1_by_lc_code
= NULL
;
1350 geoip_entries
= NULL
;
1353 /** Release all storage held in this file. */
1355 geoip_free_all(void)
1358 clientmap_entry_t
**ent
, **next
, *this;
1359 for (ent
= HT_START(clientmap
, &client_history
); ent
!= NULL
; ent
= next
) {
1361 next
= HT_NEXT_RMV(clientmap
, &client_history
, ent
);
1364 HT_CLEAR(clientmap
, &client_history
);
1367 dirreq_map_entry_t
**ent
, **next
, *this;
1368 for (ent
= HT_START(dirreqmap
, &dirreq_map
); ent
!= NULL
; ent
= next
) {
1370 next
= HT_NEXT_RMV(dirreqmap
, &dirreq_map
, ent
);
1373 HT_CLEAR(dirreqmap
, &dirreq_map
);