Tor 0.4.9.0-alpha-dev
Data Structures | Macros | Enumerations | Functions
geoip_stats.h File Reference

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_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)
 
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)
 

Detailed Description

Header file for geoip_stats.c.

Definition in file geoip_stats.h.

Macro Definition Documentation

◆ GEOIP_NS_RESPONSE_NUM

#define GEOIP_NS_RESPONSE_NUM   6

Definition at line 45 of file geoip_stats.h.

Enumeration Type Documentation

◆ dirreq_state_t

Possible states for either direct or tunneled directory requests that are relevant for determining network status download times.

Enumerator
DIRREQ_IS_FOR_NETWORK_STATUS 

Found that the client requests a network status; applies to both direct and tunneled requests; initial state of a request that we are measuring.

DIRREQ_FLUSHING_DIR_CONN_FINISHED 

Finished writing a network status to the directory connection; applies to both direct and tunneled requests; completes a direct request.

DIRREQ_END_CELL_SENT 

END cell sent to circuit that initiated a tunneled request.

DIRREQ_CIRC_QUEUE_FLUSHED 

Flushed last cell from queue of the circuit that initiated a tunneled request to the outbuf of the OR connection.

DIRREQ_CHANNEL_BUFFER_FLUSHED 

Flushed last byte from buffer of the channel belonging to the circuit that initiated a tunneled request; completes a tunneled request.

Definition at line 56 of file geoip_stats.h.

◆ dirreq_type_t

Directory requests that we are measuring can be either direct or tunneled.

Definition at line 49 of file geoip_stats.h.

◆ geoip_client_action_t

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 

An incoming ORPort connection

GEOIP_CLIENT_NETWORKSTATUS 

We've served a networkstatus consensus as a directory server.

Definition at line 22 of file geoip_stats.h.

◆ 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.

Enumerator
GEOIP_SUCCESS 

Request is answered successfully.

GEOIP_REJECT_NOT_ENOUGH_SIGS 

V3 network status is not signed by a sufficient number of requested authorities.

GEOIP_REJECT_UNAVAILABLE 

Requested network status object is unavailable.

GEOIP_REJECT_NOT_FOUND 

Requested network status not found.

GEOIP_REJECT_NOT_MODIFIED 

Network status has not been modified since If-Modified-Since time.

GEOIP_REJECT_BUSY 

Directory is busy.

Definition at line 30 of file geoip_stats.h.

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.

Definition at line 1207 of file geoip_stats.c.

◆ geoip_bridge_stats_init()

void geoip_bridge_stats_init ( time_t  now)

Initialize bridge stats.

Definition at line 1066 of file geoip_stats.c.

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

Definition at line 1074 of file geoip_stats.c.

◆ 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.

Definition at line 1238 of file geoip_stats.c.

◆ 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.

Definition at line 552 of file geoip_stats.c.

Referenced by channel_notify_flushed(), and connection_dir_finished_flushing().

◆ geoip_client_cache_handle_oom()

size_t geoip_client_cache_handle_oom ( time_t  now,
size_t  min_remove_bytes 
)

Definition at line 350 of file geoip_stats.c.

◆ geoip_client_cache_total_allocation()

size_t geoip_client_cache_total_allocation ( void  )

Definition at line 383 of file geoip_stats.c.

◆ geoip_dirreq_stats_init()

void geoip_dirreq_stats_init ( time_t  now)

Initialize directory request stats.

Definition at line 920 of file geoip_stats.c.

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

Definition at line 959 of file geoip_stats.c.

◆ 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.

Definition at line 1031 of file geoip_stats.c.

◆ geoip_entry_stats_init()

void geoip_entry_stats_init ( time_t  now)

Initialize entry stats.

Definition at line 1321 of file geoip_stats.c.

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

Definition at line 1337 of file geoip_stats.c.

◆ 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.

Definition at line 1373 of file geoip_stats.c.

◆ 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.

Definition at line 1148 of file geoip_stats.c.

◆ 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.

Definition at line 968 of file geoip_stats.c.

◆ 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.

Definition at line 1346 of file geoip_stats.c.

◆ 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.

Definition at line 1310 of file geoip_stats.c.

◆ 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.

Definition at line 1301 of file geoip_stats.c.

◆ 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 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.

◆ 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.

Definition at line 879 of file geoip_stats.c.

◆ 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.

Definition at line 579 of file geoip_stats.c.

◆ geoip_lookup_client()

clientmap_entry_t * geoip_lookup_client ( const tor_addr_t addr,
const char *  transport_name,
geoip_client_action_t  action 
)

Definition at line 304 of file geoip_stats.c.

◆ 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.

Definition at line 229 of file geoip_stats.c.

◆ 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.

Definition at line 395 of file geoip_stats.c.

◆ geoip_remove_old_clients()

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.

◆ geoip_reset_dirreq_stats()

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

◆ geoip_reset_entry_stats()

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

◆ 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.

Definition at line 531 of file geoip_stats.c.

◆ geoip_stats_free_all()

void geoip_stats_free_all ( void  )

Release all storage held in this file.

Definition at line 1403 of file geoip_stats.c.

◆ 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.

Definition at line 112 of file geoip_stats.c.

Referenced by geoip_note_client_seen(), options_need_geoip_info(), and record_bridge_stats_callback().