Separate mutable/const accessors for circuit_build_times

(These have proved invaluable for other global accessors.)
This commit is contained in:
Nick Mathewson 2013-08-21 12:10:05 -04:00
parent e1c9b43b8e
commit 775c491502
10 changed files with 40 additions and 31 deletions

View File

@ -2361,7 +2361,7 @@ channel_do_open_actions(channel_t *chan)
started_here = channel_is_outgoing(chan);
if (started_here) {
circuit_build_times_network_is_live(get_circuit_build_times());
circuit_build_times_network_is_live(get_circuit_build_times_mutable());
rep_hist_note_connect_succeeded(chan->identity_digest, now);
if (entry_guard_register_connect_status(
chan->identity_digest, 1, 0, now) < 0) {

View File

@ -782,14 +782,14 @@ circuit_send_next_onion_skin(origin_circuit_t *circ)
/* Only count circuit times if the network is live */
if (circuit_build_times_network_check_live(
get_circuit_build_times())) {
circuit_build_times_add_time(get_circuit_build_times(),
circuit_build_times_add_time(get_circuit_build_times_mutable(),
(build_time_t)timediff);
circuit_build_times_set_timeout(get_circuit_build_times());
circuit_build_times_set_timeout(get_circuit_build_times_mutable());
}
if (circ->base_.purpose != CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
circuit_build_times_network_circ_success(
get_circuit_build_times());
get_circuit_build_times_mutable());
}
}
}

View File

@ -678,7 +678,7 @@ origin_circuit_new(void)
init_circuit_base(TO_CIRCUIT(circ));
get_circuit_build_times()->last_circ_at = approx_time();
get_circuit_build_times_mutable()->last_circ_at = approx_time();
return circ;
}

View File

