Move cbt->liveness.timeouts_after_firsthop free code into its own function

This commit is contained in:
Andrea Shepard 2012-06-12 19:27:37 -07:00 committed by Nick Mathewson
parent 825fb149cd
commit aa284561c8
2 changed files with 18 additions and 12 deletions

View File

@ -493,12 +493,7 @@ circuit_build_times_new_consensus_params(circuit_build_times_t *cbt,
"This disables adaptive timeouts since we can't keep track of "
"any recent circuits.");
if (cbt->liveness.timeouts_after_firsthop) {
tor_free(cbt->liveness.timeouts_after_firsthop);
cbt->liveness.timeouts_after_firsthop = NULL;
}
cbt->liveness.num_recent_circs = num;
circuit_build_times_free_timeouts(cbt);
}
} else {
/*
@ -509,12 +504,7 @@ circuit_build_times_new_consensus_params(circuit_build_times_t *cbt,
* if we have any.
*/
if (cbt->liveness.timeouts_after_firsthop) {
tor_free(cbt->liveness.timeouts_after_firsthop);
cbt->liveness.timeouts_after_firsthop = NULL;
}
cbt->liveness.num_recent_circs = 0;
circuit_build_times_free_timeouts(cbt);
}
}
@ -598,6 +588,21 @@ circuit_build_times_init(circuit_build_times_t *cbt)
control_event_buildtimeout_set(cbt, BUILDTIMEOUT_SET_EVENT_RESET);
}
/**
* Free the saved timeouts, if the cbtdisabled consensus parameter got turned
* on or something.
*/
void circuit_build_times_free_timeouts(circuit_build_times_t *cbt) {
if (!cbt) return;
if (cbt->liveness.timeouts_after_firsthop) {
tor_free(cbt->liveness.timeouts_after_firsthop);
}
cbt->liveness.num_recent_circs = 0;
}
#if 0
/**
* Rewind our build time history by n positions.

View File

@ -121,6 +121,7 @@ int circuit_build_times_needs_circuits(circuit_build_times_t *cbt);
int circuit_build_times_needs_circuits_now(circuit_build_times_t *cbt);
void circuit_build_times_init(circuit_build_times_t *cbt);
void circuit_build_times_free_timeouts(circuit_build_times_t *cbt);
void circuit_build_times_new_consensus_params(circuit_build_times_t *cbt,
networkstatus_t *ns);
double circuit_build_times_timeout_rate(const circuit_build_times_t *cbt);