[tor-commits] [tor/master] Sprinkle some consts in networkstatus_getinfo_by_purpose()

nickm at torproject.org nickm at torproject.org
Wed Dec 6 19:37:36 UTC 2017


commit 9acfd70f26ce8ad10c0b4a68de24121abf503c69
Author: teor <teor2345 at gmail.com>
Date:   Sun Oct 15 14:37:32 2017 -0400

    Sprinkle some consts in networkstatus_getinfo_by_purpose()
    
    And note where we change the running flag, but probably shouldn't.
    
    Implements ticket 24489.
---
 changes/bug24489       | 3 +++
 src/or/networkstatus.c | 7 ++++---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/changes/bug24489 b/changes/bug24489
new file mode 100644
index 000000000..6864ba6f5
--- /dev/null
+++ b/changes/bug24489
@@ -0,0 +1,3 @@
+  o Code simplification and refactoring (controller):
+    - Make most of the variables in networkstatus_getinfo_by_purpose() const.
+      Implements ticket 24489.
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index 10d9b7542..eeb72831c 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -2222,13 +2222,13 @@ networkstatus_getinfo_helper_single(const routerstatus_t *rs)
 char *
 networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now)
 {
-  time_t cutoff = now - ROUTER_MAX_AGE_TO_PUBLISH;
+  const time_t cutoff = now - ROUTER_MAX_AGE_TO_PUBLISH;
   char *answer;
   routerlist_t *rl = router_get_routerlist();
   smartlist_t *statuses;
-  uint8_t purpose = router_purpose_from_string(purpose_string);
+  const uint8_t purpose = router_purpose_from_string(purpose_string);
   routerstatus_t rs;
-  int bridge_auth = authdir_mode_bridge(get_options());
+  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.",
@@ -2245,6 +2245,7 @@ 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 */





More information about the tor-commits mailing list