tor  0.4.2.1-alpha-dev
dirauth_periodic.c
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 #include "core/or/or.h"
8 
10 #include "core/mainloop/netstatus.h"
12 #include "feature/stats/rephist.h"
13 
14 #include "feature/dirauth/bridgeauth.h"
16 #include "feature/dirauth/dirauth_periodic.h"
18 
19 #include "core/mainloop/periodic.h"
20 
21 #define DECLARE_EVENT(name, roles, flags) \
22  static periodic_event_item_t name ## _event = \
23  PERIODIC_EVENT(name, \
24  PERIODIC_EVENT_ROLE_##roles, \
25  flags)
26 
27 #define FL(name) (PERIODIC_EVENT_FLAG_##name)
28 
33 static int
34 check_authority_cert_callback(time_t now, const or_options_t *options)
35 {
36  (void)now;
37  (void)options;
38  /* 1e. Periodically, if we're a v3 authority, we check whether our cert is
39  * close to expiring and warn the admin if it is. */
41 #define CHECK_V3_CERTIFICATE_INTERVAL (5*60)
42  return CHECK_V3_CERTIFICATE_INTERVAL;
43 }
44 
45 DECLARE_EVENT(check_authority_cert, DIRAUTH, 0);
46 
53 static int
54 dirvote_callback(time_t now, const or_options_t *options)
55 {
56  if (!authdir_mode_v3(options)) {
57  tor_assert_nonfatal_unreached();
58  return 3600;
59  }
60 
61  time_t next = dirvote_act(options, now);
62  if (BUG(next == TIME_MAX)) {
63  /* This shouldn't be returned unless we called dirvote_act() without
64  * being an authority. If it happens, maybe our configuration will
65  * fix itself in an hour or so? */
66  return 3600;
67  }
68  return safe_timer_diff(now, next);
69 }
70 
71 DECLARE_EVENT(dirvote, DIRAUTH, FL(NEED_NET));
72 
75 void
76 reschedule_dirvote(const or_options_t *options)
77 {
78  if (authdir_mode_v3(options)) {
79  periodic_event_reschedule(&dirvote_event);
80  }
81 }
82 
87 static int
88 save_stability_callback(time_t now, const or_options_t *options)
89 {
90  if (authdir_mode_tests_reachability(options)) {
91  if (rep_hist_record_mtbf_data(now, 1)<0) {
92  log_warn(LD_GENERAL, "Couldn't store mtbf data.");
93  }
94  }
95 #define SAVE_STABILITY_INTERVAL (30*60)
96  return SAVE_STABILITY_INTERVAL;
97 }
98 
99 DECLARE_EVENT(save_stability, AUTHORITIES, 0);
100 
105 static int
106 launch_reachability_tests_callback(time_t now, const or_options_t *options)
107 {
108  if (authdir_mode_tests_reachability(options) &&
109  !net_is_disabled()) {
110  /* try to determine reachability of the other Tor relays */
112  }
114 }
115 
116 DECLARE_EVENT(launch_reachability_tests, AUTHORITIES, FL(NEED_NET));
117 
122 static int
123 downrate_stability_callback(time_t now, const or_options_t *options)
124 {
125  (void)options;
126  /* 1d. Periodically, we discount older stability information so that new
127  * stability info counts more, and save the stability information to disk as
128  * appropriate. */
129  time_t next = rep_hist_downrate_old_runs(now);
130  return safe_timer_diff(now, next);
131 }
132 
133 DECLARE_EVENT(downrate_stability, AUTHORITIES, 0);
134 
139 static int
140 write_bridge_ns_callback(time_t now, const or_options_t *options)
141 {
142  if (options->BridgeAuthoritativeDir) {
143  bridgeauth_dump_bridge_status_to_file(now);
144 #define BRIDGE_STATUSFILE_INTERVAL (30*60)
145  return BRIDGE_STATUSFILE_INTERVAL;
146  }
147  return PERIODIC_EVENT_NO_UPDATE;
148 }
149 
150 DECLARE_EVENT(write_bridge_ns, BRIDGEAUTH, 0);
151 
152 void
153 dirauth_register_periodic_events(void)
154 {
155  periodic_events_register(&downrate_stability_event);
156  periodic_events_register(&launch_reachability_tests_event);
157  periodic_events_register(&save_stability_event);
158  periodic_events_register(&check_authority_cert_event);
159  periodic_events_register(&dirvote_event);
160  periodic_events_register(&write_bridge_ns_event);
161 }
int authdir_mode_tests_reachability(const or_options_t *options)
Definition: authmode.c:59
time_t rep_hist_downrate_old_runs(time_t now)
Definition: rephist.c:382
time_t dirvote_act(const or_options_t *options, time_t now)
Definition: dirvote.c:2839
#define LD_GENERAL
Definition: log.h:60
void v3_authority_check_key_expiry(void)
Definition: router.c:704
#define REACHABILITY_TEST_INTERVAL
Definition: reachability.h:21
The or_options_t structure, which represents Tor's configuration.
Header file for reachability.c.
void dirserv_test_reachability(time_t now)
Definition: reachability.c:179
Header file for directory authority mode.
void periodic_events_register(periodic_event_item_t *item)
Definition: periodic.c:215
int safe_timer_diff(time_t now, time_t next)
Definition: periodic.c:347
Master header file for Tor-specific functionality.
void periodic_event_reschedule(periodic_event_item_t *event)
Definition: periodic.c:107
Header file for rephist.c.
int BridgeAuthoritativeDir
Header file for dirvote.c.
int rep_hist_record_mtbf_data(time_t now, int missing_means_down)
Definition: rephist.c:626