26#include "feature/client/circpathbias.h"
75 log_info(
LD_CIRC,
"Got success count %f/%f for guard %s",
86#define DFLT_PATH_BIAS_MIN_CIRC 150
91 DFLT_PATH_BIAS_MIN_CIRC,
99#define DFLT_PATH_BIAS_NOTICE_PCT 70
100 if (options->PathBiasNoticeRate >= 0.0)
101 return options->PathBiasNoticeRate;
104 DFLT_PATH_BIAS_NOTICE_PCT, 0, 100)/100.0;
111#define DFLT_PATH_BIAS_WARN_PCT 50
112 if (options->PathBiasWarnRate >= 0.0)
113 return options->PathBiasWarnRate;
116 DFLT_PATH_BIAS_WARN_PCT, 0, 100)/100.0;
127#define DFLT_PATH_BIAS_EXTREME_PCT 30
128 if (options->PathBiasExtremeRate >= 0.0)
129 return options->PathBiasExtremeRate;
132 DFLT_PATH_BIAS_EXTREME_PCT, 0, 100)/100.0;
143#define DFLT_PATH_BIAS_DROP_GUARDS 0
144 if (options->PathBiasDropGuards >= 0)
145 return options->PathBiasDropGuards;
148 DFLT_PATH_BIAS_DROP_GUARDS, 0, 1);
160#define DFLT_PATH_BIAS_SCALE_THRESHOLD 300
161 if (options->PathBiasScaleThreshold >= 10)
162 return options->PathBiasScaleThreshold;
165 DFLT_PATH_BIAS_SCALE_THRESHOLD, 10,
197 1, 1, denominator)/((double)denominator);
205#define DFLT_PATH_BIAS_MIN_USE 20
210 DFLT_PATH_BIAS_MIN_USE,
218#define DFLT_PATH_BIAS_NOTICE_USE_PCT 80
219 if (options->PathBiasNoticeUseRate >= 0.0)
220 return options->PathBiasNoticeUseRate;
223 DFLT_PATH_BIAS_NOTICE_USE_PCT,
234#define DFLT_PATH_BIAS_EXTREME_USE_PCT 60
235 if (options->PathBiasExtremeUseRate >= 0.0)
236 return options->PathBiasExtremeUseRate;
239 DFLT_PATH_BIAS_EXTREME_USE_PCT,
252#define DFLT_PATH_BIAS_SCALE_USE_THRESHOLD 100
253 if (options->PathBiasScaleUseThreshold >= 10)
254 return options->PathBiasScaleUseThreshold;
257 DFLT_PATH_BIAS_SCALE_USE_THRESHOLD,
271 return "build attempted";
273 return "build succeeded";
275 return "use attempted";
277 return "use succeeded";
281 return "already counted";
298#define N2N_TAGGING_IS_POSSIBLE
299#ifdef N2N_TAGGING_IS_POSSIBLE
303 return circ->
cpath &&
312 return circ->
cpath &&
313 circ->
cpath->
state == CPATH_STATE_AWAITING_KEYS;
325#define PATHBIAS_COUNT_INTERVAL (600)
327 RATELIM_INIT(PATHBIAS_COUNT_INTERVAL);
328 char *rate_msg = NULL;
353 circ->base_.
purpose == CIRCUIT_PURPOSE_CONFLUX_LINKED ||
367 "Circuit %d is now being ignored despite being counted "
368 "in the past. Purpose is %s, path state is %s",
396 "One-hop circuit %d has length %d. Path state is %s. "
397 "Circuit is a %s currently %s.%s",
413 "One-hop circuit %d is now being ignored despite being counted "
414 "in the past. Purpose is %s, path state is %s",
427 "Circuit %d is not being counted by pathbias because it was "
428 "ignored in the past. Purpose is %s, path state is %s",
448#define CIRC_ATTEMPT_NOTICE_INTERVAL (600)
449 static ratelim_t circ_attempt_notice_limit =
450 RATELIM_INIT(CIRC_ATTEMPT_NOTICE_INTERVAL);
451 char *rate_msg = NULL;
463 "Opened circuit %d is in strange path state %s. "
464 "Circuit is a %s currently %s.%s",
476 entry_guard_t *guard = NULL;
481 }
else if (circ->base_.
n_chan) {
492 return -END_CIRC_REASON_TORPROTOCOL;
498 "Unopened circuit %d has strange path state %s. "
499 "Circuit is a %s currently %s.%s",
512 "Unopened circuit has no known guard. "
513 "Circuit is a %s currently %s.%s",
536#define SUCCESS_NOTICE_INTERVAL (600)
538 RATELIM_INIT(SUCCESS_NOTICE_INTERVAL);
539 char *rate_msg = NULL;
540 entry_guard_t *guard = NULL;
562 log_info(
LD_CIRC,
"Got success count %f/%f for guard %s",
569 "Succeeded circuit %d is in strange path state %s. "
570 "Circuit is a %s currently %s.%s",
581 log_notice(
LD_BUG,
"Unexpectedly high successes counts (%f/%f) "
593 "Completed circuit has no known guard. "
594 "Circuit is a %s currently %s.%s",
606 "Opened circuit %d is in strange path state %s. "
607 "Circuit is a %s currently %s.%s",
634 "Used circuit %d is in strange path state %s. "
635 "Circuit is a %s currently %s.",
652 "Marked circuit %d (%f/%f) as used for guard %s.",
662 "Used circuit %d is already in path state %s. "
663 "Circuit is a %s currently %s.",
691 "Used circuit %d is in strange path state %s. "
692 "Circuit is a %s currently %s.",
726 "Rolling back pathbias use state to 'attempted' for detached "
739 entry_guard_t *guard;
747 "Successfully used circuit %d is in strange path state %s. "
748 "Circuit is a %s currently %s.",
763 log_notice(
LD_BUG,
"Unexpectedly high use successes counts (%f/%f) "
770 "Marked circuit %d (%f/%f) as used successfully for guard %s",
805 char *probe_nonce = NULL;
811 if (cpath_layer->
state != CPATH_STATE_OPEN) {
815 "Got pathbias probe request for unopened circuit %d. "
825 "Got pathbias probe request for circuit %d with "
831 if (circ->
n_chan == NULL ||
832 (!CHANNEL_IS_OPEN(circ->
n_chan)
833 && !CHANNEL_IS_MAINT(circ->
n_chan))) {
835 "Skipping pathbias probe for circuit %d: Channel is not open.",
852 log_err(
LD_BUG,
"Failed to generate nonce");
857 payload_len = (int)strlen(payload)+1;
871 "Ran out of stream IDs on circuit %u during "
878 "Sending pathbias testing cell to %s:25 on stream %d for circ %d.",
884 RELAY_COMMAND_BEGIN, payload,
885 payload_len, cpath_layer) < 0) {
887 "Failed to send pathbias probe cell on circuit %d.",
923 if (rh.
command == RELAY_COMMAND_END &&
924 reason == END_STREAM_REASON_EXITPOLICY &&
931 "Short path bias probe response length field (%d).", rh.
length);
932 return - END_CIRC_REASON_TORPROTOCOL;
941 circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
943 "Got valid path bias probe back for circ %d, stream %d.",
948 "Got strange probe value 0x%x vs 0x%x back for circ %d, "
955 "Got another cell back back on pathbias probe circuit %d: "
956 "Command: %d, Reason: %d, Stream-id: %d",
976 case RELAY_COMMAND_TRUNCATED:
986 case RELAY_COMMAND_END:
993 case RELAY_COMMAND_DATA:
1000 case RELAY_COMMAND_SENDME:
1007 case RELAY_COMMAND_CONNECTED:
1014 case RELAY_COMMAND_RESOLVED:
1053 "Circuit %d remote-closed without successful use for reason %d. "
1054 "Circuit purpose %d currently %d,%s. Len %d.",
1061 == END_CIRC_REASON_CHANNEL_CLOSED &&
1064 != CHANNEL_CLOSE_REQUESTED) {
1069 "Circuit %d's channel closed without successful use for reason "
1070 "%d, channel reason %d. Circuit purpose %d currently %d,%s. Len "
1095 "Circuit %d closed without successful use for reason %d. "
1096 "Circuit purpose %d currently %d,%s. Len %d.",
1131 entry_guard_t *guard = NULL;
1153 "Successfully closed circuit has no known guard. "
1154 "Circuit is a %s currently %s",
1171 entry_guard_t *guard = NULL;
1192 "Destroyed circuit has no known guard. "
1193 "Circuit is a %s currently %s",
1207 entry_guard_t *guard = NULL;
1229 "Stream-failing circuit has no known guard. "
1230 "Circuit is a %s currently %s",
1244 entry_guard_t *guard = NULL;
1280 int open_circuits = 0;
1286 circ->marked_for_close)
1300 log_debug(
LD_CIRC,
"Found opened circuit %d in path_state %s",
1306 SMARTLIST_FOREACH_END(circ);
1308 return open_circuits;
1371 "Guard %s is failing to carry an extremely large "
1372 "amount of stream on its circuits. "
1373 "To avoid potential route manipulation attacks, Tor has "
1374 "disabled use of this guard. "
1375 "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1376 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1377 "and %ld timed out. "
1378 "For reference, your timeout cutoff is %ld seconds.",
1395 "Guard %s is failing to carry an extremely large "
1396 "amount of streams on its circuits. "
1397 "This could indicate a route manipulation attack, network "
1398 "overload, bad local network connectivity, or a bug. "
1399 "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1400 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1401 "and %ld timed out. "
1402 "For reference, your timeout cutoff is %ld seconds.",
1419 "Guard %s is failing to carry more streams on its "
1420 "circuits than usual. "
1421 "Most likely this means the Tor network is overloaded "
1422 "or your network connection is poor. "
1423 "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1424 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1425 "and %ld timed out. "
1426 "For reference, your timeout cutoff is %ld seconds.",
1476 "Guard %s is failing an extremely large "
1477 "amount of circuits. "
1478 "To avoid potential route manipulation attacks, Tor has "
1479 "disabled use of this guard. "
1480 "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1481 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1482 "and %ld timed out. "
1483 "For reference, your timeout cutoff is %ld seconds.",
1500 "Guard %s is failing an extremely large "
1501 "amount of circuits. "
1502 "This could indicate a route manipulation attack, "
1503 "extreme network overload, or a bug. "
1504 "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1505 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1506 "and %ld timed out. "
1507 "For reference, your timeout cutoff is %ld seconds.",
1524 "Guard %s is failing a very large "
1525 "amount of circuits. "
1526 "Most likely this means the Tor network is "
1527 "overloaded, but it could also mean an attack against "
1528 "you or potentially the guard itself. "
1529 "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1530 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1531 "and %ld timed out. "
1532 "For reference, your timeout cutoff is %ld seconds.",
1549 "Guard %s is failing more circuits than "
1551 "Most likely this means the Tor network is overloaded. "
1552 "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1553 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1554 "and %ld timed out. "
1555 "For reference, your timeout cutoff is %ld seconds.",
1613 "Scaled pathbias counts to (%f,%f)/%f (%d/%d open) for guard "
1622 "Scaling has mangled pathbias counts to %f/%f (%d/%d open) "
1662 "Scaled pathbias use counts to %f/%f (%d open) for guard %s",
1669 "Scaling has mangled pathbias usage counts to %f/%f "
1670 "(%d open) for guard %s",
char * tor_dup_ip(uint32_t addr)
static uint8_t get_uint8(const void *cp)
static uint32_t get_uint32(const void *cp)
Fixed-size cell structure.
Header file for channel.c.
int pathbias_count_build_attempt(origin_circuit_t *circ)
double pathbias_get_extreme_use_rate(const or_options_t *options)
void pathbias_count_use_attempt(origin_circuit_t *circ)
static void pathbias_count_use_success(origin_circuit_t *circ)
static int pathbias_get_min_circs(const or_options_t *options)
static int pathbias_should_count(origin_circuit_t *circ)
void pathbias_count_valid_cells(circuit_t *circ, const cell_t *cell)
static int pathbias_get_min_use(const or_options_t *options)
int pathbias_check_close(origin_circuit_t *ocirc, int reason)
static double pathbias_get_warn_rate(const or_options_t *options)
static void pathbias_scale_use_rates(entry_guard_t *guard)
static void pathbias_count_collapse(origin_circuit_t *circ)
static double pathbias_get_notice_use_rate(const or_options_t *options)
static void pathbias_count_use_failed(origin_circuit_t *circ)
void pathbias_count_timeout(origin_circuit_t *circ)
static void pathbias_count_successful_close(origin_circuit_t *circ)
static int pathbias_is_new_circ_attempt(origin_circuit_t *circ)
double pathbias_get_extreme_rate(const or_options_t *options)
const char * pathbias_state_to_string(path_state_t state)
static int pathbias_send_usable_probe(circuit_t *circ)
void pathbias_mark_use_rollback(origin_circuit_t *circ)
double pathbias_get_use_success_count(entry_guard_t *guard)
static int pathbias_get_scale_use_threshold(const or_options_t *options)
static void pathbias_measure_use_rate(entry_guard_t *guard)
static double pathbias_get_notice_rate(const or_options_t *options)
static int entry_guard_inc_circ_attempt_count(entry_guard_t *guard)
static void pathbias_measure_close_rate(entry_guard_t *guard)
static int pathbias_count_circs_in_states(entry_guard_t *guard, path_state_t from, path_state_t to)
static double pathbias_get_scale_ratio(const or_options_t *options)
int pathbias_check_probe_response(circuit_t *circ, const cell_t *cell)
static int pathbias_get_scale_threshold(const or_options_t *options)
int pathbias_get_dropguards(const or_options_t *options)
static void pathbias_scale_close_rates(entry_guard_t *guard)
void pathbias_mark_use_success(origin_circuit_t *circ)
void pathbias_count_build_success(origin_circuit_t *circ)
double pathbias_get_close_success_count(entry_guard_t *guard)
int circuit_truncated(origin_circuit_t *circ, int reason)
Header file for circuitbuild.c.
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *x)
const char * circuit_state_to_string(int state)
const char * circuit_purpose_to_string(uint8_t purpose)
smartlist_t * circuit_get_global_list(void)
Header file for circuitlist.c.
#define CIRCUIT_PURPOSE_S_CONNECT_REND
#define CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT
#define CIRCUIT_PURPOSE_PATH_BIAS_TESTING
#define CIRCUIT_PURPOSE_CONTROLLER
#define CIRCUIT_IS_ORIGIN(c)
#define CIRCUIT_PURPOSE_TESTING
#define CIRCUIT_PURPOSE_S_REND_JOINED
#define CIRCUIT_PURPOSE_C_INTRODUCE_ACKED
#define CIRCUIT_PURPOSE_C_INTRODUCING
#define CIRCUIT_PURPOSE_CONFLUX_UNLINKED
double get_circuit_build_close_time_ms(void)
Header file for circuitstats.c.
void circuit_read_valid_data(origin_circuit_t *circ, uint16_t relay_body_len)
void circuit_change_purpose(circuit_t *circ, uint8_t new_purpose)
Header file for circuituse.c.
const or_options_t * get_options(void)
Header file for config.c.
int connection_half_edge_is_valid_data(const smartlist_t *half_conns, streamid_t stream_id)
int connection_half_edge_is_valid_end(smartlist_t *half_conns, streamid_t stream_id)
int connection_half_edge_is_valid_connected(const smartlist_t *half_conns, streamid_t stream_id)
int connection_half_edge_is_valid_resolved(smartlist_t *half_conns, streamid_t stream_id)
int connection_half_edge_is_valid_sendme(const smartlist_t *half_conns, streamid_t stream_id)
streamid_t get_unique_stream_id_by_circ(origin_circuit_t *circ)
Header file for connection_edge.c.
Circuit-build-stse structure.
Path structures for origin circuits.
void crypto_rand(char *to, size_t n)
Common functions for using (pseudo-)random number generators.
#define fast_memeq(a, b, c)
void entry_guards_changed(void)
entry_guard_t * entry_guard_get_by_id_digest(const char *digest)
const char * entry_guard_get_rsa_id_digest(const entry_guard_t *guard)
guard_pathbias_t * entry_guard_get_pathbias_state(entry_guard_t *guard)
const char * entry_guard_describe(const entry_guard_t *guard)
Header file for circuitbuild.c.
long tor_lround(double d)
int32_t networkstatus_get_param(const networkstatus_t *ns, const char *param_name, int32_t default_val, int32_t min_val, int32_t max_val)
Header file for networkstatus.c.
Master header file for Tor-specific functionality.
#define CELL_PAYLOAD_SIZE
#define RELAY_PAYLOAD_SIZE
#define END_CIRC_REASON_FLAG_REMOTE
#define RELAY_HEADER_SIZE
Origin circuit structure.
@ PATH_STATE_ALREADY_COUNTED
@ PATH_STATE_BUILD_ATTEMPTED
@ PATH_STATE_BUILD_SUCCEEDED
@ PATH_STATE_USE_SUCCEEDED
@ PATH_STATE_USE_ATTEMPTED
int tor_snprintf(char *str, size_t size, const char *format,...)
char * rate_limit_log(ratelim_t *lim, time_t now)
void relay_header_unpack(relay_header_t *dest, const uint8_t *src)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
uint8_t payload[CELL_PAYLOAD_SIZE]
char identity_digest[DIGEST_LEN]
enum channel_t::@8 reason_for_closing
struct timeval timestamp_began
unsigned int onehop_tunnel
struct crypt_path_t * prev
struct crypt_path_t * next
extend_info_t * extend_info
char identity_digest[DIGEST_LEN]
unsigned int path_bias_use_noticed
unsigned int path_bias_use_extreme
unsigned int path_bias_warned
unsigned int path_bias_extreme
double collapsed_circuits
unsigned int path_bias_disabled
double successful_circuits_closed
unsigned int path_bias_noticed
int PathBiasCircThreshold
uint32_t global_identifier
path_state_bitfield_t path_state
uint32_t pathbias_probe_nonce
unsigned int any_hop_from_controller
streamid_t pathbias_probe_id
cpath_build_state_t * build_state
uint8_t pathbias_shouldcount
smartlist_t * half_streams
void tor_gettimeofday(struct timeval *timeval)
#define tor_fragile_assert()