tor  0.4.1.0-alpha-dev
periodic.h
1 /* Copyright (c) 2015-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
4 #ifndef TOR_PERIODIC_H
5 #define TOR_PERIODIC_H
6 
7 #define PERIODIC_EVENT_NO_UPDATE (-1)
8 
9 /* Tor roles for which a periodic event item is for. An event can be for
10  * multiple roles, they can be combined. */
11 #define PERIODIC_EVENT_ROLE_CLIENT (1U << 0)
12 #define PERIODIC_EVENT_ROLE_RELAY (1U << 1)
13 #define PERIODIC_EVENT_ROLE_BRIDGE (1U << 2)
14 #define PERIODIC_EVENT_ROLE_DIRAUTH (1U << 3)
15 #define PERIODIC_EVENT_ROLE_BRIDGEAUTH (1U << 4)
16 #define PERIODIC_EVENT_ROLE_HS_SERVICE (1U << 5)
17 #define PERIODIC_EVENT_ROLE_DIRSERVER (1U << 6)
18 #define PERIODIC_EVENT_ROLE_CONTROLEV (1U << 7)
19 
20 #define PERIODIC_EVENT_ROLE_NET_PARTICIPANT (1U << 8)
21 #define PERIODIC_EVENT_ROLE_ALL (1U << 9)
22 
23 /* Helper macro to make it a bit less annoying to defined groups of roles that
24  * are often used. */
25 
26 /* Router that is a Bridge or Relay. */
27 #define PERIODIC_EVENT_ROLE_ROUTER \
28  (PERIODIC_EVENT_ROLE_BRIDGE | PERIODIC_EVENT_ROLE_RELAY)
29 /* Authorities that is both bridge and directory. */
30 #define PERIODIC_EVENT_ROLE_AUTHORITIES \
31  (PERIODIC_EVENT_ROLE_BRIDGEAUTH | PERIODIC_EVENT_ROLE_DIRAUTH)
32 
33 /*
34  * Event flags which can change the behavior of an event.
35  */
36 
37 /* Indicate that the event needs the network meaning that if we are in
38  * DisableNetwork or hibernation mode, the event won't be enabled. This obey
39  * the net_is_disabled() check. */
40 #define PERIODIC_EVENT_FLAG_NEED_NET (1U << 0)
41 
42 /* Indicate that if the event is enabled, it needs to be run once before
43  * it becomes disabled.
44  */
45 #define PERIODIC_EVENT_FLAG_RUN_ON_DISABLE (1U << 1)
46 
52 typedef int (*periodic_event_helper_t)(time_t now,
53  const or_options_t *options);
54 
55 struct mainloop_event_t;
56 
58 typedef struct periodic_event_item_t {
59  periodic_event_helper_t fn;
61  struct mainloop_event_t *ev;
63  const char *name;
65  /* Bitmask of roles define above for which this event applies. */
66  uint32_t roles;
67  /* Bitmask of flags which can change the behavior of the event. */
68  uint32_t flags;
69  /* Indicate that this event has been enabled that is scheduled. */
70  unsigned int enabled : 1;
72 
74 #define PERIODIC_EVENT(fn, r, f) { fn##_callback, 0, NULL, #fn, r, f, 0 }
75 #define END_OF_PERIODIC_EVENTS { NULL, 0, NULL, NULL, 0, 0, 0 }
76 
77 /* Return true iff the given event was setup before thus is enabled to be
78  * scheduled. */
79 static inline int
80 periodic_event_is_enabled(const periodic_event_item_t *item)
81 {
82  return item->enabled;
83 }
84 
92 
93 #endif /* !defined(TOR_PERIODIC_H) */
void periodic_event_enable(periodic_event_item_t *event)
Definition: periodic.c:144
const char * name
Definition: periodic.h:63
struct mainloop_event_t * ev
Definition: periodic.h:61
time_t last_action_time
Definition: periodic.h:60
void periodic_event_schedule_and_disable(periodic_event_item_t *event)
Definition: periodic.c:177
void periodic_event_reschedule(periodic_event_item_t *event)
Definition: periodic.c:88
void periodic_event_disable(periodic_event_item_t *event)
Definition: periodic.c:161
void periodic_event_setup(periodic_event_item_t *event)
Definition: periodic.c:98
void periodic_event_launch(periodic_event_item_t *event)
Definition: periodic.c:113
void periodic_event_destroy(periodic_event_item_t *event)
Definition: periodic.c:132
periodic_event_helper_t fn
Definition: periodic.h:59