From: Nick Mathewson Date: Tue, 13 Nov 2018 14:30:51 +0000 (-0500) Subject: Turn second_elapsed_callback into a normal periodic event. X-Git-Tag: tor-0.4.0.1-alpha~119^2~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4bf79fa4fa99fe66f6b1ad413cbf475325803e04;p=thirdparty%2Ftor.git Turn second_elapsed_callback into a normal periodic event. --- diff --git a/src/app/config/config.c b/src/app/config/config.c index 45a23d67d5..8aa0c1f4bd 100644 --- a/src/app/config/config.c +++ b/src/app/config/config.c @@ -1993,9 +1993,6 @@ options_act(const or_options_t *old_options) finish_daemon(options->DataDirectory); } - /* See whether we need to enable/disable our once-a-second timer. */ - reschedule_per_second_timer(); - /* We want to reinit keys as needed before we do much of anything else: keys are important, and other things can depend on them. */ if (transition_affects_workers || diff --git a/src/core/mainloop/mainloop.c b/src/core/mainloop/mainloop.c index d5f3cb13f9..176399b333 100644 --- a/src/core/mainloop/mainloop.c +++ b/src/core/mainloop/mainloop.c @@ -205,7 +205,6 @@ static void connection_start_reading_from_linked_conn(connection_t *conn); static int connection_should_read_from_linked_conn(connection_t *conn); static void conn_read_callback(evutil_socket_t fd, short event, void *_conn); static void conn_write_callback(evutil_socket_t fd, short event, void *_conn); -static void second_elapsed_callback(periodic_timer_t *timer, void *args); static void shutdown_did_not_work_callback(evutil_socket_t fd, short event, void *arg) ATTR_NORETURN; @@ -1367,6 +1366,7 @@ CALLBACK(save_state); CALLBACK(write_bridge_ns); CALLBACK(write_stats_file); CALLBACK(control_per_second_events); +CALLBACK(second_elapsed); #undef CALLBACK @@ -1380,6 +1380,11 @@ STATIC periodic_event_item_t periodic_events[] = { CALLBACK(add_entropy, ALL, 0), CALLBACK(heartbeat, ALL, 0), + /* This is a legacy catch-all callback that runs once per second if + * we are online and active. */ + CALLBACK(second_elapsed, NET_PARTICIPANT, + FL(NEED_NET)|FL(FLUSH_ON_DISABLE)), + /* XXXX Do we have a reason to do this on a callback? Does it do any good at * all? For now, if we're dormant, we can let our listeners decay. */ CALLBACK(retry_listeners, NET_PARTICIPANT, FL(NEED_NET)), @@ -1753,43 +1758,30 @@ safe_timer_diff(time_t now, time_t next) /** Perform regular maintenance tasks. This function gets run once per * second. */ -static void -second_elapsed_callback(periodic_timer_t *timer, void *arg) +static int +second_elapsed_callback(time_t now, const or_options_t *options) { - (void) timer; - (void) arg; - const time_t now = time(NULL); - const or_options_t *options = get_options(); - - /* We don't need to do this once-per-second any more: time-updating is - * only in this callback _because it is a callback_. It should be fine - * to disable this callback, and the time will still get updated. - */ - update_current_time(now); - - /* 0. See if our bandwidth limits are exhausted and we should hibernate; or - * if it's time to wake up from hibernation; or if we have a scheduled - * shutdown and it's time to run it. + /* 0. See if our bandwidth limits are exhausted and we should hibernate * - * Note: we have redundant mechanisms to handle the + * Note: we have redundant mechanisms to handle the case where it's + * time to wake up from hibernation; or where we have a scheduled + * shutdown and it's time to run it, but this will also handle those. */ - // TODO: NET_PARTICIPANT. consider_hibernation(now); /* Maybe enough time elapsed for us to reconsider a circuit. */ - // TODO: NET_PARTICIPANT circuit_upgrade_circuits_from_guard_wait(); if (options->UseBridges && !net_is_disabled()) { /* Note: this check uses net_is_disabled(), not should_delay_dir_fetches() * -- the latter is only for fetching consensus-derived directory info. */ - // TODO: client+NET_PARTICIPANT. + // TODO: client // Also, schedule this rather than probing 1x / sec fetch_bridge_descriptors(options, now); } if (accounting_is_enabled(options)) { - // TODO: refactor or rewrite; NET_PARTICIPANT + // TODO: refactor or rewrite? accounting_run_housekeeping(now); } @@ -1809,12 +1801,10 @@ second_elapsed_callback(periodic_timer_t *timer, void *arg) * Do this before step 4, so we can put them back into pending * state to be picked up by the new circuit. */ - // TODO: All expire stuff can become NET_PARTICIPANT, FLUSH_ON_DISABLE connection_ap_expire_beginning(); /* 3c. And expire connections that we've held open for too long. */ - // TODO: All expire stuff can become NET_PARTICIPANT, FLUSH_ON_DISABLE connection_expire_held_open(); /* 4. Every second, we try a new circuit if there are no valid @@ -1824,26 +1814,24 @@ second_elapsed_callback(periodic_timer_t *timer, void *arg) */ const int have_dir_info = router_have_minimum_dir_info(); if (have_dir_info && !net_is_disabled()) { - // TODO: NET_PARTICIPANT. circuit_build_needed_circs(now); } else { - // TODO: NET_PARTICIPANT, FLUSH_ON_DISABLE circuit_expire_old_circs_as_needed(now); } /* 5. We do housekeeping for each connection... */ - // TODO: NET_PARTICIPANT channel_update_bad_for_new_circs(NULL, 0); int i; for (i=0;i