Merge remote-tracking branch 'github/ticket25952'

This commit is contained in:
Nick Mathewson 2018-05-03 11:59:53 -04:00
commit 5e0316142f
2 changed files with 60 additions and 38 deletions

9
changes/ticket25952 Normal file
View File

@ -0,0 +1,9 @@
o Minor features (mainloop):
- Move responsibility for
warning relay operators about unreachable ports
from a once-per-second callback to a callback that is only scheduled as
needed. Once enough items are removed from our once-per-second
callback, we can eliminate it entirely to conserve CPU when idle.
Closes ticket
25952.

View File

@ -1362,6 +1362,7 @@ CALLBACK(heartbeat);
CALLBACK(hs_service);
CALLBACK(launch_descriptor_fetches);
CALLBACK(launch_reachability_tests);
CALLBACK(reachability_warnings);
CALLBACK(record_bridge_stats);
CALLBACK(rend_cache_failure_clean);
CALLBACK(reset_padding_counts);
@ -1405,6 +1406,8 @@ STATIC periodic_event_item_t periodic_events[] = {
CALLBACK(check_onion_keys_expiry_time, PERIODIC_EVENT_ROLE_ROUTER, 0),
CALLBACK(expire_old_ciruits_serverside, PERIODIC_EVENT_ROLE_ROUTER,
PERIODIC_EVENT_FLAG_NEED_NET),
CALLBACK(reachability_warnings, PERIODIC_EVENT_ROLE_ROUTER,
PERIODIC_EVENT_FLAG_NEED_NET),
CALLBACK(retry_dns, PERIODIC_EVENT_ROLE_ROUTER, 0),
CALLBACK(rotate_onion_key, PERIODIC_EVENT_ROLE_ROUTER, 0),
@ -2331,6 +2334,54 @@ expire_old_ciruits_serverside_callback(time_t now, const or_options_t *options)
return 11;
}
/**
* Callback: Send warnings if Tor doesn't find its ports reachable.
*/
static int
reachability_warnings_callback(time_t now, const or_options_t *options)
{
(void) now;
if (get_uptime() < TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT) {
return (int)(TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT - get_uptime());
}
if (server_mode(options) &&
!net_is_disabled() &&
have_completed_a_circuit()) {
/* every 20 minutes, check and complain if necessary */
const routerinfo_t *me = router_get_my_routerinfo();
if (me && !check_whether_orport_reachable(options)) {
char *address = tor_dup_ip(me->addr);
log_warn(LD_CONFIG,"Your server (%s:%d) has not managed to confirm that "
"its ORPort is reachable. Relays do not publish descriptors "
"until their ORPort and DirPort are reachable. Please check "
"your firewalls, ports, address, /etc/hosts file, etc.",
address, me->or_port);
control_event_server_status(LOG_WARN,
"REACHABILITY_FAILED ORADDRESS=%s:%d",
address, me->or_port);
tor_free(address);
}
if (me && !check_whether_dirport_reachable(options)) {
char *address = tor_dup_ip(me->addr);
log_warn(LD_CONFIG,
"Your server (%s:%d) has not managed to confirm that its "
"DirPort is reachable. Relays do not publish descriptors "
"until their ORPort and DirPort are reachable. Please check "
"your firewalls, ports, address, /etc/hosts file, etc.",
address, me->dir_port);
control_event_server_status(LOG_WARN,
"REACHABILITY_FAILED DIRADDRESS=%s:%d",
address, me->dir_port);
tor_free(address);
}
}
return TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT;
}
static int dns_honesty_first_time = 1;
/**
@ -2458,7 +2509,6 @@ second_elapsed_callback(periodic_timer_t *timer, void *arg)
size_t bytes_written;
size_t bytes_read;
int seconds_elapsed;
const or_options_t *options = get_options();
(void)timer;
(void)arg;
@ -2481,43 +2531,6 @@ second_elapsed_callback(periodic_timer_t *timer, void *arg)
control_event_circ_bandwidth_used();
control_event_circuit_cell_stats();
if (server_mode(options) &&
!net_is_disabled() &&
seconds_elapsed > 0 &&
have_completed_a_circuit() &&
get_uptime() / TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT !=
(get_uptime()+seconds_elapsed) /
TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT) {
/* every 20 minutes, check and complain if necessary */
const routerinfo_t *me = router_get_my_routerinfo();
if (me && !check_whether_orport_reachable(options)) {
char *address = tor_dup_ip(me->addr);
log_warn(LD_CONFIG,"Your server (%s:%d) has not managed to confirm that "
"its ORPort is reachable. Relays do not publish descriptors "
"until their ORPort and DirPort are reachable. Please check "
"your firewalls, ports, address, /etc/hosts file, etc.",
address, me->or_port);
control_event_server_status(LOG_WARN,
"REACHABILITY_FAILED ORADDRESS=%s:%d",
address, me->or_port);
tor_free(address);
}
if (me && !check_whether_dirport_reachable(options)) {
char *address = tor_dup_ip(me->addr);
log_warn(LD_CONFIG,
"Your server (%s:%d) has not managed to confirm that its "
"DirPort is reachable. Relays do not publish descriptors "
"until their ORPort and DirPort are reachable. Please check "
"your firewalls, ports, address, /etc/hosts file, etc.",
address, me->dir_port);
control_event_server_status(LOG_WARN,
"REACHABILITY_FAILED DIRADDRESS=%s:%d",
address, me->dir_port);
tor_free(address);
}
}
/** If more than this many seconds have elapsed, probably the clock
* jumped: doesn't count. */
#define NUM_JUMPED_SECONDS_BEFORE_WARN 100