diff options
author | Mike Perry <mikeperry-git@fscked.org> | 2010-05-08 11:54:29 -0700 |
---|---|---|
committer | Mike Perry <mikeperry-git@fscked.org> | 2010-05-10 13:11:48 -0700 |
commit | 29e0d7081454c49cb6cab14685447aa811379a22 (patch) | |
tree | 63fdba604f448344672b1a17fc5f4f528ebac9a0 /src/or/circuitbuild.c | |
parent | 0a6191cf701617d51d30c468b5987b62ad75883c (diff) | |
download | tor-29e0d7081454c49cb6cab14685447aa811379a22.tar.gz tor-29e0d7081454c49cb6cab14685447aa811379a22.zip |
Bug 1296: Add option+logic to disable CBT learning.
There are now four ways that CBT can be disabled:
1. Network-wide, with the cbtdisabled consensus param.
2. Via config, with "LearnCircuitBuildTimeout 0"
3. Via config, with "AuthoritativeDirectory 1"
4. Via a state file write failure.
Diffstat (limited to 'src/or/circuitbuild.c')
-rw-r--r-- | src/or/circuitbuild.c | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c index 3600ce7c4d..4f79d32444 100644 --- a/src/or/circuitbuild.c +++ b/src/or/circuitbuild.c @@ -81,6 +81,28 @@ static int onion_append_hop(crypt_path_t **head_ptr, extend_info_t *choice); static void entry_guards_changed(void); +static int +circuit_build_times_disabled(void) +{ + int consensus_disabled = networkstatus_get_param(NULL, "cbtdisabled", + 0); + int config_disabled = !get_options()->LearnCircuitBuildTimeout; + int dirauth_disabled = get_options()->AuthoritativeDir; + int state_disabled = (get_or_state()->LastWritten == -1); + + if (consensus_disabled || config_disabled || dirauth_disabled || + state_disabled) { + log_info(LD_CIRC, + "CircuitBuildTime learning is disabled. " + "Consensus=%d, Config=%d, AuthDir=%d, StateFile=%d", + consensus_disabled, config_disabled, dirauth_disabled, + state_disabled); + return 1; + } else { + return 0; + } +} + static int32_t circuit_build_times_max_timeouts(void) { @@ -531,11 +553,16 @@ circuit_build_times_parse_state(circuit_build_times_t *cbt, uint32_t loaded_cnt = 0, N = 0; config_line_t *line; int i; - build_time_t *loaded_times = tor_malloc(sizeof(build_time_t) - * state->TotalBuildTimes); + build_time_t *loaded_times; circuit_build_times_init(cbt); *msg = NULL; + if (circuit_build_times_disabled()) { + return 0; + } + + loaded_times = tor_malloc(sizeof(build_time_t)*state->TotalBuildTimes); + for (line = state->BuildtimeHistogram; line; line = line->next) { smartlist_t *args = smartlist_create(); smartlist_split_string(args, line->value, " ", @@ -1020,6 +1047,11 @@ circuit_build_times_add_timeout(circuit_build_times_t *cbt, int did_onehop, time_t start_time) { + if (circuit_build_times_disabled()) { + cbt->timeout_ms = circuit_build_times_get_initial_timeout(); + return 0; + } + circuit_build_times_network_timeout(cbt, did_onehop, start_time); /* Only count timeouts if network is live.. */ @@ -1769,7 +1801,7 @@ circuit_send_next_onion_skin(origin_circuit_t *circ) if (timediff < 0 || timediff > 2*circ_times.timeout_ms+1000) { log_notice(LD_CIRC, "Strange value for circuit build time: %ld. " "Assuming clock jump.", timediff); - } else { + } else if (!circuit_build_times_disabled()) { circuit_build_times_add_time(&circ_times, (build_time_t)timediff); circuit_build_times_network_circ_success(&circ_times); circuit_build_times_set_timeout(&circ_times); |