Browse Source

Merge remote-tracking branch 'tor-github/pr/889'

Nick Mathewson 5 years ago
parent
commit
efeb101b96

+ 5 - 0
changes/bug24490

@@ -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

+ 1 - 6
src/feature/control/fmt_serverstatus.c

@@ -66,11 +66,9 @@ 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();
@@ -78,10 +76,7 @@ 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 (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;

+ 18 - 0
src/feature/dirauth/voteflags.c

@@ -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);
+}

+ 2 - 0
src/feature/dirauth/voteflags.h

@@ -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. */

+ 6 - 6
src/feature/nodelist/networkstatus.c

@@ -2381,7 +2381,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.",
@@ -2398,9 +2397,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));
@@ -2412,11 +2408,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;
@@ -2425,6 +2422,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);