From 05d314f888dd96840d92fbcc513974487485f4cb Mon Sep 17 00:00:00 2001 From: David Goulet Date: Thu, 26 Apr 2018 14:20:31 -0400 Subject: main: Add mainloop callback event flags Implement the ability to set flags per events which influences the set up of the event. This commit only adds one flag which is "need network" meaning that the event is not enabled if tor has disabled the network or if hibernation mode. Signed-off-by: David Goulet --- src/or/periodic.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/or/periodic.h') diff --git a/src/or/periodic.h b/src/or/periodic.h index dde27db5af..a044b34fdd 100644 --- a/src/or/periodic.h +++ b/src/or/periodic.h @@ -29,6 +29,15 @@ (PERIODIC_EVENT_ROLE_AUTHORITIES | PERIODIC_EVENT_ROLE_CLIENT | \ PERIODIC_EVENT_ROLE_HS_SERVICE | PERIODIC_EVENT_ROLE_ROUTER) +/* + * Event flags which can change the behavior of an event. + */ + +/* Indicate that the event needs the network meaning that if we are in + * DisableNetwork or hibernation mode, the event won't be enabled. This obey + * the net_is_disabled() check. */ +#define PERIODIC_EVENT_FLAG_NEED_NET (1U << 0) + /** 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 @@ -49,13 +58,15 @@ typedef struct periodic_event_item_t { /* Bitmask of roles define above for which this event applies. */ uint32_t roles; + /* Bitmask of flags which can change the behavior of the event. */ + uint32_t flags; /* Indicate that this event has been enabled that is scheduled. */ unsigned int enabled : 1; } periodic_event_item_t; /** events will get their interval from first execution */ -#define PERIODIC_EVENT(fn, r) { fn##_callback, 0, NULL, #fn, r, 0 } -#define END_OF_PERIODIC_EVENTS { NULL, 0, NULL, NULL, 0, 0 } +#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 } /* Return true iff the given event was setup before thus is enabled to be * scheduled. */ -- cgit v1.2.3-54-g00ecf