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.",
917 reason = msg->length > 0 ?
get_uint8(msg->body) : END_STREAM_REASON_MISC;
919 if (msg->command == RELAY_COMMAND_END &&
920 reason == END_STREAM_REASON_EXITPOLICY &&
925 if (msg->length < 9) {
927 "Short path bias probe response length field (%d).", msg->length);
928 return - END_CIRC_REASON_TORPROTOCOL;
937 circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
939 "Got valid path bias probe back for circ %d, stream %d.",
944 "Got strange probe value 0x%x vs 0x%x back for circ %d, "
951 "Got another cell back back on pathbias probe circuit %d: "
952 "Command: %d, Reason: %d, Stream-id: %d",
968 switch (msg->command) {
969 case RELAY_COMMAND_TRUNCATED:
978 case RELAY_COMMAND_END:
985 case RELAY_COMMAND_DATA:
992 case RELAY_COMMAND_SENDME:
999 case RELAY_COMMAND_CONNECTED:
1006 case RELAY_COMMAND_RESOLVED:
1045 "Circuit %d remote-closed without successful use for reason %d. "
1046 "Circuit purpose %d currently %d,%s. Len %d.",
1053 == END_CIRC_REASON_CHANNEL_CLOSED &&
1056 != CHANNEL_CLOSE_REQUESTED) {
1061 "Circuit %d's channel closed without successful use for reason "
1062 "%d, channel reason %d. Circuit purpose %d currently %d,%s. Len "
1087 "Circuit %d closed without successful use for reason %d. "
1088 "Circuit purpose %d currently %d,%s. Len %d.",
1123 entry_guard_t *guard = NULL;
1145 "Successfully closed circuit has no known guard. "
1146 "Circuit is a %s currently %s",
1163 entry_guard_t *guard = NULL;
1184 "Destroyed circuit has no known guard. "
1185 "Circuit is a %s currently %s",
1199 entry_guard_t *guard = NULL;
1221 "Stream-failing circuit has no known guard. "
1222 "Circuit is a %s currently %s",
1236 entry_guard_t *guard = NULL;
1272 int open_circuits = 0;
1278 circ->marked_for_close)
1292 log_debug(
LD_CIRC,
"Found opened circuit %d in path_state %s",
1298 SMARTLIST_FOREACH_END(circ);
1300 return open_circuits;
1363 "Guard %s is failing to carry an extremely large "
1364 "amount of stream on its circuits. "
1365 "To avoid potential route manipulation attacks, Tor has "
1366 "disabled use of this guard. "
1367 "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1368 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1369 "and %ld timed out. "
1370 "For reference, your timeout cutoff is %ld seconds.",
1387 "Guard %s is failing to carry an extremely large "
1388 "amount of streams on its circuits. "
1389 "This could indicate a route manipulation attack, network "
1390 "overload, bad local network connectivity, or a bug. "
1391 "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1392 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1393 "and %ld timed out. "
1394 "For reference, your timeout cutoff is %ld seconds.",
1411 "Guard %s is failing to carry more streams on its "
1412 "circuits than usual. "
1413 "Most likely this means the Tor network is overloaded "
1414 "or your network connection is poor. "
1415 "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1416 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1417 "and %ld timed out. "
1418 "For reference, your timeout cutoff is %ld seconds.",
1468 "Guard %s is failing an extremely large "
1469 "amount of circuits. "
1470 "To avoid potential route manipulation attacks, Tor has "
1471 "disabled use of this guard. "
1472 "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1473 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1474 "and %ld timed out. "
1475 "For reference, your timeout cutoff is %ld seconds.",
1492 "Guard %s is failing an extremely large "
1493 "amount of circuits. "
1494 "This could indicate a route manipulation attack, "
1495 "extreme network overload, or a bug. "
1496 "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1497 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1498 "and %ld timed out. "
1499 "For reference, your timeout cutoff is %ld seconds.",
1516 "Guard %s is failing a very large "
1517 "amount of circuits. "
1518 "Most likely this means the Tor network is "
1519 "overloaded, but it could also mean an attack against "
1520 "you or potentially the guard itself. "
1521 "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1522 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1523 "and %ld timed out. "
1524 "For reference, your timeout cutoff is %ld seconds.",
1541 "Guard %s is failing more circuits than "
1543 "Most likely this means the Tor network is overloaded. "
1544 "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1545 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1546 "and %ld timed out. "
1547 "For reference, your timeout cutoff is %ld seconds.",
1605 "Scaled pathbias counts to (%f,%f)/%f (%d/%d open) for guard "
1614 "Scaling has mangled pathbias counts to %f/%f (%d/%d open) "
1654 "Scaled pathbias use counts to %f/%f (%d open) for guard %s",
1661 "Scaling has mangled pathbias usage counts to %f/%f "
1662 "(%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)
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)
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)
void pathbias_count_valid_cells(circuit_t *circ, const relay_msg_t *msg)
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 relay_msg_t *msg)
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 END_CIRC_REASON_FLAG_REMOTE
#define RELAY_PAYLOAD_SIZE_MAX
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)
Header file for relay_msg.c.
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
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()