Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tor Trac #24490]: Stop setting bridges running in networkstatus_getinfo_by_purpose() #889

Merged
merged 10 commits into from Apr 26, 2019
@@ -0,0 +1,5 @@
o Minor bugfixes (bridge authority):
- We set bridges as running when we dump the bridge status to a file.
Previously, we set bridges as running in a GETINFO controller, but
these shouldn't modify vital data structures. Fixes bug 24490;
bugfix on 0.2.0.13-alpha. Patch by Neel Chauhan
@@ -66,22 +66,17 @@ list_server_status_v1(smartlist_t *routers, char **router_status_out,
smartlist_t *rs_entries;
time_t now = time(NULL);
time_t cutoff = now - ROUTER_MAX_AGE_TO_PUBLISH;
const or_options_t *options = get_options();
/* We include v2 dir auths here too, because they need to answer
* controllers. Eventually we'll deprecate this whole function;
* see also networkstatus_getinfo_by_purpose(). */
int authdir = authdir_mode_publishes_statuses(options);
tor_assert(router_status_out);

rs_entries = smartlist_new();

SMARTLIST_FOREACH_BEGIN(routers, routerinfo_t *, ri) {
const node_t *node = node_get_by_id(ri->cache_info.identity_digest);
tor_assert(node);
if (authdir) {
/* Update router status in routerinfo_t. */
dirserv_set_router_is_running(ri, now);
}

if (for_controller) {
char name_buf[MAX_VERBOSE_NICKNAME_LEN+2];
char *cp = name_buf;
@@ -29,6 +29,7 @@

#include "feature/nodelist/node_st.h"
#include "feature/nodelist/routerinfo_st.h"
#include "feature/nodelist/routerlist_st.h"
#include "feature/nodelist/vote_routerstatus_st.h"

#include "lib/container/order.h"
@@ -658,3 +659,20 @@ dirserv_set_routerstatus_testing(routerstatus_t *rs)
rs->is_hs_dir = 0;
}
}

/** Use dirserv_set_router_is_running() to set bridges as running if they're
* reachable.
*
* This function is called from set_bridge_running_callback() when running as
* a bridge authority.
*/
void
dirserv_set_bridges_running(time_t now)
{
routerlist_t *rl = router_get_routerlist();

SMARTLIST_FOREACH_BEGIN(rl->routers, routerinfo_t *, ri) {
if (ri->purpose == ROUTER_PURPOSE_BRIDGE)
dirserv_set_router_is_running(ri, now);
} SMARTLIST_FOREACH_END(ri);
}
@@ -25,6 +25,8 @@ void set_routerstatus_from_routerinfo(routerstatus_t *rs,

void dirserv_compute_performance_thresholds(digestmap_t *omit_as_sybil);

void dirserv_set_bridges_running(time_t now);

#ifdef VOTEFLAGS_PRIVATE
/** Any descriptor older than this age causes the authorities to set the
* StaleDesc flag. */
@@ -2378,7 +2378,6 @@ networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now)
smartlist_t *statuses;
const uint8_t purpose = router_purpose_from_string(purpose_string);
routerstatus_t rs;
const int bridge_auth = authdir_mode_bridge(get_options());

if (purpose == ROUTER_PURPOSE_UNKNOWN) {
log_info(LD_DIR, "Unrecognized purpose '%s' when listing router statuses.",
@@ -2395,9 +2394,6 @@ networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now)
continue;
if (ri->purpose != purpose)
continue;
/* TODO: modifying the running flag in a getinfo is a bad idea */
if (bridge_auth && ri->purpose == ROUTER_PURPOSE_BRIDGE)
dirserv_set_router_is_running(ri, now);
/* then generate and write out status lines for each of them */
set_routerstatus_from_routerinfo(&rs, node, ri, now, 0);
smartlist_add(statuses, networkstatus_getinfo_helper_single(&rs));
@@ -2409,11 +2405,12 @@ networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now)
return answer;
}

/** Write out router status entries for all our bridge descriptors. */
/** 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 = networkstatus_getinfo_by_purpose("bridge", now);
char *status;
char *fname = NULL;
char *thresholds = NULL;
char *published_thresholds_and_status = NULL;
@@ -2422,6 +2419,9 @@ networkstatus_dump_bridge_status_to_file(time_t now)
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);