Fix comments from Sebastian + Nick's code review.

Check for overflow in one place, and be consistent about type usage.
This commit is contained in:
Mike Perry 2010-05-10 19:56:27 -07:00
parent 29e0d70814
commit a5ac96b58d
2 changed files with 11 additions and 5 deletions

View File

@ -955,7 +955,7 @@ circuit_build_times_network_check_live(circuit_build_times_t *cbt)
}
return 0;
} else if (cbt->liveness.suspended_timeout) {
} else if (cbt->liveness.suspended_timeout > 0) {
log_notice(LD_CIRC,
"Network activity has resumed. "
"Resuming circuit timeout calculations.");
@ -1004,7 +1004,12 @@ circuit_build_times_network_check_changed(circuit_build_times_t *cbt)
/* Check to see if this has happened before. If so, double the timeout
* to give people on abysmally bad network connections a shot at access */
if (cbt->timeout_ms >= circuit_build_times_get_initial_timeout()) {
cbt->timeout_ms *= 2;
if (cbt->timeout_ms > INT32_MAX/2) {
log_warn(LD_CIRC, "Insanely large circuit build timeout value: %lf",
cbt->timeout_ms);
} else {
cbt->timeout_ms *= 2;
}
} else {
cbt->timeout_ms = circuit_build_times_get_initial_timeout();
}
@ -1100,7 +1105,7 @@ circuit_build_times_filter_timeouts(circuit_build_times_t *cbt)
}
timeout_rate = circuit_build_times_timeout_rate(cbt);
max_timeout = tor_lround(circuit_build_times_calculate_timeout(cbt,
max_timeout = (build_time_t)tor_lround(circuit_build_times_calculate_timeout(cbt,
circuit_build_times_max_synthetic_quantile()));
for (i = 0; i < CBT_NCIRCUITS_TO_OBSERVE; i++) {

View File

@ -3113,7 +3113,7 @@ typedef struct {
int after_firsthop_idx;
/** Timeout gathering is suspended if non-zero. The old timeout value
* is stored here in that case. */
build_time_t suspended_timeout;
double suspended_timeout;
} network_liveness_t;
/** Structure for circuit build times history */
@ -3137,7 +3137,8 @@ typedef struct {
double alpha;
/** Have we computed a timeout? */
int have_computed_timeout;
/** The exact value for that timeout in milliseconds */
/** The exact value for that timeout in milliseconds. Stored as a double
* to maintain precision from calculations to and from quantile value. */
double timeout_ms;
} circuit_build_times_t;