From 853942b71e1a397cbe025dd9c101ccbab4bdaa11 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 30 Apr 2019 11:25:41 -0400 Subject: Make the recommend_pkg file dirauth-only. --- src/core/include.am | 2 +- src/feature/dirauth/recommend_pkg.h | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/include.am b/src/core/include.am index 4ec42182a6..dba957b6b5 100644 --- a/src/core/include.am +++ b/src/core/include.am @@ -157,7 +157,6 @@ LIBTOR_APP_A_SOURCES += \ src/feature/dirauth/dsigs_parse.c \ src/feature/dirauth/guardfraction.c \ src/feature/dirauth/reachability.c \ - src/feature/dirauth/recommend_pkg.c \ src/feature/dirauth/process_descs.c \ src/feature/dirauth/voteflags.c @@ -180,6 +179,7 @@ MODULE_DIRAUTH_SOURCES = \ src/feature/dirauth/dirauth_sys.c \ src/feature/dirauth/dircollate.c \ src/feature/dirauth/dirvote.c \ + src/feature/dirauth/recommend_pkg.c \ src/feature/dirauth/shared_random.c \ src/feature/dirauth/shared_random_state.c diff --git a/src/feature/dirauth/recommend_pkg.h b/src/feature/dirauth/recommend_pkg.h index 8200d78f72..1f97d50177 100644 --- a/src/feature/dirauth/recommend_pkg.h +++ b/src/feature/dirauth/recommend_pkg.h @@ -12,6 +12,18 @@ #ifndef TOR_RECOMMEND_PKG_H #define TOR_RECOMMEND_PKG_H +#ifdef HAVE_MODULE_DIRAUTH int validate_recommended_package_line(const char *line); +#else + +static inline int +validate_recommended_package_line(const char *line) +{ + (void) line; + return 0; +} + +#endif + #endif -- cgit v1.2.3-54-g00ecf From aab02459243ef282849cd5015f3102a907ed1c17 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 30 Apr 2019 11:29:31 -0400 Subject: Make the dsigs_parse.c module dirauth-only. --- src/core/include.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/include.am b/src/core/include.am index dba957b6b5..f3ba10a3df 100644 --- a/src/core/include.am +++ b/src/core/include.am @@ -154,7 +154,6 @@ LIBTOR_APP_A_SOURCES = \ # the separation is only in the code location. LIBTOR_APP_A_SOURCES += \ src/feature/dirauth/bwauth.c \ - src/feature/dirauth/dsigs_parse.c \ src/feature/dirauth/guardfraction.c \ src/feature/dirauth/reachability.c \ src/feature/dirauth/process_descs.c \ @@ -179,6 +178,7 @@ MODULE_DIRAUTH_SOURCES = \ src/feature/dirauth/dirauth_sys.c \ src/feature/dirauth/dircollate.c \ src/feature/dirauth/dirvote.c \ + src/feature/dirauth/dsigs_parse.c \ src/feature/dirauth/recommend_pkg.c \ src/feature/dirauth/shared_random.c \ src/feature/dirauth/shared_random_state.c -- cgit v1.2.3-54-g00ecf From 857bfc70330f9e808c99310f1efbc3fb5738c4fb Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 30 Apr 2019 11:31:03 -0400 Subject: Make the process_descs.c module dirauth-only. --- src/app/main/shutdown.c | 2 -- src/core/include.am | 2 +- src/feature/dirauth/dirauth_sys.c | 3 +++ 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/app/main/shutdown.c b/src/app/main/shutdown.c index 9239a0cf0f..fd9512ce4b 100644 --- a/src/app/main/shutdown.c +++ b/src/app/main/shutdown.c @@ -39,7 +39,6 @@ #include "feature/dirauth/bwauth.h" #include "feature/dirauth/dirvote.h" #include "feature/dirauth/keypin.h" -#include "feature/dirauth/process_descs.h" #include "feature/dirauth/shared_random.h" #include "feature/dircache/consdiffmgr.h" #include "feature/dircache/dirserv.h" @@ -128,7 +127,6 @@ tor_free_all(int postfork) routerlist_free_all(); networkstatus_free_all(); addressmap_free_all(); - dirserv_free_fingerprint_list(); dirserv_free_all(); dirserv_clear_measured_bw_cache(); rend_cache_free_all(); diff --git a/src/core/include.am b/src/core/include.am index f3ba10a3df..02b90ba180 100644 --- a/src/core/include.am +++ b/src/core/include.am @@ -156,7 +156,6 @@ LIBTOR_APP_A_SOURCES += \ src/feature/dirauth/bwauth.c \ src/feature/dirauth/guardfraction.c \ src/feature/dirauth/reachability.c \ - src/feature/dirauth/process_descs.c \ src/feature/dirauth/voteflags.c if BUILD_NT_SERVICES @@ -179,6 +178,7 @@ MODULE_DIRAUTH_SOURCES = \ src/feature/dirauth/dircollate.c \ src/feature/dirauth/dirvote.c \ src/feature/dirauth/dsigs_parse.c \ + src/feature/dirauth/process_descs.c \ src/feature/dirauth/recommend_pkg.c \ src/feature/dirauth/shared_random.c \ src/feature/dirauth/shared_random_state.c diff --git a/src/feature/dirauth/dirauth_sys.c b/src/feature/dirauth/dirauth_sys.c index bb482f2685..b87fa5dc29 100644 --- a/src/feature/dirauth/dirauth_sys.c +++ b/src/feature/dirauth/dirauth_sys.c @@ -9,6 +9,8 @@ #include "feature/dirauth/dirauth_sys.h" #include "feature/dirauth/dirvote.h" #include "feature/dirauth/dirauth_periodic.h" +#include "feature/dirauth/process_descs.h" + #include "lib/subsys/subsys.h" static int @@ -21,6 +23,7 @@ subsys_dirauth_initialize(void) static void subsys_dirauth_shutdown(void) { + dirserv_free_fingerprint_list(); dirvote_free_all(); } -- cgit v1.2.3-54-g00ecf From 339ac4dc67af912e3c8608627e436fb866714538 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 30 Apr 2019 11:31:57 -0400 Subject: Make the guardfraction.c module dirauth-only. --- src/app/config/config.c | 2 ++ src/core/include.am | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/app/config/config.c b/src/app/config/config.c index 81a83e2c5f..3e0683eb56 100644 --- a/src/app/config/config.c +++ b/src/app/config/config.c @@ -3561,10 +3561,12 @@ options_validate(or_options_t *old_options, or_options_t *options, dirserv_read_measured_bandwidths(options->V3BandwidthsFile, NULL, NULL, NULL); } +#ifdef HAVE_MODULE_DIRAUTH /* same for guardfraction file */ if (options->GuardfractionFile && !old_options) { dirserv_read_guardfraction_file(options->GuardfractionFile, NULL); } +#endif } if (options->AuthoritativeDir && !options->DirPort_set) diff --git a/src/core/include.am b/src/core/include.am index 02b90ba180..8ddbdbc0b7 100644 --- a/src/core/include.am +++ b/src/core/include.am @@ -154,7 +154,6 @@ LIBTOR_APP_A_SOURCES = \ # the separation is only in the code location. LIBTOR_APP_A_SOURCES += \ src/feature/dirauth/bwauth.c \ - src/feature/dirauth/guardfraction.c \ src/feature/dirauth/reachability.c \ src/feature/dirauth/voteflags.c @@ -178,6 +177,7 @@ MODULE_DIRAUTH_SOURCES = \ src/feature/dirauth/dircollate.c \ src/feature/dirauth/dirvote.c \ src/feature/dirauth/dsigs_parse.c \ + src/feature/dirauth/guardfraction.c \ src/feature/dirauth/process_descs.c \ src/feature/dirauth/recommend_pkg.c \ src/feature/dirauth/shared_random.c \ -- cgit v1.2.3-54-g00ecf From 996f7c75ba6abd9c4bc884f2c9a3b62889da9134 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 30 Apr 2019 11:33:00 -0400 Subject: Make the reachability.c module dirauth-only. --- src/core/include.am | 2 +- src/feature/nodelist/routerlist.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/include.am b/src/core/include.am index 8ddbdbc0b7..6367b01978 100644 --- a/src/core/include.am +++ b/src/core/include.am @@ -154,7 +154,6 @@ LIBTOR_APP_A_SOURCES = \ # the separation is only in the code location. LIBTOR_APP_A_SOURCES += \ src/feature/dirauth/bwauth.c \ - src/feature/dirauth/reachability.c \ src/feature/dirauth/voteflags.c if BUILD_NT_SERVICES @@ -179,6 +178,7 @@ MODULE_DIRAUTH_SOURCES = \ src/feature/dirauth/dsigs_parse.c \ src/feature/dirauth/guardfraction.c \ src/feature/dirauth/process_descs.c \ + src/feature/dirauth/reachability.c \ src/feature/dirauth/recommend_pkg.c \ src/feature/dirauth/shared_random.c \ src/feature/dirauth/shared_random_state.c diff --git a/src/feature/nodelist/routerlist.c b/src/feature/nodelist/routerlist.c index 48f448ad1e..88a5eeac6a 100644 --- a/src/feature/nodelist/routerlist.c +++ b/src/feature/nodelist/routerlist.c @@ -1926,6 +1926,8 @@ routerlist_remove_old_routers(void) void routerlist_descriptors_added(smartlist_t *sl, int from_cache) { + // XXXX use pubsub mechanism here. + tor_assert(sl); control_event_descriptors_changed(sl); SMARTLIST_FOREACH_BEGIN(sl, routerinfo_t *, ri) { @@ -1933,7 +1935,9 @@ routerlist_descriptors_added(smartlist_t *sl, int from_cache) learned_bridge_descriptor(ri, from_cache); if (ri->needs_retest_if_added) { ri->needs_retest_if_added = 0; +#ifdef HAVE_MODULE_DIRAUTH dirserv_single_reachability_test(approx_time(), ri); +#endif } } SMARTLIST_FOREACH_END(ri); } -- cgit v1.2.3-54-g00ecf From 6f42efaa5926a2f1be89e3b591311f2130931db8 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 30 Apr 2019 12:42:33 -0400 Subject: Move voteflags.[ch] to become dirauth only. For various reasons, this was a nontrivial movement. There are several places in the code where we do something like "update the flags on this routerstatus or node if we're an authority", and at least one where we pretended to be an authority when we weren't. --- src/core/include.am | 9 ++-- src/core/mainloop/mainloop.c | 21 +------- src/feature/control/fmt_serverstatus.c | 1 - src/feature/dirauth/bridgeauth.c | 55 +++++++++++++++++++++ src/feature/dirauth/bridgeauth.h | 12 +++++ src/feature/dirauth/dirauth_periodic.c | 19 ++++++++ src/feature/dirauth/dirvote.c | 4 +- src/feature/dirauth/voteflags.c | 66 +++++++++----------------- src/feature/dirauth/voteflags.h | 12 +++-- src/feature/nodelist/networkstatus.c | 87 +++++++++++++++++----------------- src/feature/nodelist/networkstatus.h | 5 +- src/test/test_voting_flags.c | 2 +- 12 files changed, 173 insertions(+), 120 deletions(-) create mode 100644 src/feature/dirauth/bridgeauth.c create mode 100644 src/feature/dirauth/bridgeauth.h (limited to 'src') diff --git a/src/core/include.am b/src/core/include.am index 6367b01978..63d4264210 100644 --- a/src/core/include.am +++ b/src/core/include.am @@ -153,8 +153,8 @@ LIBTOR_APP_A_SOURCES = \ # These should eventually move into module_dirauth_sources, but for now # the separation is only in the code location. LIBTOR_APP_A_SOURCES += \ - src/feature/dirauth/bwauth.c \ - src/feature/dirauth/voteflags.c + src/feature/dirauth/bwauth.c + if BUILD_NT_SERVICES LIBTOR_APP_A_SOURCES += src/app/main/ntmain.c @@ -171,6 +171,7 @@ LIBTOR_APP_TESTING_A_SOURCES = $(LIBTOR_APP_A_SOURCES) # The Directory Authority module. MODULE_DIRAUTH_SOURCES = \ src/feature/dirauth/authmode.c \ + src/feature/dirauth/bridgeauth.c \ src/feature/dirauth/dirauth_periodic.c \ src/feature/dirauth/dirauth_sys.c \ src/feature/dirauth/dircollate.c \ @@ -181,7 +182,8 @@ MODULE_DIRAUTH_SOURCES = \ src/feature/dirauth/reachability.c \ src/feature/dirauth/recommend_pkg.c \ src/feature/dirauth/shared_random.c \ - src/feature/dirauth/shared_random_state.c + src/feature/dirauth/shared_random_state.c \ + src/feature/dirauth/voteflags.c if BUILD_MODULE_DIRAUTH LIBTOR_APP_A_SOURCES += $(MODULE_DIRAUTH_SOURCES) @@ -310,6 +312,7 @@ noinst_HEADERS += \ src/feature/control/fmt_serverstatus.h \ src/feature/control/getinfo_geoip.h \ src/feature/dirauth/authmode.h \ + src/feature/dirauth/bridgeauth.h \ src/feature/dirauth/bwauth.h \ src/feature/dirauth/dirauth_periodic.h \ src/feature/dirauth/dirauth_sys.h \ diff --git a/src/core/mainloop/mainloop.c b/src/core/mainloop/mainloop.c index 30dad956ae..eb875df023 100644 --- a/src/core/mainloop/mainloop.c +++ b/src/core/mainloop/mainloop.c @@ -75,6 +75,7 @@ #include "feature/control/control.h" #include "feature/control/control_events.h" #include "feature/dirauth/authmode.h" +#include "feature/dirauth/bridgeauth.h" #include "feature/dircache/consdiffmgr.h" #include "feature/dircache/dirserv.h" #include "feature/dircommon/directory.h" @@ -1366,7 +1367,6 @@ CALLBACK(retry_listeners); CALLBACK(rotate_onion_key); CALLBACK(rotate_x509_certificate); CALLBACK(save_state); -CALLBACK(write_bridge_ns); CALLBACK(write_stats_file); CALLBACK(control_per_second_events); CALLBACK(second_elapsed); @@ -1433,9 +1433,6 @@ STATIC periodic_event_item_t mainloop_periodic_events[] = { /* XXXX this could be restricted to CLIENT+NET_PARTICIPANT */ CALLBACK(rend_cache_failure_clean, NET_PARTICIPANT, FL(RUN_ON_DISABLE)), - /* Bridge Authority only. */ - CALLBACK(write_bridge_ns, BRIDGEAUTH, 0), - /* Directory server only. */ CALLBACK(clean_consdiffmgr, DIRSERVER, 0), @@ -2369,22 +2366,6 @@ check_dns_honesty_callback(time_t now, const or_options_t *options) return 12*3600 + crypto_rand_int(12*3600); } -/** - * Periodic callback: if we're the bridge authority, write a networkstatus - * file to disk. - */ -static int -write_bridge_ns_callback(time_t now, const or_options_t *options) -{ - /* 10. write bridge networkstatus file to disk */ - if (options->BridgeAuthoritativeDir) { - networkstatus_dump_bridge_status_to_file(now); -#define BRIDGE_STATUSFILE_INTERVAL (30*60) - return BRIDGE_STATUSFILE_INTERVAL; - } - return PERIODIC_EVENT_NO_UPDATE; -} - static int heartbeat_callback_first_time = 1; /** diff --git a/src/feature/control/fmt_serverstatus.c b/src/feature/control/fmt_serverstatus.c index d224a1d234..a80bf50ad9 100644 --- a/src/feature/control/fmt_serverstatus.c +++ b/src/feature/control/fmt_serverstatus.c @@ -76,7 +76,6 @@ list_server_status_v1(smartlist_t *routers, char **router_status_out, SMARTLIST_FOREACH_BEGIN(routers, routerinfo_t *, ri) { const node_t *node = node_get_by_id(ri->cache_info.identity_digest); tor_assert(node); - if (for_controller) { char name_buf[MAX_VERBOSE_NICKNAME_LEN+2]; char *cp = name_buf; diff --git a/src/feature/dirauth/bridgeauth.c b/src/feature/dirauth/bridgeauth.c new file mode 100644 index 0000000000..4aaefc7a6d --- /dev/null +++ b/src/feature/dirauth/bridgeauth.c @@ -0,0 +1,55 @@ +/* Copyright (c) 2001 Matej Pfajfar. + * Copyright (c) 2001-2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2019, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#include "core/or/or.h" +#include "feature/dirauth/bridgeauth.h" +#include "feature/dirauth/voteflags.h" +#include "feature/nodelist/networkstatus.h" +#include "feature/relay/router.h" +#include "app/config/config.h" + +#include "feature/nodelist/routerinfo_st.h" + +/** Write out router status entries for all our bridge descriptors. Here, we + * also mark routers as running. */ +void +bridgeauth_dump_bridge_status_to_file(time_t now) +{ + char *status; + char *fname = NULL; + char *thresholds = NULL; + char *published_thresholds_and_status = NULL; + char published[ISO_TIME_LEN+1]; + const routerinfo_t *me = router_get_my_routerinfo(); + char fingerprint[FINGERPRINT_LEN+1]; + char *fingerprint_line = NULL; + + dirserv_set_bridges_running(now); + status = networkstatus_getinfo_by_purpose("bridge", now); + + if (me && crypto_pk_get_fingerprint(me->identity_pkey, + fingerprint, 0) >= 0) { + tor_asprintf(&fingerprint_line, "fingerprint %s\n", fingerprint); + } else { + log_warn(LD_BUG, "Error computing fingerprint for bridge status."); + } + format_iso_time(published, now); + dirserv_compute_bridge_flag_thresholds(); + thresholds = dirserv_get_flag_thresholds_line(); + tor_asprintf(&published_thresholds_and_status, + "published %s\nflag-thresholds %s\n%s%s", + published, thresholds, fingerprint_line ? fingerprint_line : "", + status); + fname = get_datadir_fname("networkstatus-bridges"); + if (write_str_to_file(fname,published_thresholds_and_status,0)<0) { + log_warn(LD_DIRSERV, "Unable to write networkstatus-bridges file."); + } + tor_free(thresholds); + tor_free(published_thresholds_and_status); + tor_free(fname); + tor_free(status); + tor_free(fingerprint_line); +} diff --git a/src/feature/dirauth/bridgeauth.h b/src/feature/dirauth/bridgeauth.h new file mode 100644 index 0000000000..cc80fd6375 --- /dev/null +++ b/src/feature/dirauth/bridgeauth.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2001 Matej Pfajfar. + * Copyright (c) 2001-2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2019, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#ifndef TOR_DIRAUTH_BRIDGEAUTH_H +#define TOR_DIRAUTH_BRIDGEAUTH_H + +void bridgeauth_dump_bridge_status_to_file(time_t now); + +#endif diff --git a/src/feature/dirauth/dirauth_periodic.c b/src/feature/dirauth/dirauth_periodic.c index cfbb156b9f..02727d61b4 100644 --- a/src/feature/dirauth/dirauth_periodic.c +++ b/src/feature/dirauth/dirauth_periodic.c @@ -11,6 +11,7 @@ #include "feature/dirauth/reachability.h" #include "feature/stats/rephist.h" +#include "feature/dirauth/bridgeauth.h" #include "feature/dirauth/dirvote.h" #include "feature/dirauth/dirauth_periodic.h" #include "feature/dirauth/authmode.h" @@ -131,6 +132,23 @@ downrate_stability_callback(time_t now, const or_options_t *options) DECLARE_EVENT(downrate_stability, AUTHORITIES, 0); +/** + * Periodic callback: if we're the bridge authority, write a networkstatus + * file to disk. + */ +static int +write_bridge_ns_callback(time_t now, const or_options_t *options) +{ + if (options->BridgeAuthoritativeDir) { + bridgeauth_dump_bridge_status_to_file(now); +#define BRIDGE_STATUSFILE_INTERVAL (30*60) + return BRIDGE_STATUSFILE_INTERVAL; + } + return PERIODIC_EVENT_NO_UPDATE; +} + +DECLARE_EVENT(write_bridge_ns, BRIDGEAUTH, 0); + void dirauth_register_periodic_events(void) { @@ -139,4 +157,5 @@ dirauth_register_periodic_events(void) periodic_events_register(&save_stability_event); periodic_events_register(&check_authority_cert_event); periodic_events_register(&dirvote_event); + periodic_events_register(&write_bridge_ns_event); } diff --git a/src/feature/dirauth/dirvote.c b/src/feature/dirauth/dirvote.c index 1f861d2417..38b583c46a 100644 --- a/src/feature/dirauth/dirvote.c +++ b/src/feature/dirauth/dirvote.c @@ -4545,8 +4545,8 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key, vrs = tor_malloc_zero(sizeof(vote_routerstatus_t)); rs = &vrs->status; - set_routerstatus_from_routerinfo(rs, node, ri, now, - listbadexits); + dirauth_set_routerstatus_from_routerinfo(rs, node, ri, now, + listbadexits); if (ri->cache_info.signing_key_cert) { memcpy(vrs->ed25519_id, diff --git a/src/feature/dirauth/voteflags.c b/src/feature/dirauth/voteflags.c index 957ebe4a4f..f552af98c4 100644 --- a/src/feature/dirauth/voteflags.c +++ b/src/feature/dirauth/voteflags.c @@ -546,38 +546,31 @@ should_publish_node_ipv6(const node_t *node, const routerinfo_t *ri, router_is_me(ri)); } -/** Extract status information from ri and from other authority - * functions and store it in rs. rs is zeroed out before it is - * set. - * - * We assume that ri-\>is_running has already been set, e.g. by - * dirserv_set_router_is_running(ri, now); +/** + * Extract status information from ri and from other authority + * functions and store it in rs, as per + * set_routerstatus_from_routerinfo. Additionally, sets information + * in from the authority subsystem. */ void -set_routerstatus_from_routerinfo(routerstatus_t *rs, - node_t *node, - const routerinfo_t *ri, - time_t now, - int listbadexits) +dirauth_set_routerstatus_from_routerinfo(routerstatus_t *rs, + node_t *node, + const routerinfo_t *ri, + time_t now, + int listbadexits) { const or_options_t *options = get_options(); uint32_t routerbw_kb = dirserv_get_credible_bandwidth_kb(ri); - memset(rs, 0, sizeof(routerstatus_t)); - - rs->is_authority = - router_digest_is_trusted_dir(ri->cache_info.identity_digest); - - /* Already set by compute_performance_thresholds. */ - rs->is_exit = node->is_exit; - rs->is_stable = node->is_stable = - !dirserv_thinks_router_is_unreliable(now, ri, 1, 0); - rs->is_fast = node->is_fast = - !dirserv_thinks_router_is_unreliable(now, ri, 0, 1); - rs->is_flagged_running = node->is_running; /* computed above */ + /* Set these flags so that set_routerstatus_from_routerinfo can copy them. + */ + node->is_stable = !dirserv_thinks_router_is_unreliable(now, ri, 1, 0); + node->is_fast = !dirserv_thinks_router_is_unreliable(now, ri, 0, 1); + node->is_hs_dir = dirserv_thinks_router_is_hs_dir(ri, node, now); - rs->is_valid = node->is_valid; + set_routerstatus_from_routerinfo(rs, node, ri); + /* Override rs->is_possible_guard. */ if (node->is_fast && node->is_stable && ri->supports_tunnelled_dir_requests && ((options->AuthDirGuardBWGuarantee && @@ -593,31 +586,16 @@ set_routerstatus_from_routerinfo(routerstatus_t *rs, rs->is_possible_guard = 0; } + /* Override rs->is_bad_exit */ rs->is_bad_exit = listbadexits && node->is_bad_exit; - rs->is_hs_dir = node->is_hs_dir = - dirserv_thinks_router_is_hs_dir(ri, node, now); - - rs->is_named = rs->is_unnamed = 0; - - rs->published_on = ri->cache_info.published_on; - memcpy(rs->identity_digest, node->identity, DIGEST_LEN); - memcpy(rs->descriptor_digest, ri->cache_info.signed_descriptor_digest, - DIGEST_LEN); - rs->addr = ri->addr; - strlcpy(rs->nickname, ri->nickname, sizeof(rs->nickname)); - rs->or_port = ri->or_port; - rs->dir_port = ri->dir_port; - rs->is_v2_dir = ri->supports_tunnelled_dir_requests; + /* Set rs->is_staledesc. */ rs->is_staledesc = (ri->cache_info.published_on + DESC_IS_STALE_INTERVAL) < now; - if (should_publish_node_ipv6(node, ri, now)) { - /* We're configured as having IPv6 connectivity. There's an IPv6 - OR port and it's reachable so copy it to the routerstatus. */ - tor_addr_copy(&rs->ipv6_addr, &ri->ipv6_addr); - rs->ipv6_orport = ri->ipv6_orport; - } else { + if (! should_publish_node_ipv6(node, ri, now)) { + /* We're not configured as having IPv6 connectivity or the node isn't: + * zero its IPv6 information. */ tor_addr_make_null(&rs->ipv6_addr, AF_INET6); rs->ipv6_orport = 0; } diff --git a/src/feature/dirauth/voteflags.h b/src/feature/dirauth/voteflags.h index 18b29a5183..ee809a290d 100644 --- a/src/feature/dirauth/voteflags.h +++ b/src/feature/dirauth/voteflags.h @@ -12,18 +12,20 @@ #ifndef TOR_VOTEFLAGS_H #define TOR_VOTEFLAGS_H +#ifdef HAVE_MODULE_DIRAUTH void dirserv_set_router_is_running(routerinfo_t *router, time_t now); char *dirserv_get_flag_thresholds_line(void); void dirserv_compute_bridge_flag_thresholds(void); int running_long_enough_to_decide_unreachable(void); -void set_routerstatus_from_routerinfo(routerstatus_t *rs, - node_t *node, - const routerinfo_t *ri, - time_t now, - int listbadexits); +void dirauth_set_routerstatus_from_routerinfo(routerstatus_t *rs, + node_t *node, + const routerinfo_t *ri, + time_t now, + int listbadexits); void dirserv_compute_performance_thresholds(digestmap_t *omit_as_sybil); +#endif void dirserv_set_bridges_running(time_t now); diff --git a/src/feature/nodelist/networkstatus.c b/src/feature/nodelist/networkstatus.c index 22fef81085..c7e337309e 100644 --- a/src/feature/nodelist/networkstatus.c +++ b/src/feature/nodelist/networkstatus.c @@ -2366,6 +2366,49 @@ networkstatus_getinfo_helper_single(const routerstatus_t *rs) NULL); } +/** + * Extract status information from ri and from other authority + * functions and store it in rs. rs is zeroed out before it is + * set. + * + * We assume that node-\>is_running has already been set, e.g. by + * dirserv_set_router_is_running(ri, now); + */ +void +set_routerstatus_from_routerinfo(routerstatus_t *rs, + const node_t *node, + const routerinfo_t *ri) +{ + memset(rs, 0, sizeof(routerstatus_t)); + + rs->is_authority = + router_digest_is_trusted_dir(ri->cache_info.identity_digest); + + /* Set by compute_performance_thresholds or from consensus */ + rs->is_exit = node->is_exit; + rs->is_stable = node->is_stable; + rs->is_fast = node->is_fast; + rs->is_flagged_running = node->is_running; + rs->is_valid = node->is_valid; + rs->is_possible_guard = node->is_possible_guard; + rs->is_bad_exit = node->is_bad_exit; + rs->is_hs_dir = node->is_hs_dir; + rs->is_named = rs->is_unnamed = 0; + + rs->published_on = ri->cache_info.published_on; + memcpy(rs->identity_digest, node->identity, DIGEST_LEN); + memcpy(rs->descriptor_digest, ri->cache_info.signed_descriptor_digest, + DIGEST_LEN); + rs->addr = ri->addr; + strlcpy(rs->nickname, ri->nickname, sizeof(rs->nickname)); + rs->or_port = ri->or_port; + rs->dir_port = ri->dir_port; + rs->is_v2_dir = ri->supports_tunnelled_dir_requests; + + tor_addr_copy(&rs->ipv6_addr, &ri->ipv6_addr); + rs->ipv6_orport = ri->ipv6_orport; +} + /** Alloc and return a string describing routerstatuses for the most * recent info of each router we know about that is of purpose * purpose_string. Return NULL if unrecognized purpose. @@ -2398,8 +2441,7 @@ networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now) continue; if (ri->purpose != purpose) continue; - /* then generate and write out status lines for each of them */ - set_routerstatus_from_routerinfo(&rs, node, ri, now, 0); + set_routerstatus_from_routerinfo(&rs, node, ri); smartlist_add(statuses, networkstatus_getinfo_helper_single(&rs)); } SMARTLIST_FOREACH_END(ri); @@ -2409,47 +2451,6 @@ networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now) return answer; } -/** Write out router status entries for all our bridge descriptors. Here, we - * also mark routers as running. */ -void -networkstatus_dump_bridge_status_to_file(time_t now) -{ - char *status; - char *fname = NULL; - char *thresholds = NULL; - char *published_thresholds_and_status = NULL; - char published[ISO_TIME_LEN+1]; - const routerinfo_t *me = router_get_my_routerinfo(); - char fingerprint[FINGERPRINT_LEN+1]; - char *fingerprint_line = NULL; - - dirserv_set_bridges_running(now); - status = networkstatus_getinfo_by_purpose("bridge", now); - - if (me && crypto_pk_get_fingerprint(me->identity_pkey, - fingerprint, 0) >= 0) { - tor_asprintf(&fingerprint_line, "fingerprint %s\n", fingerprint); - } else { - log_warn(LD_BUG, "Error computing fingerprint for bridge status."); - } - format_iso_time(published, now); - dirserv_compute_bridge_flag_thresholds(); - thresholds = dirserv_get_flag_thresholds_line(); - tor_asprintf(&published_thresholds_and_status, - "published %s\nflag-thresholds %s\n%s%s", - published, thresholds, fingerprint_line ? fingerprint_line : "", - status); - fname = get_datadir_fname("networkstatus-bridges"); - if (write_str_to_file(fname,published_thresholds_and_status,0)<0) { - log_warn(LD_DIRSERV, "Unable to write networkstatus-bridges file."); - } - tor_free(thresholds); - tor_free(published_thresholds_and_status); - tor_free(fname); - tor_free(status); - tor_free(fingerprint_line); -} - /* DOCDOC get_net_param_from_list */ static int32_t get_net_param_from_list(smartlist_t *net_params, const char *param_name, diff --git a/src/feature/nodelist/networkstatus.h b/src/feature/nodelist/networkstatus.h index 8269fc6182..600fd7fbd5 100644 --- a/src/feature/nodelist/networkstatus.h +++ b/src/feature/nodelist/networkstatus.h @@ -122,7 +122,6 @@ void signed_descs_update_status_from_consensus_networkstatus( char *networkstatus_getinfo_helper_single(const routerstatus_t *rs); char *networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now); -void networkstatus_dump_bridge_status_to_file(time_t now); MOCK_DECL(int32_t, networkstatus_get_param, (const networkstatus_t *ns, const char *param_name, int32_t default_val, int32_t min_val, int32_t max_val)); @@ -149,6 +148,10 @@ void vote_routerstatus_free_(vote_routerstatus_t *rs); #define vote_routerstatus_free(rs) \ FREE_AND_NULL(vote_routerstatus_t, vote_routerstatus_free_, (rs)) +void set_routerstatus_from_routerinfo(routerstatus_t *rs, + const node_t *node, + const routerinfo_t *ri); + #ifdef NETWORKSTATUS_PRIVATE #ifdef TOR_UNIT_TESTS STATIC int networkstatus_set_current_consensus_from_ns(networkstatus_t *c, diff --git a/src/test/test_voting_flags.c b/src/test/test_voting_flags.c index 5c9eebd00e..c8111ea5df 100644 --- a/src/test/test_voting_flags.c +++ b/src/test/test_voting_flags.c @@ -60,7 +60,7 @@ check_result(flag_vote_test_cfg_t *c) bool result = false; routerstatus_t rs; memset(&rs, 0, sizeof(rs)); - set_routerstatus_from_routerinfo(&rs, &c->node, &c->ri, c->now, 0); + dirauth_set_routerstatus_from_routerinfo(&rs, &c->node, &c->ri, c->now, 0); tt_i64_op(rs.published_on, OP_EQ, c->expected.published_on); tt_str_op(rs.nickname, OP_EQ, c->expected.nickname); -- cgit v1.2.3-54-g00ecf From 31fb4a78451a98a8d62e1f52e75e372a8a2dd48b Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 30 Apr 2019 12:48:00 -0400 Subject: Make the bwauth.c module dirauth-only. --- src/app/config/config.c | 2 +- src/app/main/shutdown.c | 1 - src/core/include.am | 7 +------ src/feature/dirauth/dirauth_sys.c | 2 ++ 4 files changed, 4 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/app/config/config.c b/src/app/config/config.c index 3e0683eb56..26a3061a26 100644 --- a/src/app/config/config.c +++ b/src/app/config/config.c @@ -3556,12 +3556,12 @@ options_validate(or_options_t *old_options, or_options_t *options, options->V3AuthoritativeDir)) REJECT("AuthoritativeDir is set, but none of " "(Bridge/V3)AuthoritativeDir is set."); +#ifdef HAVE_MODULE_DIRAUTH /* If we have a v3bandwidthsfile and it's broken, complain on startup */ if (options->V3BandwidthsFile && !old_options) { dirserv_read_measured_bandwidths(options->V3BandwidthsFile, NULL, NULL, NULL); } -#ifdef HAVE_MODULE_DIRAUTH /* same for guardfraction file */ if (options->GuardfractionFile && !old_options) { dirserv_read_guardfraction_file(options->GuardfractionFile, NULL); diff --git a/src/app/main/shutdown.c b/src/app/main/shutdown.c index fd9512ce4b..92cd9c6f7b 100644 --- a/src/app/main/shutdown.c +++ b/src/app/main/shutdown.c @@ -128,7 +128,6 @@ tor_free_all(int postfork) networkstatus_free_all(); addressmap_free_all(); dirserv_free_all(); - dirserv_clear_measured_bw_cache(); rend_cache_free_all(); rend_service_authorization_free_all(); rep_hist_free_all(); diff --git a/src/core/include.am b/src/core/include.am index 63d4264210..18b6046bfc 100644 --- a/src/core/include.am +++ b/src/core/include.am @@ -150,12 +150,6 @@ LIBTOR_APP_A_SOURCES = \ src/feature/stats/rephist.c \ src/feature/stats/predict_ports.c -# These should eventually move into module_dirauth_sources, but for now -# the separation is only in the code location. -LIBTOR_APP_A_SOURCES += \ - src/feature/dirauth/bwauth.c - - if BUILD_NT_SERVICES LIBTOR_APP_A_SOURCES += src/app/main/ntmain.c endif @@ -172,6 +166,7 @@ LIBTOR_APP_TESTING_A_SOURCES = $(LIBTOR_APP_A_SOURCES) MODULE_DIRAUTH_SOURCES = \ src/feature/dirauth/authmode.c \ src/feature/dirauth/bridgeauth.c \ + src/feature/dirauth/bwauth.c \ src/feature/dirauth/dirauth_periodic.c \ src/feature/dirauth/dirauth_sys.c \ src/feature/dirauth/dircollate.c \ diff --git a/src/feature/dirauth/dirauth_sys.c b/src/feature/dirauth/dirauth_sys.c index b87fa5dc29..f691d5618a 100644 --- a/src/feature/dirauth/dirauth_sys.c +++ b/src/feature/dirauth/dirauth_sys.c @@ -6,6 +6,7 @@ #include "core/or/or.h" +#include "feature/dirauth/bwauth.h" #include "feature/dirauth/dirauth_sys.h" #include "feature/dirauth/dirvote.h" #include "feature/dirauth/dirauth_periodic.h" @@ -25,6 +26,7 @@ subsys_dirauth_shutdown(void) { dirserv_free_fingerprint_list(); dirvote_free_all(); + dirserv_clear_measured_bw_cache(); } const struct subsys_fns_t sys_dirauth = { -- cgit v1.2.3-54-g00ecf From a45413e7d58363fc4df71376b7cfc56d52534f86 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 30 Apr 2019 12:52:00 -0400 Subject: Make keypin.c dirauth-only --- src/app/main/shutdown.c | 1 - src/core/include.am | 3 +-- src/feature/dirauth/dirauth_sys.c | 2 ++ 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/app/main/shutdown.c b/src/app/main/shutdown.c index 92cd9c6f7b..390a512c13 100644 --- a/src/app/main/shutdown.c +++ b/src/app/main/shutdown.c @@ -97,7 +97,6 @@ tor_cleanup(void) } if (authdir_mode_tests_reachability(options)) rep_hist_record_mtbf_data(now, 0); - keypin_close_journal(); } timers_shutdown(); diff --git a/src/core/include.am b/src/core/include.am index 18b6046bfc..dc7371fedd 100644 --- a/src/core/include.am +++ b/src/core/include.am @@ -81,7 +81,6 @@ LIBTOR_APP_A_SOURCES = \ src/feature/control/control_getinfo.c \ src/feature/control/fmt_serverstatus.c \ src/feature/control/getinfo_geoip.c \ - src/feature/dirauth/keypin.c \ src/feature/dircache/conscache.c \ src/feature/dircache/consdiffmgr.c \ src/feature/dircache/dircache.c \ @@ -118,7 +117,6 @@ LIBTOR_APP_A_SOURCES = \ src/feature/hs_common/replaycache.c \ src/feature/hs_common/shared_random_client.c \ src/feature/keymgt/loadkey.c \ - src/feature/dirauth/keypin.c \ src/feature/nodelist/authcert.c \ src/feature/nodelist/describe.c \ src/feature/nodelist/dirlist.c \ @@ -173,6 +171,7 @@ MODULE_DIRAUTH_SOURCES = \ src/feature/dirauth/dirvote.c \ src/feature/dirauth/dsigs_parse.c \ src/feature/dirauth/guardfraction.c \ + src/feature/dirauth/keypin.c \ src/feature/dirauth/process_descs.c \ src/feature/dirauth/reachability.c \ src/feature/dirauth/recommend_pkg.c \ diff --git a/src/feature/dirauth/dirauth_sys.c b/src/feature/dirauth/dirauth_sys.c index f691d5618a..e38d391300 100644 --- a/src/feature/dirauth/dirauth_sys.c +++ b/src/feature/dirauth/dirauth_sys.c @@ -10,6 +10,7 @@ #include "feature/dirauth/dirauth_sys.h" #include "feature/dirauth/dirvote.h" #include "feature/dirauth/dirauth_periodic.h" +#include "feature/dirauth/keypin.h" #include "feature/dirauth/process_descs.h" #include "lib/subsys/subsys.h" @@ -27,6 +28,7 @@ subsys_dirauth_shutdown(void) dirserv_free_fingerprint_list(); dirvote_free_all(); dirserv_clear_measured_bw_cache(); + keypin_close_journal(); } const struct subsys_fns_t sys_dirauth = { -- cgit v1.2.3-54-g00ecf From 9c3aa22740b79cb55d4c2d523ffb3adb09e02479 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 30 Apr 2019 12:58:00 -0400 Subject: Remove some now-needless dirauth includes --- src/app/main/shutdown.c | 3 --- src/core/mainloop/mainloop.c | 1 - src/feature/nodelist/fmt_routerstatus.c | 41 --------------------------------- 3 files changed, 45 deletions(-) (limited to 'src') diff --git a/src/app/main/shutdown.c b/src/app/main/shutdown.c index 390a512c13..c302ce455c 100644 --- a/src/app/main/shutdown.c +++ b/src/app/main/shutdown.c @@ -36,9 +36,6 @@ #include "feature/control/control.h" #include "feature/control/control_auth.h" #include "feature/dirauth/authmode.h" -#include "feature/dirauth/bwauth.h" -#include "feature/dirauth/dirvote.h" -#include "feature/dirauth/keypin.h" #include "feature/dirauth/shared_random.h" #include "feature/dircache/consdiffmgr.h" #include "feature/dircache/dirserv.h" diff --git a/src/core/mainloop/mainloop.c b/src/core/mainloop/mainloop.c index eb875df023..4401f805d9 100644 --- a/src/core/mainloop/mainloop.c +++ b/src/core/mainloop/mainloop.c @@ -75,7 +75,6 @@ #include "feature/control/control.h" #include "feature/control/control_events.h" #include "feature/dirauth/authmode.h" -#include "feature/dirauth/bridgeauth.h" #include "feature/dircache/consdiffmgr.h" #include "feature/dircache/dirserv.h" #include "feature/dircommon/directory.h" diff --git a/src/feature/nodelist/fmt_routerstatus.c b/src/feature/nodelist/fmt_routerstatus.c index 8c9212e05c..2ada4a7ed5 100644 --- a/src/feature/nodelist/fmt_routerstatus.c +++ b/src/feature/nodelist/fmt_routerstatus.c @@ -14,55 +14,14 @@ #include "core/or/or.h" #include "feature/nodelist/fmt_routerstatus.h" -/* #include "lib/container/buffers.h" */ -/* #include "app/config/config.h" */ -/* #include "app/config/confparse.h" */ -/* #include "core/or/channel.h" */ -/* #include "core/or/channeltls.h" */ -/* #include "core/or/command.h" */ -/* #include "core/mainloop/connection.h" */ -/* #include "core/or/connection_or.h" */ -/* #include "feature/dircache/conscache.h" */ -/* #include "feature/dircache/consdiffmgr.h" */ -/* #include "feature/control/control.h" */ -/* #include "feature/dircache/directory.h" */ -/* #include "feature/dircache/dirserv.h" */ -/* #include "feature/hibernate/hibernate.h" */ -/* #include "feature/dirauth/keypin.h" */ -/* #include "core/mainloop/mainloop.h" */ -/* #include "feature/nodelist/microdesc.h" */ -/* #include "feature/nodelist/networkstatus.h" */ -/* #include "feature/nodelist/nodelist.h" */ #include "core/or/policies.h" -/* #include "core/or/protover.h" */ -/* #include "feature/stats/rephist.h" */ -/* #include "feature/relay/router.h" */ -/* #include "feature/nodelist/dirlist.h" */ #include "feature/nodelist/routerlist.h" - -/* #include "feature/nodelist/routerparse.h" */ -/* #include "feature/nodelist/routerset.h" */ -/* #include "feature/nodelist/torcert.h" */ -/* #include "feature/dircommon/voting_schedule.h" */ - #include "feature/dirauth/dirvote.h" -/* #include "feature/dircache/cached_dir_st.h" */ -/* #include "feature/dircommon/dir_connection_st.h" */ -/* #include "feature/nodelist/extrainfo_st.h" */ -/* #include "feature/nodelist/microdesc_st.h" */ -/* #include "feature/nodelist/node_st.h" */ #include "feature/nodelist/routerinfo_st.h" -/* #include "feature/nodelist/routerlist_st.h" */ -/* #include "core/or/tor_version_st.h" */ #include "feature/nodelist/vote_routerstatus_st.h" -/* #include "lib/compress/compress.h" */ -/* #include "lib/container/order.h" */ #include "lib/crypt_ops/crypto_format.h" -/* #include "lib/encoding/confline.h" */ - -/* #include "lib/encoding/keyval.h" */ /** Helper: write the router-status information in rs into a newly * allocated character buffer. Use the same format as in network-status -- cgit v1.2.3-54-g00ecf