aboutsummaryrefslogtreecommitdiff
path: root/src/or/periodic.h
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2018-04-26 14:20:31 -0400
committerNick Mathewson <nickm@torproject.org>2018-04-27 09:28:00 -0400
commit05d314f888dd96840d92fbcc513974487485f4cb (patch)
treeb4f8c5d28bbedab890475bbdbd4fe517c7f6cac1 /src/or/periodic.h
parent302908657f492f064f9bddac794db477f53ab958 (diff)
downloadtor-05d314f888dd96840d92fbcc513974487485f4cb.tar.gz
tor-05d314f888dd96840d92fbcc513974487485f4cb.zip
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 <dgoulet@torproject.org>
Diffstat (limited to 'src/or/periodic.h')
-rw-r--r--src/or/periodic.h15
1 files changed, 13 insertions, 2 deletions
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 <b>last_action_time</b> 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. */