aboutsummaryrefslogtreecommitdiff
path: root/src/core/or/or_periodic.c
blob: 4dfdce14cadd31572126d3b2295f27db25bf8775 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Copyright (c) 2001 Matej Pfajfar.
 * Copyright (c) 2001-2004, Roger Dingledine.
 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
 * Copyright (c) 2007-2020, The Tor Project, Inc. */
/* See LICENSE for licensing information */

/**
 * @file or_periodic.c
 * @brief Periodic callbacks for the onion routing subsystem
 **/

#include "orconfig.h"
#include "core/or/or.h"

#include "core/mainloop/periodic.h"

#include "core/or/channel.h"
#include "core/or/circuituse.h"
#include "core/or/or_periodic.h"

#include "feature/relay/routermode.h"

#ifndef COCCI
#define DECLARE_EVENT(name, roles, flags)         \
  static periodic_event_item_t name ## _event =   \
    PERIODIC_EVENT(name,                          \
                   PERIODIC_EVENT_ROLE_##roles,   \
                   flags)
#endif /* !defined(COCCI) */

#define FL(name) (PERIODIC_EVENT_FLAG_ ## name)

#define CHANNEL_CHECK_INTERVAL (60*60)
static int
check_canonical_channels_callback(time_t now, const or_options_t *options)
{
  (void)now;
  if (public_server_mode(options))
    channel_check_for_duplicates();

  return CHANNEL_CHECK_INTERVAL;
}

DECLARE_EVENT(check_canonical_channels, RELAY, FL(NEED_NET));

/**
 * Periodic callback: as a server, see if we have any old unused circuits
 * that should be expired */
static int
expire_old_circuits_serverside_callback(time_t now,
                                        const or_options_t *options)
{
  (void)options;
  /* every 11 seconds, so not usually the same second as other such events */
  circuit_expire_old_circuits_serverside(now);
  return 11;
}

DECLARE_EVENT(expire_old_circuits_serverside, ROUTER, FL(NEED_NET));

void
or_register_periodic_events(void)
{
  // These are router-only events, but they're owned by the OR subsystem. */
  periodic_events_register(&check_canonical_channels_event);
  periodic_events_register(&expire_old_circuits_serverside_event);
}