tor  master
Data Structures | Typedefs | Functions
geoip.h File Reference

Header file for geoip.c. More...

#include "testsupport.h"
#include "dos.h"
Include dependency graph for geoip.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  clientmap_entry_t
 

Typedefs

typedef struct clientmap_entry_t clientmap_entry_t
 

Functions

int should_record_bridge_info (const or_options_t *options)
 
int geoip_load_file (sa_family_t family, const char *filename)
 
 MOCK_DECL (int, geoip_get_country_by_addr,(const 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))
 
const char * geoip_db_digest (sa_family_t family)
 
 MOCK_DECL (country_t, geoip_get_country,(const char *countrycode))
 
void geoip_note_client_seen (geoip_client_action_t action, const tor_addr_t *addr, const char *transport_name, time_t now)
 
void geoip_remove_old_clients (time_t cutoff)
 
clientmap_entry_tgeoip_lookup_client (const tor_addr_t *addr, const char *transport_name, geoip_client_action_t action)
 
size_t geoip_client_cache_total_allocation (void)
 
size_t geoip_client_cache_handle_oom (time_t now, size_t min_remove_bytes)
 
void geoip_note_ns_response (geoip_ns_response_t response)
 
char * geoip_get_transport_history (void)
 
int geoip_get_client_history (geoip_client_action_t action, char **country_str, char **ipver_str)
 
char * geoip_get_request_history (void)
 
int getinfo_helper_geoip (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
void geoip_free_all (void)
 
void geoip_start_dirreq (uint64_t dirreq_id, size_t response_size, dirreq_type_t type)
 
void geoip_change_dirreq_state (uint64_t dirreq_id, dirreq_type_t type, dirreq_state_t new_state)
 
void geoip_dirreq_stats_init (time_t now)
 
void geoip_reset_dirreq_stats (time_t now)
 
char * geoip_format_dirreq_stats (time_t now)
 
time_t geoip_dirreq_stats_write (time_t now)
 
void geoip_dirreq_stats_term (void)
 
void geoip_entry_stats_init (time_t now)
 
time_t geoip_entry_stats_write (time_t now)
 
void geoip_entry_stats_term (void)
 
void geoip_reset_entry_stats (time_t now)
 
char * geoip_format_entry_stats (time_t now)
 
void geoip_bridge_stats_init (time_t now)
 
char * geoip_format_bridge_stats (time_t now)
 
time_t geoip_bridge_stats_write (time_t now)
 
void geoip_bridge_stats_term (void)
 
const char * geoip_get_bridge_stats_extrainfo (time_t)
 
char * geoip_get_bridge_stats_controller (time_t)
 
char * format_client_stats_heartbeat (time_t now)
 

Detailed Description

Header file for geoip.c.

Typedef Documentation

◆ clientmap_entry_t

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, or the DoS mitigation subsystem if enabled.

Function Documentation

◆ format_client_stats_heartbeat()

char* format_client_stats_heartbeat ( time_t  now)

Return a newly allocated string holding our bridge usage stats by country in a format suitable for inclusion in our heartbeat message. Return NULL on failure.

Here is the call graph for this function:

◆ geoip_bridge_stats_init()

void geoip_bridge_stats_init ( time_t  now)

Initialize bridge stats.

◆ geoip_bridge_stats_term()

void geoip_bridge_stats_term ( void  )

Stop collecting bridge stats in a way that we can re-start doing so in geoip_bridge_stats_init().

◆ geoip_bridge_stats_write()

time_t geoip_bridge_stats_write ( time_t  now)

Write bridge statistics to $DATADIR/stats/bridge-stats and return when we should next try to write statistics.

◆ geoip_change_dirreq_state()

void geoip_change_dirreq_state ( uint64_t  dirreq_id,
dirreq_type_t  type,
dirreq_state_t  new_state 
)

Change the state of the either direct or tunneled (see type) directory request with dirreq_id to new_state and possibly mark it as completed. If no entry can be found for the given key parts (e.g., if this is a directory request that we are not measuring, or one that was started in the previous measurement period), or if the state cannot be advanced to new_state, do nothing.

Here is the caller graph for this function:

◆ geoip_db_digest()

const char* geoip_db_digest ( sa_family_t  family)

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().

Here is the call graph for this function:

◆ geoip_dirreq_stats_init()

void geoip_dirreq_stats_init ( time_t  now)

Initialize directory request stats.

◆ geoip_dirreq_stats_term()

void geoip_dirreq_stats_term ( void  )

Stop collecting directory request stats in a way that we can re-start doing so in geoip_dirreq_stats_init().

Here is the call graph for this function:

◆ geoip_dirreq_stats_write()

time_t geoip_dirreq_stats_write ( time_t  now)

If 24 hours have passed since the beginning of the current dirreq stats period, write dirreq stats to $DATADIR/stats/dirreq-stats (possibly overwriting an existing file) and reset counters. Return when we would next want to write dirreq stats or 0 if we never want to write.

◆ geoip_entry_stats_init()

void geoip_entry_stats_init ( time_t  now)

Initialize entry stats.

◆ geoip_entry_stats_term()

void geoip_entry_stats_term ( void  )

Stop collecting entry stats in a way that we can re-start doing so in geoip_entry_stats_init().

Here is the call graph for this function:

◆ geoip_entry_stats_write()

time_t geoip_entry_stats_write ( time_t  now)

If 24 hours have passed since the beginning of the current entry stats period, write entry stats to $DATADIR/stats/entry-stats (possibly overwriting an existing file) and reset counters. Return when we would next want to write entry stats or 0 if we never want to write.

◆ geoip_format_bridge_stats()

char* geoip_format_bridge_stats ( time_t  now)

Return a newly allocated string holding our bridge usage stats by country in a format suitable for inclusion in an extrainfo document. Return NULL on failure.

◆ geoip_format_dirreq_stats()

char* geoip_format_dirreq_stats ( time_t  now)

Return a newly allocated string containing the dirreq statistics until now, or NULL if we're not collecting dirreq stats. Caller must ensure start_of_dirreq_stats_interval is in the past.

◆ geoip_format_entry_stats()

char* geoip_format_entry_stats ( time_t  now)

Return a newly allocated string containing the entry statistics until now, or NULL if we're not collecting entry stats. Caller must ensure start_of_entry_stats_interval lies in the past.

◆ geoip_free_all()

void geoip_free_all ( void  )

Release all storage held in this file.

◆ geoip_get_bridge_stats_controller()

char* geoip_get_bridge_stats_controller ( time_t  now)

Return a new string containing the recent bridge statistics to be returned to controller clients, or NULL if we don't have any bridge statistics.

◆ geoip_get_bridge_stats_extrainfo()

const char* geoip_get_bridge_stats_extrainfo ( time_t  now)

Return most recent bridge statistics for inclusion in extra-info descriptors, or NULL if we don't have recent bridge statistics.

◆ geoip_get_client_history()

int geoip_get_client_history ( geoip_client_action_t  action,
char **  country_str,
char **  ipver_str 
)

Store a newly allocated comma-separated string in *country_str containing entries for all the countries from which we've seen enough clients connect as a bridge, directory server, or entry guard. The entry format is cc=num where num is the number of IPs we've seen connecting from that country, and cc is a lowercased country code. *country_str is set to NULL if we're not ready to export per country data yet.

Store a newly allocated comma-separated string in ipver_str containing entries for clients connecting over IPv4 and IPv6. The format is family=num where num is the nubmer of IPs we've seen connecting over that protocol family, and family is 'v4' or 'v6'.

Return 0 on success and -1 if we're missing geoip data.

unresolved requests are stored at index 0.

◆ geoip_get_country_name()

const char* geoip_get_country_name ( country_t  num)

Return the two-letter country code associated with the number num, or "??" for an unknown value.

◆ geoip_get_request_history()

char* geoip_get_request_history ( void  )

Return a newly allocated string holding the per-country request history for v3 network statuses in a format suitable for an extra-info document, or NULL on failure.

◆ geoip_get_transport_history()

char* geoip_get_transport_history ( void  )

Return the bridge-ip-transports string that should be inserted in our extra-info descriptor. Return NULL if the bridge-ip-transports line should be empty.

String hash table (name of transport) -> (number of users).

Smartlist that contains copies of the names of the transports that have been used.

We do the following steps to form the transport history string: a) Foreach client that uses a pluggable transport, we increase the times that transport was used by one. If the client did not use a transport, we increase the number of times someone connected without obfuscation. b) Foreach transport we observed, we write its transport history string and push it to string_chunks. So, for example, if we've seen 665 obfs2 clients, we write "obfs2=665". c) We concatenate string_chunks to form the final string.

