Tor  0.4.3.0-alpha-dev
geoip_stats.h
Go to the documentation of this file.
1 /* Copyright (c) 2001 Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2019, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 /**
8  * \file geoip_stats.h
9  * \brief Header file for geoip_stats.c.
10  **/
11 
12 #ifndef TOR_GEOIP_STATS_H
13 #define TOR_GEOIP_STATS_H
14 
15 #include "core/or/dos.h"
16 
17 /** Indicates an action that we might be noting geoip statistics on.
18  * Note that if we're noticing CONNECT, we're a bridge, and if we're noticing
19  * the others, we're not.
20  */
21 typedef enum {
22  /** We've noticed a connection as a bridge relay or entry guard. */
24  /** We've served a networkstatus consensus as a directory server. */
27 /** Indicates either a positive reply or a reason for rejectng a network
28  * status request that will be included in geoip statistics. */
29 typedef enum {
30  /** Request is answered successfully. */
32  /** V3 network status is not signed by a sufficient number of requested
33  * authorities. */
35  /** Requested network status object is unavailable. */
37  /** Requested network status not found. */
39  /** Network status has not been modified since If-Modified-Since time. */
41  /** Directory is busy. */
44 #define GEOIP_NS_RESPONSE_NUM 6
45 
46 /** Directory requests that we are measuring can be either direct or
47  * tunneled. */
48 typedef enum {
49  DIRREQ_DIRECT = 0,
50  DIRREQ_TUNNELED = 1,
52 
53 /** Possible states for either direct or tunneled directory requests that
54  * are relevant for determining network status download times. */
55 typedef enum {
56  /** Found that the client requests a network status; applies to both
57  * direct and tunneled requests; initial state of a request that we are
58  * measuring. */
60  /** Finished writing a network status to the directory connection;
61  * applies to both direct and tunneled requests; completes a direct
62  * request. */
64  /** END cell sent to circuit that initiated a tunneled request. */
66  /** Flushed last cell from queue of the circuit that initiated a
67  * tunneled request to the outbuf of the OR connection. */
69  /** Flushed last byte from buffer of the channel belonging to the
70  * circuit that initiated a tunneled request; completes a tunneled
71  * request. */
74 
75 /** Entry in a map from IP address to the last time we've seen an incoming
76  * connection from that IP address. Used by bridges only to track which
77  * countries have them blocked, or the DoS mitigation subsystem if enabled. */
78 typedef struct clientmap_entry_t {
79  HT_ENTRY(clientmap_entry_t) node;
80  tor_addr_t addr;
81  /* Name of pluggable transport used by this client. NULL if no
82  pluggable transport was used. */
83  char *transport_name;
84 
85  /** Time when we last saw this IP address, in MINUTES since the epoch.
86  *
87  * (This will run out of space around 4011 CE. If Tor is still in use around
88  * 4000 CE, please remember to add more bits to last_seen_in_minutes.) */
89  unsigned int last_seen_in_minutes:30;
90  unsigned int action:2;
91 
92  /* This object is used to keep some statistics per client address for the
93  * DoS mitigation subsystem. */
94  dos_client_stats_t dos_stats;
96 
97 int should_record_bridge_info(const or_options_t *options);
98 
100  const tor_addr_t *addr, const char *transport_name,
101  time_t now);
102 void geoip_remove_old_clients(time_t cutoff);
103 clientmap_entry_t *geoip_lookup_client(const tor_addr_t *addr,
104  const char *transport_name,
105  geoip_client_action_t action);
106 size_t geoip_client_cache_total_allocation(void);
107 size_t geoip_client_cache_handle_oom(time_t now, size_t min_remove_bytes);
108 
110 char *geoip_get_transport_history(void);
112  char **country_str, char **ipver_str);
113 char *geoip_get_request_history(void);
114 void geoip_stats_free_all(void);
115 
116 void geoip_start_dirreq(uint64_t dirreq_id, size_t response_size,
117  dirreq_type_t type);
118 void geoip_change_dirreq_state(uint64_t dirreq_id, dirreq_type_t type,
119  dirreq_state_t new_state);
120 
121 void geoip_dirreq_stats_init(time_t now);
122 void geoip_reset_dirreq_stats(time_t now);
123 char *geoip_format_dirreq_stats(time_t now);
124 time_t geoip_dirreq_stats_write(time_t now);
125 void geoip_dirreq_stats_term(void);
126 void geoip_entry_stats_init(time_t now);
127 time_t geoip_entry_stats_write(time_t now);
128 void geoip_entry_stats_term(void);
129 void geoip_reset_entry_stats(time_t now);
130 char *geoip_format_entry_stats(time_t now);
131 void geoip_bridge_stats_init(time_t now);
132 char *geoip_format_bridge_stats(time_t now);
133 time_t geoip_bridge_stats_write(time_t now);
134 void geoip_bridge_stats_term(void);
135 const char *geoip_get_bridge_stats_extrainfo(time_t);
137 char *format_client_stats_heartbeat(time_t now);
138 
139 #endif /* !defined(TOR_GEOIP_STATS_H) */
void geoip_reset_dirreq_stats(time_t now)
Definition: geoip_stats.c:925
void geoip_change_dirreq_state(uint64_t dirreq_id, dirreq_type_t type, dirreq_state_t new_state)
Definition: geoip_stats.c:550
int geoip_get_client_history(geoip_client_action_t action, char **country_str, char **ipver_str)
Definition: geoip_stats.c:782
void geoip_note_client_seen(geoip_client_action_t action, const tor_addr_t *addr, const char *transport_name, time_t now)
Definition: geoip_stats.c:227
char * geoip_format_dirreq_stats(time_t now)
Definition: geoip_stats.c:966
dirreq_type_t
Definition: geoip_stats.h:48
char * geoip_format_bridge_stats(time_t now)
Definition: geoip_stats.c:1146
dirreq_state_t
Definition: geoip_stats.h:55
void geoip_dirreq_stats_init(time_t now)
Definition: geoip_stats.c:918
int should_record_bridge_info(const or_options_t *options)
Definition: geoip_stats.c:112
char * geoip_get_request_history(void)
Definition: geoip_stats.c:877
time_t geoip_bridge_stats_write(time_t now)
Definition: geoip_stats.c:1237
void geoip_dirreq_stats_term(void)
Definition: geoip_stats.c:957
char * geoip_format_entry_stats(time_t now)
Definition: geoip_stats.c:1345
void geoip_entry_stats_init(time_t now)
Definition: geoip_stats.c:1320
void geoip_reset_entry_stats(time_t now)
Definition: geoip_stats.c:1327
time_t geoip_entry_stats_write(time_t now)
Definition: geoip_stats.c:1372
geoip_ns_response_t
Definition: geoip_stats.h:29
void geoip_note_ns_response(geoip_ns_response_t response)
Definition: geoip_stats.c:393
char * geoip_get_bridge_stats_controller(time_t)
Definition: geoip_stats.c:1309
void geoip_start_dirreq(uint64_t dirreq_id, size_t response_size, dirreq_type_t type)
Definition: geoip_stats.c:529
geoip_client_action_t
Definition: geoip_stats.h:21
Definition: geoip_stats.h:78
void geoip_bridge_stats_init(time_t now)
Definition: geoip_stats.c:1064
void geoip_entry_stats_term(void)
Definition: geoip_stats.c:1336
const char * geoip_get_bridge_stats_extrainfo(time_t)
Definition: geoip_stats.c:1300
void geoip_remove_old_clients(time_t cutoff)
Definition: geoip_stats.c:291
time_t geoip_dirreq_stats_write(time_t now)
Definition: geoip_stats.c:1029
unsigned int last_seen_in_minutes
Definition: geoip_stats.h:89
void geoip_stats_free_all(void)
Definition: geoip_stats.c:1402
void geoip_bridge_stats_term(void)
Definition: geoip_stats.c:1072
char * format_client_stats_heartbeat(time_t now)
Definition: geoip_stats.c:1205
char * geoip_get_transport_history(void)
Definition: geoip_stats.c:577