Convert to doubles for all pathbias state.

Let's hope this solves the rounding error issue..
This commit is contained in:
Mike Perry 2012-12-09 20:53:22 -08:00
parent ab1fce5c19
commit 2dbb62f1b5
3 changed files with 54 additions and 57 deletions

View File

@ -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,27 +1732,23 @@ 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));
"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;
@ -1768,9 +1764,8 @@ entry_guard_inc_circ_attempt_count(entry_guard_t *guard)
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;

View File

@ -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);

View File

@ -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