Merge branch 'maint-0.4.8'
[tor.git] / src / core / or / or_periodic.c
blobb01790feac7cce92aab8fde3fe47c4b9d6297fdf
1 /* Copyright (c) 2001 Matej Pfajfar.
2 * Copyright (c) 2001-2004, Roger Dingledine.
3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4 * Copyright (c) 2007-2021, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
7 /**
8 * @file or_periodic.c
9 * @brief Periodic callbacks for the onion routing subsystem
10 **/
12 #include "orconfig.h"
13 #include "core/or/or.h"
15 #include "core/mainloop/periodic.h"
17 #include "core/or/channel.h"
18 #include "core/or/circuituse.h"
19 #include "core/or/or_periodic.h"
21 #include "feature/relay/routermode.h"
23 #ifndef COCCI
24 #define DECLARE_EVENT(name, roles, flags) \
25 static periodic_event_item_t name ## _event = \
26 PERIODIC_EVENT(name, \
27 PERIODIC_EVENT_ROLE_##roles, \
28 flags)
29 #endif /* !defined(COCCI) */
31 #define FL(name) (PERIODIC_EVENT_FLAG_ ## name)
33 #define CHANNEL_CHECK_INTERVAL (60*60)
34 static int
35 check_canonical_channels_callback(time_t now, const or_options_t *options)
37 (void)now;
38 if (public_server_mode(options))
39 channel_check_for_duplicates();
41 return CHANNEL_CHECK_INTERVAL;
44 DECLARE_EVENT(check_canonical_channels, RELAY, FL(NEED_NET));
46 /**
47 * Periodic callback: as a server, see if we have any old unused circuits
48 * that should be expired */
49 static int
50 expire_old_circuits_serverside_callback(time_t now,
51 const or_options_t *options)
53 (void)options;
54 /* every 11 seconds, so not usually the same second as other such events */
55 circuit_expire_old_circuits_serverside(now);
56 return 11;
59 DECLARE_EVENT(expire_old_circuits_serverside, ROUTER, FL(NEED_NET));
61 void
62 or_register_periodic_events(void)
64 // These are router-only events, but they're owned by the OR subsystem. */
65 periodic_events_register(&check_canonical_channels_event);
66 periodic_events_register(&expire_old_circuits_serverside_event);