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",
385 "One-hop circuit %d has length %d. Path state is %s. "
386 "Circuit is a %s currently %s.%s",
402 "One-hop circuit %d is now being ignored despite being counted "
403 "in the past. Purpose is %s, path state is %s",
416 "Circuit %d is not being counted by pathbias because it was "
417 "ignored in the past. Purpose is %s, path state is %s",
437 #define CIRC_ATTEMPT_NOTICE_INTERVAL (600)
438 static ratelim_t circ_attempt_notice_limit =
439 RATELIM_INIT(CIRC_ATTEMPT_NOTICE_INTERVAL);
440 char *rate_msg = NULL;
452 "Opened circuit %d is in strange path state %s. "
453 "Circuit is a %s currently %s.%s",
465 entry_guard_t *guard = NULL;
470 }
else if (circ->base_.
n_chan) {
481 return -END_CIRC_REASON_TORPROTOCOL;
487 "Unopened circuit %d has strange path state %s. "
488 "Circuit is a %s currently %s.%s",
501 "Unopened circuit has no known guard. "
502 "Circuit is a %s currently %s.%s",
525 #define SUCCESS_NOTICE_INTERVAL (600)
527 RATELIM_INIT(SUCCESS_NOTICE_INTERVAL);
528 char *rate_msg = NULL;
529 entry_guard_t *guard = NULL;
551 log_info(
LD_CIRC,
"Got success count %f/%f for guard %s",
558 "Succeeded circuit %d is in strange path state %s. "
559 "Circuit is a %s currently %s.%s",
570 log_notice(
LD_BUG,
"Unexpectedly high successes counts (%f/%f) "
582 "Completed circuit has no known guard. "
583 "Circuit is a %s currently %s.%s",
595 "Opened circuit %d is in strange path state %s. "
596 "Circuit is a %s currently %s.%s",
623 "Used circuit %d is in strange path state %s. "
624 "Circuit is a %s currently %s.",
641 "Marked circuit %d (%f/%f) as used for guard %s.",
651 "Used circuit %d is already in path state %s. "
652 "Circuit is a %s currently %s.",
680 "Used circuit %d is in strange path state %s. "
681 "Circuit is a %s currently %s.",
715 "Rolling back pathbias use state to 'attempted' for detached "
728 entry_guard_t *guard;
736 "Successfully used circuit %d is in strange path state %s. "
737 "Circuit is a %s currently %s.",
752 log_notice(
LD_BUG,
"Unexpectedly high use successes counts (%f/%f) "
759 "Marked circuit %d (%f/%f) as used successfully for guard %s",
794 char *probe_nonce = NULL;
800 if (cpath_layer->
state != CPATH_STATE_OPEN) {
804 "Got pathbias probe request for unopened circuit %d. "
814 "Got pathbias probe request for circuit %d with "
820 if (circ->
n_chan == NULL ||
821 (!CHANNEL_IS_OPEN(circ->
n_chan)
822 && !CHANNEL_IS_MAINT(circ->
n_chan))) {
824 "Skipping pathbias probe for circuit %d: Channel is not open.",
841 log_err(
LD_BUG,
"Failed to generate nonce");
846 payload_len = (int)strlen(payload)+1;
860 "Ran out of stream IDs on circuit %u during "
867 "Sending pathbias testing cell to %s:25 on stream %d for circ %d.",
873 RELAY_COMMAND_BEGIN, payload,
874 payload_len, cpath_layer) < 0) {
876 "Failed to send pathbias probe cell on circuit %d.",
912 if (rh.
command == RELAY_COMMAND_END &&
913 reason == END_STREAM_REASON_EXITPOLICY &&
920 "Short path bias probe response length field (%d).", rh.
length);
921 return - END_CIRC_REASON_TORPROTOCOL;
930 circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
932 "Got valid path bias probe back for circ %d, stream %d.",
937 "Got strange probe value 0x%x vs 0x%x back for circ %d, "
944 "Got another cell back back on pathbias probe circuit %d: "
945 "Command: %d, Reason: %d, Stream-id: %d",
965 case RELAY_COMMAND_TRUNCATED:
975 case RELAY_COMMAND_END:
982 case RELAY_COMMAND_DATA:
989 case RELAY_COMMAND_SENDME:
996 case RELAY_COMMAND_CONNECTED:
1003 case RELAY_COMMAND_RESOLVED:
1042 "Circuit %d remote-closed without successful use for reason %d. "
1043 "Circuit purpose %d currently %d,%s. Len %d.",
1050 == END_CIRC_REASON_CHANNEL_CLOSED &&
1053 != CHANNEL_CLOSE_REQUESTED) {
1058 "Circuit %d's channel closed without successful use for reason "
1059 "%d, channel reason %d. Circuit purpose %d currently %d,%s. Len "
1084 "Circuit %d closed without successful use for reason %d. "
1085 "Circuit purpose %d currently %d,%s. Len %d.",
1120 entry_guard_t *guard = NULL;
1142 "Successfully closed circuit has no known guard. "
1143 "Circuit is a %s currently %s",
1160 entry_guard_t *guard = NULL;
1181 "Destroyed circuit has no known guard. "
1182 "Circuit is a %s currently %s",
1196 entry_guard_t *guard = NULL;
1218 "Stream-failing circuit has no known guard. "
1219 "Circuit is a %s currently %s",
1233 entry_guard_t *guard = NULL;
1269 int open_circuits = 0;
1275 circ->marked_for_close)
1289 log_debug(
LD_CIRC,
"Found opened circuit %d in path_state %s",
1295 SMARTLIST_FOREACH_END(circ);
1297 return open_circuits;
1360 "Guard %s is failing to carry an extremely large "
1361 "amount of stream on its circuits. "
1362 "To avoid potential route manipulation attacks, Tor has "
1363 "disabled use of this guard. "
1364 "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1365 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1366 "and %ld timed out. "
1367 "For reference, your timeout cutoff is %ld seconds.",
1384 "Guard %s is failing to carry an extremely large "
1385 "amount of streams on its circuits. "
1386 "This could indicate a route manipulation attack, network "
1387 "overload, bad local network connectivity, or a bug. "
1388 "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1389 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1390 "and %ld timed out. "
1391 "For reference, your timeout cutoff is %ld seconds.",
1408 "Guard %s is failing to carry more streams on its "
1409 "circuits than usual. "
1410 "Most likely this means the Tor network is overloaded "
1411 "or your network connection is poor. "
1412 "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1413 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1414 "and %ld timed out. "
1415 "For reference, your timeout cutoff is %ld seconds.",
1465 "Guard %s is failing an extremely large "
1466 "amount of circuits. "
1467 "To avoid potential route manipulation attacks, Tor has "
1468 "disabled use of this guard. "
1469 "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1470 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1471 "and %ld timed out. "
1472 "For reference, your timeout cutoff is %ld seconds.",
1489 "Guard %s is failing an extremely large "
1490 "amount of circuits. "
1491 "This could indicate a route manipulation attack, "
1492 "extreme network overload, or a bug. "
1493 "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1494 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1495 "and %ld timed out. "
1496 "For reference, your timeout cutoff is %ld seconds.",
1513 "Guard %s is failing a very large "
1514 "amount of circuits. "
1515 "Most likely this means the Tor network is "
1516 "overloaded, but it could also mean an attack against "
1517 "you or potentially the guard itself. "
1518 "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1519 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1520 "and %ld timed out. "
1521 "For reference, your timeout cutoff is %ld seconds.",
1538 "Guard %s is failing more circuits than "
1540 "Most likely this means the Tor network is overloaded. "
1541 "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1542 "%ld circuits completed, %ld were unusable, %ld collapsed, "
1543 "and %ld timed out. "
1544 "For reference, your timeout cutoff is %ld seconds.",
1602 "Scaled pathbias counts to (%f,%f)/%f (%d/%d open) for guard "
1611 "Scaling has mangled pathbias counts to %f/%f (%d/%d open) "
1651 "Scaled pathbias use counts to %f/%f (%d open) for guard %s",
1658 "Scaling has mangled pathbias usage counts to %f/%f "
1659 "(%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
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()