Tor  0.4.7.0-alpha-dev
or_periodic.c
Go to the documentation of this file.
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 */
6 
7 /**
8  * @file or_periodic.c
9  * @brief Periodic callbacks for the onion routing subsystem
10  **/
11 
12 #include "orconfig.h"
13 #include "core/or/or.h"
14 
15 #include "core/mainloop/periodic.h"
16 
17 #include "core/or/channel.h"
18 #include "core/or/circuituse.h"
19 #include "core/or/or_periodic.h"
20 
22 
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) */
30 
31 #define FL(name) (PERIODIC_EVENT_FLAG_ ## name)
32 
33 #define CHANNEL_CHECK_INTERVAL (60*60)
34 static int
35 check_canonical_channels_callback(time_t now, const or_options_t *options)
36 {
37  (void)now;
38  if (public_server_mode(options))
40 
41  return CHANNEL_CHECK_INTERVAL;
42 }
43 
44 DECLARE_EVENT(check_canonical_channels, RELAY, FL(NEED_NET));
45 
46 /**
47  * Periodic callback: as a server, see if we have any old unused circuits
48  * that should be expired */
49 static int
51  const or_options_t *options)
52 {
53  (void)options;
54  /* every 11 seconds, so not usually the same second as other such events */
56  return 11;
57 }
58 
59 DECLARE_EVENT(expire_old_circuits_serverside, ROUTER, FL(NEED_NET));
60 
61 void
62 or_register_periodic_events(void)
63 {
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);
67 }
void channel_check_for_duplicates(void)
Definition: channel.c:748
Header file for channel.c.
void circuit_expire_old_circuits_serverside(time_t now)
Definition: circuituse.c:1564
Header file for circuituse.c.
Master header file for Tor-specific functionality.
static int expire_old_circuits_serverside_callback(time_t now, const or_options_t *options)
Definition: or_periodic.c:50
Header for core/or/or_periodic.c.
void periodic_events_register(periodic_event_item_t *item)
Definition: periodic.c:219
Header for periodic.c.
int public_server_mode(const or_options_t *options)
Definition: routermode.c:43
Header file for routermode.c.