Tor
0.4.7.0-alpha-dev
|
Header file for geoip_stats.c. More...
#include "core/or/dos.h"
#include "ext/ht.h"
Go to the source code of this file.
Data Structures | |
struct | clientmap_entry_t |
Macros | |
#define | GEOIP_NS_RESPONSE_NUM 6 |
Enumerations | |
enum | geoip_client_action_t { GEOIP_CLIENT_CONNECT = 0 , GEOIP_CLIENT_NETWORKSTATUS = 1 } |
enum | geoip_ns_response_t { GEOIP_SUCCESS = 0 , GEOIP_REJECT_NOT_ENOUGH_SIGS = 1 , GEOIP_REJECT_UNAVAILABLE = 2 , GEOIP_REJECT_NOT_FOUND = 3 , GEOIP_REJECT_NOT_MODIFIED = 4 , GEOIP_REJECT_BUSY = 5 } |
enum | dirreq_type_t { DIRREQ_DIRECT = 0 , DIRREQ_TUNNELED = 1 } |
enum | dirreq_state_t { DIRREQ_IS_FOR_NETWORK_STATUS = 0 , DIRREQ_FLUSHING_DIR_CONN_FINISHED = 1 , DIRREQ_END_CELL_SENT = 2 , DIRREQ_CIRC_QUEUE_FLUSHED = 3 , DIRREQ_CHANNEL_BUFFER_FLUSHED = 4 } |
Functions | |
int | should_record_bridge_info (const or_options_t *options) |
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_t * | geoip_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) |
void | geoip_stats_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) |
Header file for geoip_stats.c.
Definition in file geoip_stats.h.
enum dirreq_state_t |
Possible states for either direct or tunneled directory requests that are relevant for determining network status download times.
Definition at line 56 of file geoip_stats.h.
enum dirreq_type_t |
Directory requests that we are measuring can be either direct or tunneled.
Definition at line 49 of file geoip_stats.h.
Indicates an action that we might be noting geoip statistics on. Note that if we're noticing CONNECT, we're a bridge, and if we're noticing the others, we're not.
Enumerator | |
---|---|
GEOIP_CLIENT_CONNECT | We've noticed a connection as a bridge relay or entry guard. |
GEOIP_CLIENT_NETWORKSTATUS | We've served a networkstatus consensus as a directory server. |
Definition at line 22 of file geoip_stats.h.
enum geoip_ns_response_t |
Indicates either a positive reply or a reason for rejectng a network status request that will be included in geoip statistics.
Definition at line 30 of file geoip_stats.h.
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.
Definition at line 1207 of file geoip_stats.c.
void geoip_bridge_stats_init | ( | time_t | now | ) |
Initialize bridge stats.
Definition at line 1066 of file geoip_stats.c.
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().
Definition at line 1074 of file geoip_stats.c.
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.
Definition at line 1238 of file geoip_stats.c.
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.
Definition at line 552 of file geoip_stats.c.
Referenced by channel_notify_flushed(), and connection_dir_finished_flushing().
void geoip_dirreq_stats_init | ( | time_t | now | ) |
Initialize directory request stats.
Definition at line 920 of file geoip_stats.c.
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().
Definition at line 959 of file geoip_stats.c.
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.
Definition at line 1031 of file geoip_stats.c.
void geoip_entry_stats_init | ( | time_t | now | ) |
Initialize entry stats.
Definition at line 1321 of file geoip_stats.c.
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().
Definition at line 1337 of file geoip_stats.c.
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.
Definition at line 1373 of file geoip_stats.c.
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.
Definition at line 1148 of file geoip_stats.c.
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.
Definition at line 968 of file geoip_stats.c.
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.
Definition at line 1346 of file geoip_stats.c.
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.
Definition at line 1310 of file geoip_stats.c.
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.
Definition at line 1301 of file geoip_stats.c.
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 number 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.
Definition at line 784 of file geoip_stats.c.
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.
Definition at line 879 of file geoip_stats.c.
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.
Definition at line 579 of file geoip_stats.c.
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.
Definition at line 229 of file geoip_stats.c.
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.
Definition at line 395 of file geoip_stats.c.
void geoip_remove_old_clients | ( | time_t | cutoff | ) |
Forget about all clients that haven't connected since cutoff.
Definition at line 293 of file geoip_stats.c.
void geoip_reset_dirreq_stats | ( | time_t | now | ) |
Reset counters for dirreq stats.
Definition at line 927 of file geoip_stats.c.
Referenced by geoip_dirreq_stats_term().
void geoip_reset_entry_stats | ( | time_t | now | ) |
Reset counters for entry stats.
Definition at line 1328 of file geoip_stats.c.
Referenced by geoip_entry_stats_term().
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.
Definition at line 531 of file geoip_stats.c.
void geoip_stats_free_all | ( | void | ) |
Release all storage held in this file.
Definition at line 1403 of file geoip_stats.c.
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.
Definition at line 112 of file geoip_stats.c.
Referenced by geoip_note_client_seen(), options_need_geoip_info(), and record_bridge_stats_callback().