@ -36,12 +36,18 @@ static int unit_tests = 0;
#define unit_tests 0
#endif
circuit_build_times_t *
const circuit_build_times_t *
get_circuit_build_times(void)
{
return &circ_times;
}
circuit_build_times_t *
get_circuit_build_times_mutable(void)
{
return &circ_times;
}
double
get_circuit_build_close_time_ms(void)
{
@ -175,7 +181,7 @@ circuit_build_times_min_circs_to_observe(void)
/** Return true iff <b>cbt</b> has recorded enough build times that we
* want to start acting on the timeout it implies. */
int
circuit_build_times_enough_to_compute(circuit_build_times_t *cbt)
circuit_build_times_enough_to_compute(const circuit_build_times_t *cbt)
{
return cbt->total_build_times >= circuit_build_times_min_circs_to_observe();
}
@ -578,7 +584,7 @@ circuit_build_times_add_time(circuit_build_times_t *cbt, build_time_t time)
* Return maximum circuit build time
*/
static build_time_t
circuit_build_times_max(circuit_build_times_t *cbt)
circuit_build_times_max(const circuit_build_times_t *cbt)
{
int i = 0;
build_time_t max_build_time = 0;
@ -619,7 +625,7 @@ circuit_build_times_min(circuit_build_times_t *cbt)
* The return value must be freed by the caller.
*/
static uint32_t *
circuit_build_times_create_histogram(circuit_build_times_t *cbt,
circuit_build_times_create_histogram(const circuit_build_times_t *cbt,
build_time_t *nbins)
{
uint32_t *histogram;
@ -709,7 +715,7 @@ circuit_build_times_get_xm(circuit_build_times_t *cbt)
* the or_state_t state structure.
*/
void
circuit_build_times_update_state(circuit_build_times_t *cbt,
circuit_build_times_update_state(const circuit_build_times_t *cbt,
or_state_t *state)
{
uint32_t *histogram;
@ -1146,7 +1152,7 @@ circuit_build_times_initial_alpha(circuit_build_times_t *cbt,
* Returns true if we need circuits to be built
*/
int
circuit_build_times_needs_circuits(circuit_build_times_t *cbt)
circuit_build_times_needs_circuits(const circuit_build_times_t *cbt)
{
/* Return true if < MIN_CIRCUITS_TO_OBSERVE */
return !circuit_build_times_enough_to_compute(cbt);
@ -1157,7 +1163,7 @@ circuit_build_times_needs_circuits(circuit_build_times_t *cbt)
* right now.
*/
int
circuit_build_times_needs_circuits_now(circuit_build_times_t *cbt)
circuit_build_times_needs_circuits_now(const circuit_build_times_t *cbt)
{
return circuit_build_times_needs_circuits(cbt) &&
approx_time()-cbt->last_circ_at > circuit_build_times_test_frequency();
@ -1290,7 +1296,7 @@ circuit_build_times_network_close(circuit_build_times_t *cbt,
* in the case of recent liveness changes.
*/
int
circuit_build_times_network_check_live(circuit_build_times_t *cbt)
circuit_build_times_network_check_live(const circuit_build_times_t *cbt)
{
if (cbt->liveness.nonlive_timeouts > 0) {
return 0;

View File

@ -12,13 +12,14 @@
#ifndef TOR_CIRCUITSTATS_H
#define TOR_CIRCUITSTATS_H
circuit_build_times_t *get_circuit_build_times(void);
const circuit_build_times_t *get_circuit_build_times(void);
circuit_build_times_t *get_circuit_build_times_mutable(void);
double get_circuit_build_close_time_ms(void);
double get_circuit_build_timeout_ms(void);
int circuit_build_times_disabled(void);
int circuit_build_times_enough_to_compute(circuit_build_times_t *cbt);
void circuit_build_times_update_state(circuit_build_times_t *cbt,
int circuit_build_times_enough_to_compute(const circuit_build_times_t *cbt);
void circuit_build_times_update_state(const circuit_build_times_t *cbt,
or_state_t *state);
int circuit_build_times_parse_state(circuit_build_times_t *cbt,
or_state_t *state);
@ -29,9 +30,9 @@ int circuit_build_times_count_close(circuit_build_times_t *cbt,
void circuit_build_times_set_timeout(circuit_build_times_t *cbt);
int circuit_build_times_add_time(circuit_build_times_t *cbt,
build_time_t time);
int circuit_build_times_needs_circuits(circuit_build_times_t *cbt);
int circuit_build_times_needs_circuits(const circuit_build_times_t *cbt);
int circuit_build_times_needs_circuits_now(circuit_build_times_t *cbt);
int circuit_build_times_needs_circuits_now(const 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,
@ -61,7 +62,7 @@ void circuitbuild_running_unit_tests(void);
/* Network liveness functions */
void circuit_build_times_network_is_live(circuit_build_times_t *cbt);
int circuit_build_times_network_check_live(circuit_build_times_t *cbt);
int circuit_build_times_network_check_live(const circuit_build_times_t *cbt);
void circuit_build_times_network_circ_success(circuit_build_times_t *cbt);
#endif

View File

@ -545,7 +545,7 @@ circuit_expire_building(void)
* was a timeout, and the timeout value needs to reset if we
* see enough of them. Note this means we also need to avoid
* double-counting below, too. */
circuit_build_times_count_timeout(get_circuit_build_times(),
circuit_build_times_count_timeout(get_circuit_build_times_mutable(),
first_hop_succeeded);
TO_ORIGIN_CIRCUIT(victim)->relaxed_timeout = 1;
}
@ -658,8 +658,9 @@ circuit_expire_building(void)
* have a timeout. We also want to avoid double-counting
* already "relaxed" circuits, which are counted above. */
if (!TO_ORIGIN_CIRCUIT(victim)->relaxed_timeout) {
circuit_build_times_count_timeout(get_circuit_build_times(),
first_hop_succeeded);
circuit_build_times_count_timeout(
get_circuit_build_times_mutable(),
first_hop_succeeded);
}
continue;
}
@ -676,10 +677,11 @@ circuit_expire_building(void)
(long)(now.tv_sec - victim->timestamp_began.tv_sec),
victim->purpose,
circuit_purpose_to_string(victim->purpose));
} else if (circuit_build_times_count_close(get_circuit_build_times(),
} else if (circuit_build_times_count_close(
get_circuit_build_times_mutable(),
first_hop_succeeded,
victim->timestamp_created.tv_sec)) {
circuit_build_times_set_timeout(get_circuit_build_times());
circuit_build_times_set_timeout(get_circuit_build_times_mutable());
}
}
}

View File

@ -1749,7 +1749,7 @@ connection_tls_finish_handshake(or_connection_t *conn)
digest_rcvd) < 0)
return -1;
circuit_build_times_network_is_live(get_circuit_build_times());
circuit_build_times_network_is_live(get_circuit_build_times_mutable());
if (tor_tls_used_v1_handshake(conn->tls)) {
conn->link_proto = 1;
@ -1783,7 +1783,7 @@ connection_or_launch_v3_or_handshake(or_connection_t *conn)
tor_assert(connection_or_nonopen_was_started_here(conn));
tor_assert(tor_tls_received_v3_certificate(conn->tls));
circuit_build_times_network_is_live(get_circuit_build_times());
circuit_build_times_network_is_live(get_circuit_build_times_mutable());
connection_or_change_state(conn, OR_CONN_STATE_OR_HANDSHAKING_V3);
if (connection_init_or_handshake_state(conn, 1) < 0)
@ -2016,7 +2016,7 @@ connection_or_process_cells_from_inbuf(or_connection_t *conn)
if (conn->chan)
channel_timestamp_active(TLS_CHAN_TO_BASE(conn->chan));
circuit_build_times_network_is_live(get_circuit_build_times());
circuit_build_times_network_is_live(get_circuit_build_times_mutable());
channel_tls_handle_var_cell(var_cell, conn);
var_cell_free(var_cell);
} else {
@ -2032,7 +2032,7 @@ connection_or_process_cells_from_inbuf(or_connection_t *conn)
if (conn->chan)
channel_timestamp_active(TLS_CHAN_TO_BASE(conn->chan));
circuit_build_times_network_is_live(get_circuit_build_times());
circuit_build_times_network_is_live(get_circuit_build_times_mutable());
connection_fetch_from_buf(buf, cell_network_size, TO_CONN(conn));
/* retrieve cell info from buf (create the host-order struct from the

View File

@ -2279,6 +2279,6 @@ entry_guards_free_all(void)
clear_bridge_list();
smartlist_free(bridge_list);
bridge_list = NULL;
circuit_build_times_free_timeouts(get_circuit_build_times());
circuit_build_times_free_timeouts(get_circuit_build_times_mutable());
}

View File

@ -1822,7 +1822,7 @@ networkstatus_set_current_consensus(const char *consensus,
* current consensus really alter our view of any OR's rate limits? */
connection_or_update_token_buckets(get_connection_array(), options);
circuit_build_times_new_consensus_params(get_circuit_build_times(),
circuit_build_times_new_consensus_params(get_circuit_build_times_mutable(),
current_consensus);
}

View File

@ -239,7 +239,7 @@ or_state_set(or_state_t *new_state)
ret = -1;
}
if (circuit_build_times_parse_state(
get_circuit_build_times(),global_state) < 0) {
get_circuit_build_times_mutable(),global_state) < 0) {
ret = -1;
}
return ret;