tor  master
periodic.h
1 /* Copyright (c) 2015-2017, 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 
19 /* Helper macro to make it a bit less annoying to defined groups of roles that
20  * are often used. */
21 
22 /* Router that is a Bridge or Relay. */
23 #define PERIODIC_EVENT_ROLE_ROUTER \
24  (PERIODIC_EVENT_ROLE_BRIDGE | PERIODIC_EVENT_ROLE_RELAY)
25 /* Authorities that is both bridge and directory. */
26 #define PERIODIC_EVENT_ROLE_AUTHORITIES \
27  (PERIODIC_EVENT_ROLE_BRIDGEAUTH | PERIODIC_EVENT_ROLE_DIRAUTH)
28 /* All roles. */
29 #define PERIODIC_EVENT_ROLE_ALL \
30  (PERIODIC_EVENT_ROLE_AUTHORITIES | PERIODIC_EVENT_ROLE_CLIENT | \
31  PERIODIC_EVENT_ROLE_HS_SERVICE | PERIODIC_EVENT_ROLE_ROUTER)
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 
47 typedef int (*periodic_event_helper_t)(time_t now,
48  const or_options_t *options);
49 
50 struct mainloop_event_t;
51 
53 typedef struct periodic_event_item_t {
54  periodic_event_helper_t fn;
56  struct mainloop_event_t *ev;
58  const char *name;
60  /* Bitmask of roles define above for which this event applies. */
61  uint32_t roles;
62  /* Bitmask of flags which can change the behavior of the event. */
63  uint32_t flags;
64  /* Indicate that this event has been enabled that is scheduled. */
65  unsigned int enabled : 1;
67 
69 #define PERIODIC_EVENT(fn, r, f) { fn##_callback, 0, NULL, #fn, r, f, 0 }
70 #define END_OF_PERIODIC_EVENTS { NULL, 0, NULL, NULL, 0, 0, 0 }
71 
72 /* Return true iff the given event was setup before thus is enabled to be
73  * scheduled. */
74 static inline int
75 periodic_event_is_enabled(const periodic_event_item_t *item)
76 {
77  return item->enabled;
78 }
79 
86 
87 #endif /* !defined(TOR_PERIODIC_H) */
88 
Definition: or.h:3657
void periodic_event_enable(periodic_event_item_t *event)
Definition: periodic.c:147
time_t last_action_time
Definition: periodic.h:55
void periodic_event_reschedule(periodic_event_item_t *event)
Definition: periodic.c:91
void periodic_event_disable(periodic_event_item_t *event)
Definition: periodic.c:162
const char * name
Definition: periodic.h:58
void periodic_event_setup(periodic_event_item_t *event)
Definition: periodic.c:101
Definition: periodic.h:53
void periodic_event_launch(periodic_event_item_t *event)
Definition: periodic.c:116
void periodic_event_destroy(periodic_event_item_t *event)
Definition: periodic.c:135
Definition: compat_libevent.c:310
struct mainloop_event_t * ev
Definition: periodic.h:56
periodic_event_helper_t fn
Definition: periodic.h:54