tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

or_periodic.c (1910B)


      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 
     21 #include "feature/relay/routermode.h"
     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))
     39    channel_check_for_duplicates();
     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
     50 expire_old_circuits_serverside_callback(time_t now,
     51                                        const or_options_t *options)
     52 {
     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;
     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 }