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;
356 "Circuit %d is now being ignored despite being counted "
357 "in the past. Purpose is %s, path state is %s",
374 "One-hop circuit %d has length %d. Path state is %s. "
375 "Circuit is a %s currently %s.%s",
391 "One-hop circuit %d is now being ignored despite being counted "
392 "in the past. Purpose is %s, path state is %s",
405 "Circuit %d is not being counted by pathbias because it was "
406 "ignored in the past. Purpose is %s, path state is %s",
426 #define CIRC_ATTEMPT_NOTICE_INTERVAL (600)
427 static ratelim_t circ_attempt_notice_limit =
428 RATELIM_INIT(CIRC_ATTEMPT_NOTICE_INTERVAL);
429 char *rate_msg = NULL;
441 "Opened circuit %d is in strange path state %s. "
442 "Circuit is a %s currently %s.%s",
454 entry_guard_t *guard = NULL;
459 }
else if (circ->base_.
n_chan) {
470 return -END_CIRC_REASON_TORPROTOCOL;
476 "Unopened circuit %d has strange path state %s. "
477 "Circuit is a %s currently %s.%s",
490 "Unopened circuit has no known guard. "
491 "Circuit is a %s currently %s.%s",
514 #define SUCCESS_NOTICE_INTERVAL (600)
516 RATELIM_INIT(SUCCESS_NOTICE_INTERVAL);
517 char *rate_msg = NULL;
518 entry_guard_t *guard = NULL;
540 log_info(
LD_CIRC,
"Got success count %f/%f for guard %s",
547 "Succeeded circuit %d is in strange path state %s. "
548 "Circuit is a %s currently %s.%s",
559 log_notice(
LD_BUG,
"Unexpectedly high successes counts (%f/%f) "
571 "Completed circuit has no known guard. "
572 "Circuit is a %s currently %s.%s",
584 "Opened circuit %d is in strange path state %s. "
585 "Circuit is a %s currently %s.%s",
612 "Used circuit %d is in strange path state %s. "
613 "Circuit is a %s currently %s.",
630 "Marked circuit %d (%f/%f) as used for guard %s.",
640 "Used circuit %d is already in path state %s. "
641 "Circuit is a %s currently %s.",
669 "Used circuit %d is in strange path state %s. "
670 "Circuit is a %s currently %s.",
704 "Rolling back pathbias use state to 'attempted' for detached "
717 entry_guard_t *guard;
725 "Successfully used circuit %d is in strange path state %s. "
726 "Circuit is a %s currently %s.",
741 log_notice(
LD_BUG,
"Unexpectedly high use successes counts (%f/%f) "
748 "Marked circuit %d (%f/%f) as used successfully for guard %s",
783 char *probe_nonce = NULL;
789 if (cpath_layer->
state != CPATH_STATE_OPEN) {
793 "Got pathbias probe request for unopened circuit %d. "
803 "Got pathbias probe request for circuit %d with "
809 if (circ->
n_chan == NULL ||
810 (!CHANNEL_IS_OPEN(circ->
n_chan)
811 && !CHANNEL_IS_MAINT(circ->
n_chan))) {
813 "Skipping pathbias probe for circuit %d: Channel is not open.",
830 log_err(
LD_BUG,
"Failed to generate nonce");
835 payload_len = (int)strlen(payload)+1;
849 "Ran out of stream IDs on circuit %u during "
856 "Sending pathbias testing cell to %s:25 on stream %d for circ %d.",
862 RELAY_COMMAND_BEGIN, payload,
863 payload_len, cpath_layer) < 0) {
865 "Failed to send pathbias probe cell on circuit %d.",
901 if (rh.
command == RELAY_COMMAND_END &&
902 reason == END_STREAM_REASON_EXITPOLICY &&
909 "Short path bias probe response length field (%d).", rh.
length);
910 return - END_CIRC_REASON_TORPROTOCOL;
919 circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
921 "Got valid path bias probe back for circ %d, stream %d.",
926 "Got strange probe value 0x%x vs 0x%x back for circ %d, "
933 "Got another cell back back on pathbias probe circuit %d: "
934 "Command: %d, Reason: %d, Stream-id: %d",
954 case RELAY_COMMAND_TRUNCATED:
964 case RELAY_COMMAND_END:
971 case RELAY_COMMAND_DATA:
978 case RELAY_COMMAND_SENDME:
985 case RELAY_COMMAND_CONNECTED:
992 case RELAY_COMMAND_RESOLVED:
1031 "Circuit %d remote-closed without successful use for reason %d. "
1032 "Circuit purpose %d currently %d,%s. Len %d.",
1039 == END_CIRC_REASON_CHANNEL_CLOSED &&
1042 != CHANNEL_CLOSE_REQUESTED) {
1047 "Circuit %d's channel closed without successful use for reason "
1048 "%d, channel reason %d. Circuit purpose %d currently %d,%s. Len "
1073 "Circuit %d closed without successful use for reason %d. "
1074 "Circuit purpose %d currently %d,%s. Len %d.",
1109 entry_guard_t *guard = NULL;
1131 "Successfully closed circuit has no known guard. "
1132 "Circuit is a %s currently %s",
1149 entry_guard_t *guard = NULL;
1170 "Destroyed circuit has no known guard. "
1171 "Circuit is a %s currently %s",
1185 entry_guard_t *guard = NULL;
1207 "Stream-failing circuit has no known guard. "
1208 "Circuit is a %s currently %s",
1222 entry_guard_t *guard = NULL;
1258 int open_circuits = 0;
1264 circ->marked_for_close)
1278 log_debug(
LD_CIRC,
"Found opened circuit %d in path_state %s",
1284 SMARTLIST_FOREACH_END(circ);
1286 return open_circuits;
1349 "Guard %s is failing to carry an extremely large "
1350 "amount of stream on its circuits. "
1351 "To avoid potential route manipulation attacks, Tor has "
1352 "disabled use of this guard. "
1353 "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1354 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1355 "and %ld timed out. "
1356 "For reference, your timeout cutoff is %ld seconds.",
1373 "Guard %s is failing to carry an extremely large "
1374 "amount of streams on its circuits. "
1375 "This could indicate a route manipulation attack, network "
1376 "overload, bad local network connectivity, or a bug. "
1377 "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1378 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1379 "and %ld timed out. "
1380 "For reference, your timeout cutoff is %ld seconds.",
1397 "Guard %s is failing to carry more streams on its "
1398 "circuits than usual. "
1399 "Most likely this means the Tor network is overloaded "
1400 "or your network connection is poor. "
1401 "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1402 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1403 "and %ld timed out. "
1404 "For reference, your timeout cutoff is %ld seconds.",
1454 "Guard %s is failing an extremely large "
1455 "amount of circuits. "
1456 "To avoid potential route manipulation attacks, Tor has "
1457 "disabled use of this guard. "
1458 "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1459 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1460 "and %ld timed out. "
1461 "For reference, your timeout cutoff is %ld seconds.",
1478 "Guard %s is failing an extremely large "
1479 "amount of circuits. "
1480 "This could indicate a route manipulation attack, "
1481 "extreme network overload, or a bug. "
1482 "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1483 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1484 "and %ld timed out. "
1485 "For reference, your timeout cutoff is %ld seconds.",
1502 "Guard %s is failing a very large "
1503 "amount of circuits. "
1504 "Most likely this means the Tor network is "
1505 "overloaded, but it could also mean an attack against "
1506 "you or potentially the guard itself. "
1507 "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1508 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1509 "and %ld timed out. "
1510 "For reference, your timeout cutoff is %ld seconds.",
1527 "Guard %s is failing more circuits than "
1529 "Most likely this means the Tor network is overloaded. "
1530 "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1531 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1532 "and %ld timed out. "
1533 "For reference, your timeout cutoff is %ld seconds.",
1591 "Scaled pathbias counts to (%f,%f)/%f (%d/%d open) for guard "
1600 "Scaling has mangled pathbias counts to %f/%f (%d/%d open) "
1640 "Scaled pathbias use counts to %f/%f (%d open) for guard %s",
1647 "Scaling has mangled pathbias usage counts to %f/%f "
1648 "(%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)
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)
const char * pathbias_state_to_string(path_state_t state)
double pathbias_get_close_success_count(entry_guard_t *guard)
int circuit_truncated(origin_circuit_t *circ, int reason)
Header file for circuitbuild.c.
const char * circuit_purpose_to_string(uint8_t purpose)
smartlist_t * circuit_get_global_list(void)
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *x)
const char * circuit_state_to_string(int state)
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
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)
entry_guard_t * entry_guard_get_by_id_digest(const char *digest)
void entry_guards_changed(void)
guard_pathbias_t * entry_guard_get_pathbias_state(entry_guard_t *guard)
const char * entry_guard_describe(const entry_guard_t *guard)
const char * entry_guard_get_rsa_id_digest(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
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()