diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c index 04b429b2b6..cbc1af9618 100644 --- a/src/or/circuitbuild.c +++ b/src/or/circuitbuild.c @@ -1363,7 +1363,7 @@ pathbias_count_build_success(origin_circuit_t *circ) circ->path_state = PATH_STATE_BUILD_SUCCEEDED; guard->circ_successes++; - log_info(LD_CIRC, "Got success count %u/%u for guard %s=%s", + log_info(LD_CIRC, "Got success count %lf/%lf for guard %s=%s", guard->circ_successes, guard->circ_attempts, guard->nickname, hex_str(guard->identity, DIGEST_LEN)); } else { @@ -1381,7 +1381,7 @@ pathbias_count_build_success(origin_circuit_t *circ) } if (guard->circ_attempts < guard->circ_successes) { - log_notice(LD_BUG, "Unexpectedly high successes counts (%u/%u) " + log_notice(LD_BUG, "Unexpectedly high successes counts (%lf/%lf) " "for guard %s=%s", guard->circ_successes, guard->circ_attempts, guard->nickname, hex_str(guard->identity, DIGEST_LEN)); @@ -1607,7 +1607,7 @@ pathbias_count_timeout(origin_circuit_t *circ) } // XXX: DOCDOC -int +double pathbias_get_closed_count(entry_guard_t *guard) { circuit_t *circ = global_circuitlist; @@ -1642,7 +1642,7 @@ pathbias_get_closed_count(entry_guard_t *guard) * if it should return guard->circ_successes or * guard->successful_circuits_closed. */ -static int +static double pathbias_get_success_count(entry_guard_t *guard) { if (pathbias_use_close_counts(get_options())) { @@ -1663,11 +1663,11 @@ entry_guard_inc_circ_attempt_count(entry_guard_t *guard) entry_guards_changed(); - if (guard->circ_attempts > (unsigned)pathbias_get_min_circs(options)) { + if (guard->circ_attempts > pathbias_get_min_circs(options)) { /* Note: We rely on the < comparison here to allow us to set a 0 * rate and disable the feature entirely. If refactoring, don't * change to <= */ - if (pathbias_get_success_count(guard)/((double)guard->circ_attempts) + if (pathbias_get_success_count(guard)/guard->circ_attempts < pathbias_get_extreme_rate(options)) { /* Dropping is currently disabled by default. */ if (pathbias_get_dropguards(options)) { @@ -1680,9 +1680,9 @@ entry_guard_inc_circ_attempt_count(entry_guard_t *guard) "were unusable, %d collapsed, and %d timed out. For " "reference, your timeout cutoff is %ld seconds.", guard->nickname, hex_str(guard->identity, DIGEST_LEN), - pathbias_get_closed_count(guard), guard->circ_attempts, - guard->circ_successes, guard->unusable_circuits, - guard->collapsed_circuits, guard->timeouts, + (int)pathbias_get_closed_count(guard), (int)guard->circ_attempts, + (int)guard->circ_successes, (int)guard->unusable_circuits, + (int)guard->collapsed_circuits, (int)guard->timeouts, (long)circ_times.close_ms/1000); guard->path_bias_disabled = 1; guard->bad_since = approx_time(); @@ -1698,9 +1698,9 @@ entry_guard_inc_circ_attempt_count(entry_guard_t *guard) "were unusable, %d collapsed, and %d timed out. For " "reference, your timeout cutoff is %ld seconds.", guard->nickname, hex_str(guard->identity, DIGEST_LEN), - pathbias_get_closed_count(guard), guard->circ_attempts, - guard->circ_successes, guard->unusable_circuits, - guard->collapsed_circuits, guard->timeouts, + (int)pathbias_get_closed_count(guard), (int)guard->circ_attempts, + (int)guard->circ_successes, (int)guard->unusable_circuits, + (int)guard->collapsed_circuits, (int)guard->timeouts, (long)circ_times.close_ms/1000); } } else if (pathbias_get_success_count(guard)/((double)guard->circ_attempts) @@ -1716,9 +1716,9 @@ entry_guard_inc_circ_attempt_count(entry_guard_t *guard) "were unusable, %d collapsed, and %d timed out. For " "reference, your timeout cutoff is %ld seconds.", guard->nickname, hex_str(guard->identity, DIGEST_LEN), - pathbias_get_closed_count(guard), guard->circ_attempts, - guard->circ_successes, guard->unusable_circuits, - guard->collapsed_circuits, guard->timeouts, + (int)pathbias_get_closed_count(guard), (int)guard->circ_attempts, + (int)guard->circ_successes, (int)guard->unusable_circuits, + (int)guard->collapsed_circuits, (int)guard->timeouts, (long)circ_times.close_ms/1000); } } else if (pathbias_get_success_count(guard)/((double)guard->circ_attempts) @@ -1732,45 +1732,40 @@ entry_guard_inc_circ_attempt_count(entry_guard_t *guard) "were unusable, %d collapsed, and %d timed out. For " "reference, your timeout cutoff is %ld seconds.", guard->nickname, hex_str(guard->identity, DIGEST_LEN), - pathbias_get_closed_count(guard), guard->circ_attempts, - guard->circ_successes, guard->unusable_circuits, - guard->collapsed_circuits, guard->timeouts, + (int)pathbias_get_closed_count(guard), (int)guard->circ_attempts, + (int)guard->circ_successes, (int)guard->unusable_circuits, + (int)guard->collapsed_circuits, (int)guard->timeouts, (long)circ_times.close_ms/1000); } } } /* If we get a ton of circuits, just scale everything down */ - if (guard->circ_attempts > (unsigned)pathbias_get_scale_threshold(options)) { + if (guard->circ_attempts > pathbias_get_scale_threshold(options)) { const int scale_factor = pathbias_get_scale_factor(options); const int mult_factor = pathbias_get_mult_factor(options); - /* Only scale if there will be no rounding error for our scaling - * factors */ - if (((mult_factor*guard->circ_attempts) % scale_factor) == 0 && - ((mult_factor*guard->circ_successes) % scale_factor) == 0) { - log_info(LD_CIRC, - "Scaling pathbias counts to (%u/%u)*(%d/%d) for guard %s=%s", - guard->circ_successes, guard->circ_attempts, mult_factor, - scale_factor, guard->nickname, hex_str(guard->identity, - DIGEST_LEN)); + log_info(LD_CIRC, + "Scaling pathbias counts to (%lf/%lf)*(%d/%d) for guard %s=%s", + guard->circ_successes, guard->circ_attempts, + mult_factor, scale_factor, guard->nickname, + hex_str(guard->identity, DIGEST_LEN)); - guard->circ_attempts *= mult_factor; - guard->circ_successes *= mult_factor; - guard->timeouts *= mult_factor; - guard->successful_circuits_closed *= mult_factor; - guard->collapsed_circuits *= mult_factor; - guard->unusable_circuits *= mult_factor; + guard->circ_attempts *= mult_factor; + guard->circ_successes *= mult_factor; + guard->timeouts *= mult_factor; + guard->successful_circuits_closed *= mult_factor; + guard->collapsed_circuits *= mult_factor; + guard->unusable_circuits *= mult_factor; - guard->circ_attempts /= scale_factor; - guard->circ_successes /= scale_factor; - guard->timeouts /= scale_factor; - guard->successful_circuits_closed /= scale_factor; - guard->collapsed_circuits /= scale_factor; - guard->unusable_circuits /= scale_factor; - } + guard->circ_attempts /= scale_factor; + guard->circ_successes /= scale_factor; + guard->timeouts /= scale_factor; + guard->successful_circuits_closed /= scale_factor; + guard->collapsed_circuits /= scale_factor; + guard->unusable_circuits /= scale_factor; } guard->circ_attempts++; - log_info(LD_CIRC, "Got success count %u/%u for guard %s=%s", + log_info(LD_CIRC, "Got success count %lf/%lf for guard %s=%s", guard->circ_successes, guard->circ_attempts, guard->nickname, hex_str(guard->identity, DIGEST_LEN)); return 0; diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c index 84764d1869..21c09f79c3 100644 --- a/src/or/entrynodes.c +++ b/src/or/entrynodes.c @@ -1021,7 +1021,7 @@ entry_guards_parse_state(or_state_t *state, int set, char **msg) digestmap_set(added_by, d, tor_strdup(line->value+HEX_DIGEST_LEN+1)); } else if (!strcasecmp(line->key, "EntryGuardPathBias")) { const or_options_t *options = get_options(); - unsigned hop_cnt, success_cnt, timeouts, collapsed, successful_closed, + double hop_cnt, success_cnt, timeouts, collapsed, successful_closed, unusable; if (!node) { @@ -1031,20 +1031,22 @@ entry_guards_parse_state(or_state_t *state, int set, char **msg) } /* First try 3 params, then 2. */ - // XXX: We want to convert this to floating point before merge /* In the long run: circuit_success ~= successful_circuit_close + * collapsed_circuits + * unusable_circuits */ - if (tor_sscanf(line->value, "%u %u %u %u %u %u", + if (tor_sscanf(line->value, "%lf %lf %lf %lf %lf %lf", &hop_cnt, &success_cnt, &successful_closed, &collapsed, &unusable, &timeouts) != 6) { - if (tor_sscanf(line->value, "%u %u", &success_cnt, &hop_cnt) != 2) { + int old_success, old_hops; + if (tor_sscanf(line->value, "%u %u", &old_success, &old_hops) != 2) { continue; } log_info(LD_GENERAL, "Reading old-style EntryGuardPathBias %s", escaped(line->value)); - successful_closed = success_cnt; + success_cnt = old_success; + successful_closed = old_success; + hop_cnt = old_hops; timeouts = 0; collapsed = 0; unusable = 0; @@ -1058,7 +1060,7 @@ entry_guards_parse_state(or_state_t *state, int set, char **msg) node->collapsed_circuits = collapsed; node->unusable_circuits = unusable; - log_info(LD_GENERAL, "Read %u/%u path bias for node %s", + log_info(LD_GENERAL, "Read %lf/%lf path bias for node %s", node->circ_successes, node->circ_attempts, node->nickname); /* Note: We rely on the < comparison here to allow us to set a 0 * rate and disable the feature entirely. If refactoring, don't @@ -1068,7 +1070,7 @@ entry_guards_parse_state(or_state_t *state, int set, char **msg) pathbias_get_dropguards(options)) { node->path_bias_disabled = 1; log_info(LD_GENERAL, - "Path bias is too high (%u/%u); disabling node %s", + "Path bias is too high (%lf/%lf); disabling node %s", node->circ_successes, node->circ_attempts, node->nickname); } @@ -1198,7 +1200,7 @@ entry_guards_update_state(or_state_t *state) /* In the long run: circuit_success ~= successful_circuit_close + * collapsed_circuits + * unusable_circuits */ - tor_asprintf(&line->value, "%u %u %u %u %u %u", + tor_asprintf(&line->value, "%lf %lf %lf %lf %lf %lf", e->circ_attempts, e->circ_successes, pathbias_get_closed_count(e), e->collapsed_circuits, e->unusable_circuits, e->timeouts); diff --git a/src/or/entrynodes.h b/src/or/entrynodes.h index 0e58802cbe..de8c60c33d 100644 --- a/src/or/entrynodes.h +++ b/src/or/entrynodes.h @@ -48,17 +48,17 @@ typedef struct entry_guard_t { time_t last_attempted; /**< 0 if we can connect to this guard, or the time * at which we last failed to connect to it. */ - unsigned circ_attempts; /**< Number of circuits this guard has "attempted" */ - unsigned circ_successes; /**< Number of successfully built circuits using + double circ_attempts; /**< Number of circuits this guard has "attempted" */ + double circ_successes; /**< Number of successfully built circuits using * this guard as first hop. */ - unsigned successful_circuits_closed; /**< Number of circuits that carried + double successful_circuits_closed; /**< Number of circuits that carried * streams successfully. */ - unsigned collapsed_circuits; /**< Number of fully built circuits that were + double collapsed_circuits; /**< Number of fully built circuits that were * remotely closed before any streams were * attempted. */ - unsigned unusable_circuits; /**< Number of circuits for which streams were + double unusable_circuits; /**< Number of circuits for which streams were * attempted, but none succeeded. */ - unsigned timeouts; /**< Number of 'right-censored' circuit timeouts for this + double timeouts; /**< Number of 'right-censored' circuit timeouts for this * guard. */ } entry_guard_t; @@ -111,7 +111,7 @@ int find_transport_by_bridge_addrport(const tor_addr_t *addr, uint16_t port, int validate_pluggable_transports_config(void); -int pathbias_get_closed_count(entry_guard_t *gaurd); +double pathbias_get_closed_count(entry_guard_t *gaurd); #endif