Tor
0.4.7.0-alpha-dev
|
Header for periodic.c. More...
Go to the source code of this file.
Data Structures | |
struct | periodic_event_item_t |
Macros | |
#define | PERIODIC_EVENT_NO_UPDATE (-1) |
#define | PERIODIC_EVENT_ROLE_CLIENT (1U << 0) |
#define | PERIODIC_EVENT_ROLE_RELAY (1U << 1) |
#define | PERIODIC_EVENT_ROLE_BRIDGE (1U << 2) |
#define | PERIODIC_EVENT_ROLE_DIRAUTH (1U << 3) |
#define | PERIODIC_EVENT_ROLE_BRIDGEAUTH (1U << 4) |
#define | PERIODIC_EVENT_ROLE_HS_SERVICE (1U << 5) |
#define | PERIODIC_EVENT_ROLE_DIRSERVER (1U << 6) |
#define | PERIODIC_EVENT_ROLE_CONTROLEV (1U << 7) |
#define | PERIODIC_EVENT_ROLE_NET_PARTICIPANT (1U << 8) |
#define | PERIODIC_EVENT_ROLE_ALL (1U << 9) |
#define | PERIODIC_EVENT_ROLE_ROUTER (PERIODIC_EVENT_ROLE_BRIDGE | PERIODIC_EVENT_ROLE_RELAY) |
#define | PERIODIC_EVENT_ROLE_AUTHORITIES (PERIODIC_EVENT_ROLE_BRIDGEAUTH | PERIODIC_EVENT_ROLE_DIRAUTH) |
#define | PERIODIC_EVENT_FLAG_NEED_NET (1U << 0) |
#define | PERIODIC_EVENT_FLAG_RUN_ON_DISABLE (1U << 1) |
#define | PERIODIC_EVENT(fn, r, f) { fn##_callback, 0, NULL, #fn, r, f, 0 } |
#define | END_OF_PERIODIC_EVENTS { NULL, 0, NULL, NULL, 0, 0, 0 } |
Typedefs | |
typedef int(* | periodic_event_helper_t) (time_t now, const or_options_t *options) |
Functions | |
static int | periodic_event_is_enabled (const periodic_event_item_t *item) |
void | periodic_event_launch (periodic_event_item_t *event) |
void | periodic_event_connect (periodic_event_item_t *event) |
void | periodic_event_reschedule (periodic_event_item_t *event) |
void | periodic_event_enable (periodic_event_item_t *event) |
void | periodic_event_disable (periodic_event_item_t *event) |
void | periodic_event_schedule_and_disable (periodic_event_item_t *event) |
void | periodic_events_register (periodic_event_item_t *item) |
void | periodic_events_connect_all (void) |
void | periodic_events_reset_all (void) |
periodic_event_item_t * | periodic_events_find (const char *name) |
void | periodic_events_rescan_by_roles (int roles, bool net_disabled) |
void | periodic_events_disconnect_all (void) |
int | safe_timer_diff (time_t now, time_t next) |
Header for periodic.c.
Definition in file periodic.h.
#define PERIODIC_EVENT | ( | fn, | |
r, | |||
f | |||
) | { fn##_callback, 0, NULL, #fn, r, f, 0 } |
events will get their interval from first execution
Definition at line 80 of file periodic.h.
typedef int(* periodic_event_helper_t) (time_t now, const or_options_t *options) |
Callback function for a periodic event to take action. The return value influences the next time the function will get called. Return PERIODIC_EVENT_NO_UPDATE to not update last_action_time and be polled again in the next second. If a positive value is returned it will update the interval time.
Definition at line 57 of file periodic.h.
void periodic_event_connect | ( | periodic_event_item_t * | event | ) |
Connects a periodic event to the Libevent backend. Does not launch the event immediately.
Definition at line 117 of file periodic.c.
Referenced by periodic_events_connect_all().
void periodic_event_disable | ( | periodic_event_item_t * | event | ) |
Disable the given event which means the event is destroyed and then the event's enabled flag is unset. This can be called for an event that is already disabled.
Definition at line 185 of file periodic.c.
Referenced by periodic_event_disconnect().
void periodic_event_enable | ( | periodic_event_item_t * | event | ) |
Enable the given event by setting its "enabled" flag and scheduling it to run immediately in the event loop. This can be called for an event that is already enabled.
Definition at line 168 of file periodic.c.
void periodic_event_launch | ( | periodic_event_item_t * | event | ) |
Handles initial dispatch for periodic events. It should happen 1 second after the events are created to mimic behaviour before #3199's refactor
Definition at line 132 of file periodic.c.
void periodic_event_reschedule | ( | periodic_event_item_t * | event | ) |
Schedules event to run as soon as possible from now.
Definition at line 106 of file periodic.c.
Referenced by periodic_events_reset_all(), and reschedule_descriptor_update_check().
void periodic_event_schedule_and_disable | ( | periodic_event_item_t * | event | ) |
Disable an event, then schedule it to run once. Do nothing if the event was already disabled.
Definition at line 201 of file periodic.c.
void periodic_events_connect_all | ( | void | ) |
Make all registered periodic events connect to the libevent backend.
Definition at line 234 of file periodic.c.
Referenced by do_main_loop().
void periodic_events_disconnect_all | ( | void | ) |
Invoked at shutdown: disconnect and unregister all periodic events.
Does not free the periodic_event_item_t object themselves, because we do not own them.
Definition at line 331 of file periodic.c.
periodic_event_item_t* periodic_events_find | ( | const char * | name | ) |
Return the registered periodic event whose name is name. Return NULL if no such event is found.
Definition at line 272 of file periodic.c.
void periodic_events_register | ( | periodic_event_item_t * | item | ) |
Add item to the list of periodic events.
Note that item should be statically allocated: we do not take ownership of it.
Definition at line 219 of file periodic.c.
void periodic_events_rescan_by_roles | ( | int | roles, |
bool | net_disabled | ||
) |
Start or stop registered periodic events, depending on our current set of roles.
Invoked when our list of roles, or the net_disabled flag has changed.
Definition at line 291 of file periodic.c.
Referenced by rescan_periodic_events().
void periodic_events_reset_all | ( | void | ) |
Reset all the registered periodic events so we'll do all our actions again as if we just started up.
Useful if our clock just moved back a long time from the future, so we don't wait until that future arrives again before acting.
Definition at line 254 of file periodic.c.
Referenced by reset_all_main_loop_timers().
int safe_timer_diff | ( | time_t | now, |
time_t | next | ||
) |
Helper: Return the number of seconds between now and next, clipped to the range [1 second, LONGEST_TIMER_PERIOD].
We use this to answer the question, "how many seconds is it from now until next" in periodic timer callbacks. Don't use it for other purposes
Definition at line 351 of file periodic.c.
Referenced by downrate_stability_callback().