Tor 0.4.9.8
Loading...
Searching...
No Matches
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-2021, 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#include "ext/ht.h"
17
18/** Indicates an action that we might be noting geoip statistics on.
19 * Note that if we're noticing CONNECT, we're a bridge, and if we're noticing
20 * the others, we're not.
21 */
22typedef enum {
23 /** An incoming ORPort connection */
25 /** We've served a networkstatus consensus as a directory server. */
28/** Indicates either a positive reply or a reason for rejecting a network
29 * status request that will be included in geoip statistics. */
30typedef enum {
31 /** Request is answered successfully. */
33 /** V3 network status is not signed by a sufficient number of requested
34 * authorities. */
36 /** Requested network status object is unavailable. */
38 /** Requested network status not found. */
40 /** Network status has not been modified since If-Modified-Since time. */
42 /** Directory is busy. */
44 /** We began to serve the request, and when we feel we have finished
45 * serving it we will note this with a GEOIP_SUCCESS call too. */
48#define GEOIP_NS_RESPONSE_NUM 7
49
50/** Directory requests that we are measuring can be either direct or
51 * tunneled. */
52typedef enum {
53 DIRREQ_DIRECT = 0,
54 DIRREQ_TUNNELED = 1,
56
57/** Possible states for either direct or tunneled directory requests that
58 * are relevant for determining network status download times. */
59typedef enum {
60 /** Found that the client requests a network status; applies to both
61 * direct and tunneled requests; initial state of a request that we are
62 * measuring. */
64 /** Finished writing a network status to the directory connection;
65 * applies to both direct and tunneled requests; completes a direct
66 * request. */
68 /** END cell sent to circuit that initiated a tunneled request. */
70 /** Flushed last cell from queue of the circuit that initiated a
71 * tunneled request to the outbuf of the OR connection. */
73 /** Flushed last byte from buffer of the channel belonging to the
74 * circuit that initiated a tunneled request; completes a tunneled
75 * request. */
78
79/** Entry in a map from IP address to the last time we've seen an incoming
80 * connection from that IP address. Used by bridges only to track which
81 * countries have them blocked, or the DoS mitigation subsystem if enabled. */
82typedef struct clientmap_entry_t {
83 HT_ENTRY(clientmap_entry_t) node;
84 tor_addr_t addr;
85 /* Name of pluggable transport used by this client. NULL if no
86 pluggable transport was used. */
87 char *transport_name;
88
89 /** Time when we last saw this IP address, in MINUTES since the epoch.
90 *
91 * (This will run out of space around 4011 CE. If Tor is still in use around
92 * 4000 CE, please remember to add more bits to last_seen_in_minutes.) */
93 unsigned int last_seen_in_minutes:30;
94 unsigned int action:2;
95
96 /* This object is used to keep some statistics per client address for the
97 * DoS mitigation subsystem. */
98 dos_client_stats_t dos_stats;
100
101int should_record_bridge_info(const or_options_t *options);
102
104 const tor_addr_t *addr, const char *transport_name,
105 time_t now);
106void geoip_remove_old_clients(time_t cutoff);
107clientmap_entry_t *geoip_lookup_client(const tor_addr_t *addr,
108 const char *transport_name,
109 geoip_client_action_t action);
110size_t geoip_client_cache_total_allocation(void);
111size_t geoip_client_cache_handle_oom(time_t now, size_t min_remove_bytes);
112
116 char **country_str, char **ipver_str);
117char *geoip_get_request_history(void);
118void geoip_stats_free_all(void);
119
120void geoip_start_dirreq(uint64_t dirreq_id, size_t response_size,
121 dirreq_type_t type);
122void geoip_change_dirreq_state(uint64_t dirreq_id, dirreq_type_t type,
123 dirreq_state_t new_state);
124
125void geoip_dirreq_stats_init(time_t now);
126void geoip_reset_dirreq_stats(time_t now);
127char *geoip_format_dirreq_stats(time_t now);
128time_t geoip_dirreq_stats_write(time_t now);
129void geoip_dirreq_stats_term(void);
130void geoip_entry_stats_init(time_t now);
131time_t geoip_entry_stats_write(time_t now);
132void geoip_entry_stats_term(void);
133void geoip_reset_entry_stats(time_t now);
134char *geoip_format_entry_stats(time_t now);
135void geoip_bridge_stats_init(time_t now);
136char *geoip_format_bridge_stats(time_t now);
137time_t geoip_bridge_stats_write(time_t now);
138void geoip_bridge_stats_term(void);
139const char *geoip_get_bridge_stats_extrainfo(time_t);
141char *format_client_stats_heartbeat(time_t now);
142
143#endif /* !defined(TOR_GEOIP_STATS_H) */
time_t geoip_entry_stats_write(time_t now)
int geoip_get_client_history(geoip_client_action_t action, char **country_str, char **ipver_str)
void geoip_reset_entry_stats(time_t now)
dirreq_type_t
Definition geoip_stats.h:52
time_t geoip_dirreq_stats_write(time_t now)
dirreq_state_t
Definition geoip_stats.h:59
@ DIRREQ_END_CELL_SENT
Definition geoip_stats.h:69
@ DIRREQ_CIRC_QUEUE_FLUSHED
Definition geoip_stats.h:72
@ DIRREQ_CHANNEL_BUFFER_FLUSHED
Definition geoip_stats.h:76
@ DIRREQ_IS_FOR_NETWORK_STATUS
Definition geoip_stats.h:63
@ DIRREQ_FLUSHING_DIR_CONN_FINISHED
Definition geoip_stats.h:67
const char * geoip_get_bridge_stats_extrainfo(time_t)
void geoip_dirreq_stats_init(time_t now)
void geoip_bridge_stats_init(time_t now)
void geoip_change_dirreq_state(uint64_t dirreq_id, dirreq_type_t type, dirreq_state_t new_state)
char * geoip_format_bridge_stats(time_t now)
void geoip_note_ns_response(geoip_ns_response_t response)
void geoip_remove_old_clients(time_t cutoff)
void geoip_bridge_stats_term(void)
void geoip_entry_stats_init(time_t now)
char * geoip_format_dirreq_stats(time_t now)
char * format_client_stats_heartbeat(time_t now)
void geoip_dirreq_stats_term(void)
geoip_client_action_t
Definition geoip_stats.h:22
@ GEOIP_CLIENT_NETWORKSTATUS
Definition geoip_stats.h:26
@ GEOIP_CLIENT_CONNECT
Definition geoip_stats.h:24
void geoip_start_dirreq(uint64_t dirreq_id, size_t response_size, dirreq_type_t type)
char * geoip_format_entry_stats(time_t now)
void geoip_note_client_seen(geoip_client_action_t action, const tor_addr_t *addr, const char *transport_name, time_t now)
char * geoip_get_request_history(void)
char * geoip_get_bridge_stats_controller(time_t)
void geoip_reset_dirreq_stats(time_t now)
char * geoip_get_transport_history(void)
void geoip_stats_free_all(void)
void geoip_entry_stats_term(void)
int should_record_bridge_info(const or_options_t *options)
time_t geoip_bridge_stats_write(time_t now)
geoip_ns_response_t
Definition geoip_stats.h:30
@ GEOIP_REJECT_BUSY
Definition geoip_stats.h:43
@ GEOIP_SUCCESS
Definition geoip_stats.h:32
@ GEOIP_REJECT_NOT_FOUND
Definition geoip_stats.h:39
@ GEOIP_REJECT_NOT_MODIFIED
Definition geoip_stats.h:41
@ GEOIP_REJECT_NOT_ENOUGH_SIGS
Definition geoip_stats.h:35
@ GEOIP_SERVED
Definition geoip_stats.h:46
@ GEOIP_REJECT_UNAVAILABLE
Definition geoip_stats.h:37
Definition geoip_stats.h:82
unsigned int last_seen_in_minutes
Definition geoip_stats.h:93