diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-04-27 09:50:07 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-05-01 10:54:54 -0400 |
commit | 6868398b69f9651ad4d15892f19470500ef031d3 (patch) | |
tree | 52c157e5863fb783c0d95f9d9581bcf0d99c5317 /src/or/main.c | |
parent | 9870497f9df909c6a48a6f6c1e82171e99aa33a4 (diff) | |
download | tor-6868398b69f9651ad4d15892f19470500ef031d3.tar.gz tor-6868398b69f9651ad4d15892f19470500ef031d3.zip |
Move responsibility for voting into a separate periodic callback.
Closes ticket25937.
Diffstat (limited to 'src/or/main.c')
-rw-r--r-- | src/or/main.c | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/src/or/main.c b/src/or/main.c index b5ddfe6f23..8bc89817a4 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -1341,6 +1341,7 @@ CALLBACK(check_for_reachability_bw); CALLBACK(check_onion_keys_expiry_time); CALLBACK(clean_caches); CALLBACK(clean_consdiffmgr); +CALLBACK(dirvote); CALLBACK(downrate_stability); CALLBACK(expire_old_ciruits_serverside); CALLBACK(fetch_networkstatus); @@ -1402,6 +1403,7 @@ STATIC periodic_event_item_t periodic_events[] = { /* Directory authority only. */ CALLBACK(check_authority_cert, PERIODIC_EVENT_ROLE_DIRAUTH, 0), + CALLBACK(dirvote, PERIODIC_EVENT_ROLE_DIRAUTH, PERIODIC_EVENT_FLAG_NEED_NET), /* Relay only. */ CALLBACK(check_canonical_channels, PERIODIC_EVENT_ROLE_RELAY, @@ -1718,10 +1720,6 @@ run_scheduled_events(time_t now) accounting_run_housekeeping(now); } - if (authdir_mode_v3(options)) { - dirvote_act(options, now); - } - /* 3a. Every second, we examine pending circuits and prune the * ones which have been pending for more than a few seconds. * We do this before step 4, so it can try building more if @@ -1974,6 +1972,36 @@ check_authority_cert_callback(time_t now, const or_options_t *options) } /** + * Scheduled callback: Run directory-authority voting functionality. + * + * The schedule is a bit complicated here, so dirvote_act() manages the + * schedule itself. + **/ +static int +dirvote_callback(time_t now, const or_options_t *options) +{ + if (!authdir_mode_v3(options)) { + tor_assert_nonfatal_unreached(); + return 3600; + } + + time_t next = dirvote_act(options, now); + if (BUG(next == TIME_MAX)) { + /* This shouldn't be returned unless we called dirvote_act() without + * being an authority. If it happens, maybe our configuration will + * fix itself in an hour or so? */ + return 3600; + } + if (BUG(next <= now)) { + /* This case shouldn't be possible, since "next" is computed by + * dirvote_act() based on the value of "now" we give it. */ + return 1; + } else { + return next - now; + } +} + +/** * Periodic callback: If our consensus is too old, recalculate whether * we can actually use it. */ |