◆ geoip_load_file()

int geoip_load_file ( sa_family_t  family,
const char *  filename 
)

Clear appropriate GeoIP database, based on family, and reload it from the file filename. Return 0 on success, -1 on failure.

Recognized line formats for IPv4 are: INTIPLOW,INTIPHIGH,CC and "INTIPLOW","INTIPHIGH","CC","CC3","COUNTRY NAME" where INTIPLOW and INTIPHIGH are IPv4 addresses encoded as 4-byte unsigned integers, and CC is a country code.

Recognized line format for IPv6 is: IPV6LOW,IPV6HIGH,CC where IPV6LOW and IPV6HIGH are IPv6 addresses and CC is a country code.

It also recognizes, and skips over, blank lines and lines that start with '#' (comments).

Here is the call graph for this function:

◆ geoip_note_client_seen()

void geoip_note_client_seen ( geoip_client_action_t  action,
const tor_addr_t addr,
const char *  transport_name,
time_t  now 
)

Note that we've seen a client connect from the IP addr at time now. Ignored by all but bridges and directories if configured accordingly.

unresolved requests are stored at index 0.

Here is the call graph for this function:

◆ geoip_note_ns_response()

void geoip_note_ns_response ( geoip_ns_response_t  response)

Note that we've rejected a client's request for a v3 network status for reason reason at time now.

◆ geoip_remove_old_clients()

void geoip_remove_old_clients ( time_t  cutoff)

Forget about all clients that haven't connected since cutoff.

◆ geoip_reset_dirreq_stats()

void geoip_reset_dirreq_stats ( time_t  now)

Reset counters for dirreq stats.

Here is the caller graph for this function:

◆ geoip_reset_entry_stats()

void geoip_reset_entry_stats ( time_t  now)

Reset counters for entry stats.

Here is the caller graph for this function:

◆ geoip_start_dirreq()

void geoip_start_dirreq ( uint64_t  dirreq_id,
size_t  response_size,
dirreq_type_t  type 
)

Note that an either direct or tunneled (see type) directory request for a v3 network status with unique ID dirreq_id of size response_size has started.

◆ getinfo_helper_geoip()

int getinfo_helper_geoip ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)

Helper used to implement GETINFO ip-to-country/... controller command.

Here is the call graph for this function:

◆ should_record_bridge_info()

int should_record_bridge_info ( const or_options_t options)

Return 1 if we should collect geoip stats on bridge users, and include them in our extrainfo descriptor. Else return 0.

Here is the caller graph for this function: