or_periodic.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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-2019, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * @file or_periodic.c
  8. * @brief Periodic callbacks for the onion routing subsystem
  9. **/
  10. #include "orconfig.h"
  11. #include "core/or/or.h"
  12. #include "core/mainloop/periodic.h"
  13. #include "core/or/channel.h"
  14. #include "core/or/circuituse.h"
  15. #include "core/or/or_periodic.h"
  16. #include "feature/relay/routermode.h"
  17. #define DECLARE_EVENT(name, roles, flags) \
  18. static periodic_event_item_t name ## _event = \
  19. PERIODIC_EVENT(name, \
  20. PERIODIC_EVENT_ROLE_##roles, \
  21. flags)
  22. #define FL(name) (PERIODIC_EVENT_FLAG_ ## name)
  23. #define CHANNEL_CHECK_INTERVAL (60*60)
  24. static int
  25. check_canonical_channels_callback(time_t now, const or_options_t *options)
  26. {
  27. (void)now;
  28. if (public_server_mode(options))
  29. channel_check_for_duplicates();
  30. return CHANNEL_CHECK_INTERVAL;
  31. }
  32. DECLARE_EVENT(check_canonical_channels, RELAY, FL(NEED_NET));
  33. /**
  34. * Periodic callback: as a server, see if we have any old unused circuits
  35. * that should be expired */
  36. static int
  37. expire_old_circuits_serverside_callback(time_t now,
  38. const or_options_t *options)
  39. {
  40. (void)options;
  41. /* every 11 seconds, so not usually the same second as other such events */
  42. circuit_expire_old_circuits_serverside(now);
  43. return 11;
  44. }
  45. DECLARE_EVENT(expire_old_circuits_serverside, ROUTER, FL(NEED_NET));
  46. void
  47. or_register_periodic_events(void)
  48. {
  49. // These are router-only events, but they're owned by the OR subsystem. */
  50. periodic_events_register(&check_canonical_channels_event);
  51. periodic_events_register(&expire_old_circuits_serverside_event);
  52. }