tor

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

commit 5595f90cb62441aae558f87bafa669b3b92de5cf
parent 4bda4534a569a737f3ee47222336be06a0cc36f2
Author: David Goulet <dgoulet@torproject.org>
Date:   Mon,  6 Oct 2025 13:19:17 +0000

Merge branch 'dirport-cleanup' into 'main'

refactor since advertised dir_port is 0 (except dir auths)

See merge request tpo/core/tor!940
Diffstat:
Msrc/feature/control/control_getinfo.c | 6++----
Msrc/feature/relay/relay_periodic.c | 2+-
Msrc/feature/relay/router.c | 55+++++++++++++++++--------------------------------------
Msrc/feature/relay/selftest.c | 10----------
Msrc/feature/relay/selftest.h | 2--
5 files changed, 20 insertions(+), 55 deletions(-)

diff --git a/src/feature/control/control_getinfo.c b/src/feature/control/control_getinfo.c @@ -1257,14 +1257,12 @@ getinfo_helper_events(control_connection_t *control_conn, router_all_orports_seem_reachable(options) ? "1" : "0"); } else if (!strcmp(question, "status/reachability-succeeded/dir")) { - *answer = tor_strdup( - router_dirport_seems_reachable(options) ? - "1" : "0"); + *answer = tor_strdup("1"); /* obsolete since tor#2667) */ } else if (!strcmp(question, "status/reachability-succeeded")) { tor_asprintf( answer, "OR=%d DIR=%d", router_all_orports_seem_reachable(options) ? 1 : 0, - router_dirport_seems_reachable(options) ? 1 : 0); + 1); } else if (!strcmp(question, "status/bootstrap-phase")) { *answer = control_event_boot_last_msg(); } else if (!strcmpstart(question, "status/version/")) { diff --git a/src/feature/relay/relay_periodic.c b/src/feature/relay/relay_periodic.c @@ -241,7 +241,7 @@ reachability_warnings_callback(time_t now, const or_options_t *options) log_warn(LD_CONFIG, "Your server has not managed to confirm reachability for " "its ORPort(s) at %s%s%s. Relays do not publish " - "descriptors until their ORPort and DirPort are " + "descriptors until their ORPort(s) are " "reachable. Please check your firewalls, ports, address, " "/etc/hosts file, etc.", where4?where4:"", diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c @@ -1286,13 +1286,12 @@ router_has_bandwidth_to_be_dirserver(const or_options_t *options) /** Helper: Return 1 if we have sufficient resources for serving directory * requests, return 0 otherwise. - * dir_port is either 0 or the configured DirPort number. * If AccountingMax is set less than our advertised bandwidth, then don't * serve requests. Likewise, if our advertised bandwidth is less than * MIN_BW_TO_ADVERTISE_DIRSERVER, don't bother trying to serve requests. */ static int -router_should_be_dirserver(const or_options_t *options, int dir_port) +router_should_be_dirserver(const or_options_t *options) { static int advertising=1; /* start out assuming we will advertise */ int new_choice=1; @@ -1301,7 +1300,8 @@ router_should_be_dirserver(const or_options_t *options, int dir_port) if (accounting_is_enabled(options) && get_options()->AccountingRule != ACCT_IN) { /* Don't spend bytes for directory traffic if we could end up hibernating, - * but allow DirPort otherwise. Some relay operators set AccountingMax + * but allow being a dir cache otherwise. + * Some relay operators set AccountingMax * because they're confused or to get statistics. Directory traffic has a * much larger effect on output than input so there is no reason to turn it * off if using AccountingRule in. */ @@ -1313,10 +1313,9 @@ router_should_be_dirserver(const or_options_t *options, int dir_port) "seconds long. Raising to 1."); interval_length = 1; } - log_info(LD_GENERAL, "Calculating whether to advertise %s: effective " - "bwrate: %u, AccountingMax: %"PRIu64", " + log_info(LD_GENERAL, "Calculating whether to advertise begindir: " + "effective bwrate: %u, AccountingMax: %"PRIu64", " "accounting interval length %d", - dir_port ? "dirport" : "begindir", effective_bw, (options->AccountingMax), interval_length); @@ -1336,14 +1335,11 @@ router_should_be_dirserver(const or_options_t *options, int dir_port) if (advertising != new_choice) { if (new_choice == 1) { - if (dir_port > 0) - log_notice(LD_DIR, "Advertising DirPort as %d", dir_port); - else - log_notice(LD_DIR, "Advertising directory service support"); + log_notice(LD_DIR, "Advertising directory service support"); } else { tor_assert(reason); - log_notice(LD_DIR, "Not advertising Dir%s (Reason: %s)", - dir_port ? "Port" : "ectory Service support", reason); + log_notice(LD_DIR, "Not advertising Directory Service support " + "(Reason: %s)", reason); } advertising = new_choice; } @@ -1352,17 +1348,13 @@ router_should_be_dirserver(const or_options_t *options, int dir_port) } /** Look at a variety of factors, and return 0 if we don't want to - * advertise the fact that we have a DirPort open or begindir support, else + * advertise the fact that we have begindir support, else * return 1. * - * Where dir_port or supports_tunnelled_dir_requests are not relevant, they - * must be 0. - * * Log a helpful message if we change our mind about whether to publish. */ static int decide_to_advertise_dir_impl(const or_options_t *options, - uint16_t dir_port, int supports_tunnelled_dir_requests) { /* Part one: reasons to publish or not publish that aren't @@ -1370,24 +1362,21 @@ decide_to_advertise_dir_impl(const or_options_t *options, * or because they're normal behavior. */ /* short circuit the rest of the function */ - if (!dir_port && !supports_tunnelled_dir_requests) + if (!supports_tunnelled_dir_requests) return 0; if (authdir_mode(options)) /* always publish */ return 1; if (net_is_disabled()) return 0; - if (dir_port && !routerconf_find_dir_port(options, dir_port)) - return 0; - if (supports_tunnelled_dir_requests && - !routerconf_find_or_port(options, AF_INET)) + if (!routerconf_find_or_port(options, AF_INET)) return 0; /* Part two: consider config options that could make us choose to * publish or not publish that the user might find surprising. */ - return router_should_be_dirserver(options, dir_port); + return router_should_be_dirserver(options); } -/** Front-end to decide_to_advertise_dir_impl(): return 0 if we don't want to +/** Return 0 if we don't want to * advertise the fact that we have a DirPort open, else return the * DirPort we want to advertise. */ @@ -1405,8 +1394,7 @@ static int router_should_advertise_begindir(const or_options_t *options, int supports_tunnelled_dir_requests) { - /* dir_port is not relevant, pass 0 */ - return decide_to_advertise_dir_impl(options, 0, + return decide_to_advertise_dir_impl(options, supports_tunnelled_dir_requests); } @@ -1435,17 +1423,14 @@ static bool publish_even_when_ipv4_orport_unreachable = false; static bool publish_even_when_ipv6_orport_unreachable = false; /** Decide if we're a publishable server. We are a publishable server if: + * - We are an authoritative directory server, or if * - We don't have the ClientOnly option set * and * - We have the PublishServerDescriptor option set to non-empty * and * - We have ORPort set * and - * - We believe our ORPort and DirPort (if present) are reachable from - * the outside; or - * - We believe our ORPort is reachable from the outside, and we can't - * check our DirPort because the consensus has no exits; or - * - We are an authoritative directory server. + * - We believe our ORPort is reachable from the outside. */ static int decide_if_publishable_server(void) @@ -1478,13 +1463,7 @@ decide_if_publishable_server(void) return 0; } } - if (router_have_consensus_path() == CONSENSUS_PATH_INTERNAL) { - /* All set: there are no exits in the consensus (maybe this is a tiny - * test network), so we can't check our DirPort reachability. */ - return 1; - } else { - return router_dirport_seems_reachable(options); - } + return 1; /* everything looks good! publish. */ } /** Initiate server descriptor upload as reasonable (if server is publishable, diff --git a/src/feature/relay/selftest.c b/src/feature/relay/selftest.c @@ -130,16 +130,6 @@ router_orport_seems_reachable(const or_options_t *options, return true; } -/** Relay DirPorts are no longer used (though authorities are). In either case, - * reachability self test is done anymore, since network re-entry towards an - * authority DirPort is not allowed. Thus, consider it always reachable. */ -int -router_dirport_seems_reachable(const or_options_t *options) -{ - (void) options; - return 1; -} - /** See if we currently believe our ORPort to be unreachable. If so, return 1 * else return 0. */ static int diff --git a/src/feature/relay/selftest.h b/src/feature/relay/selftest.h @@ -20,8 +20,6 @@ struct or_options_t; int router_orport_seems_reachable( const struct or_options_t *options, int family); -int router_dirport_seems_reachable( - const struct or_options_t *options); void router_do_reachability_checks(void); void router_perform_bandwidth_test(int num_circs, time_t now);