[or-cvs] [tor/master 03/15] Try to make most routerstatus_t interfaces const

nickm at torproject.org nickm at torproject.org
Wed Oct 13 19:59:50 UTC 2010


Author: Nick Mathewson <nickm at torproject.org>
Date: Wed, 29 Sep 2010 01:35:08 -0400
Subject: Try to make most routerstatus_t interfaces const
Commit: 6dd7f85bc7fa9887736feb7604e76d7226d03ca5

---
 src/or/circuitbuild.c  |    2 +-
 src/or/control.c       |    6 ++--
 src/or/control.h       |    2 +-
 src/or/directory.c     |   14 ++++---
 src/or/directory.h     |    4 +-
 src/or/dirserv.c       |    4 +-
 src/or/dirserv.h       |    4 +-
 src/or/networkstatus.c |   88 +++++++++++++++++++++++++++++++++---------------
 src/or/networkstatus.h |   21 ++++++++---
 src/or/nodelist.c      |    2 +-
 src/or/routerlist.c    |   56 +++++++++++++++---------------
 src/or/routerlist.h    |   10 +++---
 12 files changed, 129 insertions(+), 84 deletions(-)

diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index c8e9508..02f361c 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -1402,7 +1402,7 @@ circuit_list_path_impl(origin_circuit_t *circ, int verbose, int verbose_names)
   hop = circ->cpath;
   do {
     const routerinfo_t *ri;
-    routerstatus_t *rs;
+    const routerstatus_t *rs;
     char *elt;
     const char *id;
     if (!hop)
diff --git a/src/or/control.c b/src/or/control.c
index be887f4..7161fea 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -3497,7 +3497,7 @@ control_event_networkstatus_changed_helper(smartlist_t *statuses,
   smartlist_add(strs, tor_strdup("650+"));
   smartlist_add(strs, tor_strdup(event_string));
   smartlist_add(strs, tor_strdup("\r\n"));
-  SMARTLIST_FOREACH(statuses, routerstatus_t *, rs,
+  SMARTLIST_FOREACH(statuses, const routerstatus_t *, rs,
     {
       s = networkstatus_getinfo_helper_single(rs);
       if (!s) continue;
@@ -3588,7 +3588,7 @@ control_event_buildtimeout_set(const circuit_build_times_t *cbt,
 /** Called when a single local_routerstatus_t has changed: Sends an NS event
  * to any controller that cares. */
 int
-control_event_networkstatus_changed_single(routerstatus_t *rs)
+control_event_networkstatus_changed_single(const routerstatus_t *rs)
 {
   smartlist_t *statuses;
   int r;
@@ -3597,7 +3597,7 @@ control_event_networkstatus_changed_single(routerstatus_t *rs)
     return 0;
 
   statuses = smartlist_create();
-  smartlist_add(statuses, rs);
+  smartlist_add(statuses, (void*)rs);
   r = control_event_networkstatus_changed(statuses);
   smartlist_free(statuses);
   return r;
diff --git a/src/or/control.h b/src/or/control.h
index 27ef5c3..275c6de 100644
--- a/src/or/control.h
+++ b/src/or/control.h
@@ -53,7 +53,7 @@ int control_event_my_descriptor_changed(void);
 int control_event_networkstatus_changed(smartlist_t *statuses);
 
 int control_event_newconsensus(const networkstatus_t *consensus);
-int control_event_networkstatus_changed_single(routerstatus_t *rs);
+int control_event_networkstatus_changed_single(const routerstatus_t *rs);
 int control_event_general_status(int severity, const char *format, ...)
   CHECK_PRINTF(2,3);
 int control_event_client_status(int severity, const char *format, ...)
diff --git a/src/or/directory.c b/src/or/directory.c
index 0b40b29..2e0eb00 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -229,7 +229,8 @@ router_supports_extrainfo(const char *identity_digest, int is_authority)
       return 1;
   }
   if (is_authority) {
-    routerstatus_t *rs = router_get_consensus_status_by_id(identity_digest);
+    const routerstatus_t *rs =
+      router_get_consensus_status_by_id(identity_digest);
     if (rs && rs->version_supports_extrainfo_upload)
       return 1;
   }
@@ -328,7 +329,7 @@ void
 directory_get_from_dirserver(uint8_t dir_purpose, uint8_t router_purpose,
                              const char *resource, int pds_flags)
 {
-  routerstatus_t *rs = NULL;
+  const routerstatus_t *rs = NULL;
   or_options_t *options = get_options();
   int prefer_authority = directory_fetches_from_authorities(options);
   int get_via_tor = purpose_needs_anonymity(dir_purpose, router_purpose);
@@ -512,7 +513,7 @@ directory_get_from_all_authorities(uint8_t dir_purpose,
 /** Same as directory_initiate_command_routerstatus(), but accepts
  * rendezvous data to fetch a hidden service descriptor. */
 void
-directory_initiate_command_routerstatus_rend(routerstatus_t *status,
+directory_initiate_command_routerstatus_rend(const routerstatus_t *status,
                                              uint8_t dir_purpose,
                                              uint8_t router_purpose,
                                              int anonymized_connection,
@@ -566,7 +567,7 @@ directory_initiate_command_routerstatus_rend(routerstatus_t *status,
  * want to fetch.
  */
 void
-directory_initiate_command_routerstatus(routerstatus_t *status,
+directory_initiate_command_routerstatus(const routerstatus_t *status,
                                         uint8_t dir_purpose,
                                         uint8_t router_purpose,
                                         int anonymized_connection,
@@ -1597,7 +1598,8 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
                "'%s:%d'. I'll try again soon.",
                status_code, escaped(reason), conn->_base.address,
                conn->_base.port);
-      if ((rs = router_get_consensus_status_by_id(conn->identity_digest)))
+      rs = router_get_mutable_consensus_status_by_id(conn->identity_digest);
+      if (rs)
         rs->last_dir_503_at = now;
       if ((ds = router_get_trusteddirserver_by_digest(conn->identity_digest)))
         ds->fake_status.last_dir_503_at = now;
@@ -3692,7 +3694,7 @@ dir_microdesc_download_failed(smartlist_t *failed,
   if (! consensus)
     return;
   SMARTLIST_FOREACH_BEGIN(failed, const char *, d) {
-    rs = router_get_consensus_status_by_descriptor_digest(consensus, d);
+    rs = router_get_mutable_consensus_status_by_descriptor_digest(consensus, d);
     if (!rs)
       continue;
     dls = &rs->dl_status;
diff --git a/src/or/directory.h b/src/or/directory.h
index 6fd2c0b..5782df9 100644
--- a/src/or/directory.h
+++ b/src/or/directory.h
@@ -23,7 +23,7 @@ void directory_get_from_dirserver(uint8_t dir_purpose, uint8_t router_purpose,
 void directory_get_from_all_authorities(uint8_t dir_purpose,
                                         uint8_t router_purpose,
                                         const char *resource);
-void directory_initiate_command_routerstatus(routerstatus_t *status,
+void directory_initiate_command_routerstatus(const routerstatus_t *status,
                                              uint8_t dir_purpose,
                                              uint8_t router_purpose,
                                              int anonymized_connection,
@@ -31,7 +31,7 @@ void directory_initiate_command_routerstatus(routerstatus_t *status,
                                              const char *payload,
                                              size_t payload_len,
                                              time_t if_modified_since);
-void directory_initiate_command_routerstatus_rend(routerstatus_t *status,
+void directory_initiate_command_routerstatus_rend(const routerstatus_t *status,
                                                   uint8_t dir_purpose,
                                                   uint8_t router_purpose,
                                                   int anonymized_connection,
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 148147b..0da12e4 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -326,7 +326,7 @@ dirserv_router_get_status(const routerinfo_t *router, const char **msg)
 /** Return true if there is no point in downloading the router described by
  * <b>rs</b> because this directory would reject it. */
 int
-dirserv_would_reject_router(routerstatus_t *rs)
+dirserv_would_reject_router(const routerstatus_t *rs)
 {
   uint32_t res;
 
@@ -1951,7 +1951,7 @@ version_from_platform(const char *platform)
  */
 int
 routerstatus_format_entry(char *buf, size_t buf_len,
-                          routerstatus_t *rs, const char *version,
+                          const routerstatus_t *rs, const char *version,
                           routerstatus_format_type_t format)
 {
   int r;
diff --git a/src/or/dirserv.h b/src/or/dirserv.h
index 9be4935..f14aee6 100644
--- a/src/or/dirserv.h
+++ b/src/or/dirserv.h
@@ -105,7 +105,7 @@ void dirserv_single_reachability_test(time_t now, routerinfo_t *router);
 void dirserv_test_reachability(time_t now);
 int authdir_wants_to_reject_router(routerinfo_t *ri, const char **msg,
                                    int complain);
-int dirserv_would_reject_router(routerstatus_t *rs);
+int dirserv_would_reject_router(const routerstatus_t *rs);
 int dirserv_remove_old_statuses(smartlist_t *fps, time_t cutoff);
 int dirserv_have_any_serverdesc(smartlist_t *fps, int spool_src);
 int dirserv_have_any_microdesc(const smartlist_t *fps);
@@ -114,7 +114,7 @@ size_t dirserv_estimate_data_size(smartlist_t *fps, int is_serverdescs,
 size_t dirserv_estimate_microdesc_size(const smartlist_t *fps, int compressed);
 
 int routerstatus_format_entry(char *buf, size_t buf_len,
-                              routerstatus_t *rs, const char *platform,
+                              const routerstatus_t *rs, const char *platform,
                               routerstatus_format_type_t format);
 void dirserv_free_all(void);
 void cached_dir_decref(cached_dir_t *d);
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index 3451a2d..e5dd4a9 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -940,10 +940,9 @@ compare_digest_to_routerstatus_entry(const void *_key, const void **_member)
   return memcmp(key, rs->identity_digest, DIGEST_LEN);
 }
 
-/** Return the entry in <b>ns</b> for the identity digest <b>digest</b>, or
- * NULL if none was found. */
+/** As networkstatus_v2_find_entry, but do not return a const pointer */
 routerstatus_t *
-networkstatus_v2_find_entry(networkstatus_v2_t *ns, const char *digest)
+networkstatus_v2_find_mutable_entry(networkstatus_v2_t *ns, const char *digest)
 {
   return smartlist_bsearch(ns->entries, digest,
                            compare_digest_to_routerstatus_entry);
@@ -951,13 +950,28 @@ networkstatus_v2_find_entry(networkstatus_v2_t *ns, const char *digest)
 
 /** Return the entry in <b>ns</b> for the identity digest <b>digest</b>, or
  * NULL if none was found. */
+const routerstatus_t *
+networkstatus_v2_find_entry(networkstatus_v2_t *ns, const char *digest)
+{
+  return networkstatus_v2_find_mutable_entry(ns, digest);
+}
+
+/** As networkstatus_find_entry, but do not return a const pointer */
 routerstatus_t *
-networkstatus_vote_find_entry(networkstatus_t *ns, const char *digest)
+networkstatus_vote_find_mutable_entry(networkstatus_t *ns, const char *digest)
 {
   return smartlist_bsearch(ns->routerstatus_list, digest,
                            compare_digest_to_routerstatus_entry);
 }
 
+/** Return the entry in <b>ns</b> for the identity digest <b>digest</b>, or
+ * NULL if none was found. */
+const routerstatus_t *
+networkstatus_vote_find_entry(networkstatus_t *ns, const char *digest)
+{
+  return networkstatus_vote_find_mutable_entry(ns, digest);
+}
+
 /*XXXX make this static once functions are moved into this file. */
 /** Search the routerstatuses in <b>ns</b> for one whose identity digest is
  * <b>digest</b>.  Return value and set *<b>found_out</b> as for
@@ -980,11 +994,11 @@ networkstatus_get_v2_list(void)
   return networkstatus_v2_list;
 }
 
-/** Return the consensus view of the status of the router whose current
- * <i>descriptor</i> digest in <b>consensus</b> is <b>digest</b>, or NULL if
- * no such router is known. */
+/* As router_get_consensus_status_by_descriptor_digest, but does not return
+ * a const pointer */
 routerstatus_t *
-router_get_consensus_status_by_descriptor_digest(networkstatus_t *consensus,
+router_get_mutable_consensus_status_by_descriptor_digest(
+                                                 networkstatus_t *consensus,
                                                  const char *digest)
 {
   if (!consensus)
@@ -1002,6 +1016,17 @@ router_get_consensus_status_by_descriptor_digest(networkstatus_t *consensus,
   return digestmap_get(consensus->desc_digest_map, digest);
 }
 
+/** Return the consensus view of the status of the router whose current
+ * <i>descriptor</i> digest in <b>consensus</b> is <b>digest</b>, or NULL if
+ * no such router is known. */
+const routerstatus_t *
+router_get_consensus_status_by_descriptor_digest(networkstatus_t *consensus,
+                                                 const char *digest)
+{
+  return router_get_mutable_consensus_status_by_descriptor_digest(
+                                                          consensus, digest);
+}
+
 /** Given the digest of a router descriptor, return its current download
  * status, or NULL if the digest is unrecognized. */
 download_status_t *
@@ -1010,8 +1035,8 @@ router_get_dl_status_by_descriptor_digest(const char *d)
   routerstatus_t *rs;
   if (!current_ns_consensus)
     return NULL;
-  if ((rs = router_get_consensus_status_by_descriptor_digest(
-                                                 current_ns_consensus, d)))
+  if ((rs = router_get_mutable_consensus_status_by_descriptor_digest(
+                                              current_ns_consensus, d)))
     return &rs->dl_status;
   if (v2_download_status_map)
     return digestmap_get(v2_download_status_map, d);
@@ -1019,10 +1044,9 @@ router_get_dl_status_by_descriptor_digest(const char *d)
   return NULL;
 }
 
-/** Return the consensus view of the status of the router whose identity
- * digest is <b>digest</b>, or NULL if we don't know about any such router. */
+/** As router_get_consensus_status_by_id, but do not return a const pointer */
 routerstatus_t *
-router_get_consensus_status_by_id(const char *digest)
+router_get_mutable_consensus_status_by_id(const char *digest)
 {
   if (!current_consensus)
     return NULL;
@@ -1030,11 +1054,19 @@ router_get_consensus_status_by_id(const char *digest)
                            compare_digest_to_routerstatus_entry);
 }
 
+/** Return the consensus view of the status of the router whose identity
+ * digest is <b>digest</b>, or NULL if we don't know about any such router. */
+const routerstatus_t *
+router_get_consensus_status_by_id(const char *digest)
+{
+  return router_get_mutable_consensus_status_by_id(digest);
+}
+
 /** Given a nickname (possibly verbose, possibly a hexadecimal digest), return
  * the corresponding routerstatus_t, or NULL if none exists.  Warn the
  * user if <b>warn_if_unnamed</b> is set, and they have specified a router by
  * nickname, but the Named flag isn't set for that router. */
-routerstatus_t *
+const routerstatus_t *
 router_get_consensus_status_by_nickname(const char *nickname,
                                         int warn_if_unnamed)
 {
@@ -1566,13 +1598,14 @@ notify_control_networkstatus_changed(const networkstatus_t *old_c,
   }
   changed = smartlist_create();
 
-  SMARTLIST_FOREACH_JOIN(old_c->routerstatus_list, routerstatus_t *, rs_old,
-                         new_c->routerstatus_list, routerstatus_t *, rs_new,
-                         memcmp(rs_old->identity_digest,
-                                rs_new->identity_digest, DIGEST_LEN),
-                         smartlist_add(changed, rs_new)) {
+  SMARTLIST_FOREACH_JOIN(
+                     old_c->routerstatus_list, const routerstatus_t *, rs_old,
+                     new_c->routerstatus_list, const routerstatus_t *, rs_new,
+                     memcmp(rs_old->identity_digest,
+                            rs_new->identity_digest, DIGEST_LEN),
+                     smartlist_add(changed, (void*) rs_new)) {
     if (routerstatus_has_changed(rs_old, rs_new))
-      smartlist_add(changed, rs_new);
+      smartlist_add(changed, (void*)rs_new);
   } SMARTLIST_FOREACH_JOIN_END(rs_old, rs_new);
 
   control_event_networkstatus_changed(changed);
@@ -1978,7 +2011,7 @@ download_status_map_update_from_v2_networkstatus(void)
 
   dl_status = digestmap_new();
   SMARTLIST_FOREACH_BEGIN(networkstatus_v2_list, networkstatus_v2_t *, ns) {
-    SMARTLIST_FOREACH_BEGIN(ns->entries, routerstatus_t *, rs) {
+    SMARTLIST_FOREACH_BEGIN(ns->entries, const routerstatus_t *, rs) {
       const char *d = rs->descriptor_digest;
       download_status_t *s;
       if (digestmap_get(dl_status, d))
@@ -2006,7 +2039,8 @@ routerstatus_list_update_named_server_map(void)
   named_server_map = strmap_new();
   strmap_free(unnamed_server_map, NULL);
   unnamed_server_map = strmap_new();
-  SMARTLIST_FOREACH(current_consensus->routerstatus_list, routerstatus_t *, rs,
+  SMARTLIST_FOREACH(current_consensus->routerstatus_list,
+                                                   const routerstatus_t *, rs,
     {
       if (rs->is_named) {
         strmap_set_lc(named_server_map, rs->nickname,
@@ -2101,7 +2135,7 @@ routers_update_status_from_consensus_networkstatus(smartlist_t *routers,
   /* XXXX If this is slow, we need to rethink the code. */
   SMARTLIST_FOREACH(networkstatus_v2_list, networkstatus_v2_t *, ns, {
     time_t live_until = ns->published_on + V2_NETWORKSTATUS_ROUTER_LIFETIME;
-    SMARTLIST_FOREACH_JOIN(ns->entries, routerstatus_t *, rs,
+    SMARTLIST_FOREACH_JOIN(ns->entries, const routerstatus_t *, rs,
                          routers, routerinfo_t *, ri,
                          memcmp(rs->identity_digest,
                                 ri->cache_info.identity_digest, DIGEST_LEN),
@@ -2134,7 +2168,7 @@ signed_descs_update_status_from_consensus_networkstatus(smartlist_t *descs)
   }
   SMARTLIST_FOREACH(descs, signed_descriptor_t *, d,
   {
-    routerstatus_t *rs = digestmap_get(ns->desc_digest_map,
+    const routerstatus_t *rs = digestmap_get(ns->desc_digest_map,
                                        d->signed_descriptor_digest);
     if (rs) {
       if (ns->valid_until > d->last_listed_as_valid_until)
@@ -2147,7 +2181,7 @@ signed_descs_update_status_from_consensus_networkstatus(smartlist_t *descs)
  * return the result in a newly allocated string.  Used only by controller
  * interface (for now.) */
 char *
-networkstatus_getinfo_helper_single(routerstatus_t *rs)
+networkstatus_getinfo_helper_single(const routerstatus_t *rs)
 {
   char buf[RS_ENTRY_LEN+1];
   routerstatus_format_entry(buf, sizeof(buf), rs, NULL, NS_CONTROL_PORT);
@@ -2303,7 +2337,7 @@ getinfo_helper_networkstatus(control_connection_t *conn,
                              const char *question, char **answer,
                              const char **errmsg)
 {
-  routerstatus_t *status;
+  const routerstatus_t *status;
   (void) conn;
 
   if (!current_consensus) {
@@ -2314,7 +2348,7 @@ getinfo_helper_networkstatus(control_connection_t *conn,
   if (!strcmp(question, "ns/all")) {
     smartlist_t *statuses = smartlist_create();
     SMARTLIST_FOREACH(current_consensus->routerstatus_list,
-                      routerstatus_t *, rs,
+                      const routerstatus_t *, rs,
       {
         smartlist_add(statuses, networkstatus_getinfo_helper_single(rs));
       });
diff --git a/src/or/networkstatus.h b/src/or/networkstatus.h
index adaddc4..61c475d 100644
--- a/src/or/networkstatus.h
+++ b/src/or/networkstatus.h
@@ -38,19 +38,28 @@ int router_set_networkstatus_v2(const char *s, time_t arrived_at,
 void networkstatus_v2_list_clean(time_t now);
 int compare_digest_to_routerstatus_entry(const void *_key,
                                          const void **_member);
-routerstatus_t *networkstatus_v2_find_entry(networkstatus_v2_t *ns,
+const routerstatus_t *networkstatus_v2_find_entry(networkstatus_v2_t *ns,
                                          const char *digest);
-routerstatus_t *networkstatus_vote_find_entry(networkstatus_t *ns,
+const routerstatus_t *networkstatus_vote_find_entry(networkstatus_t *ns,
+                                              const char *digest);
+routerstatus_t *networkstatus_v2_find_mutable_entry(networkstatus_v2_t *ns,
+                                        const char *digest);
+routerstatus_t *networkstatus_vote_find_mutable_entry(networkstatus_t *ns,
                                               const char *digest);
 int networkstatus_vote_find_entry_idx(networkstatus_t *ns,
                                       const char *digest, int *found_out);
 const smartlist_t *networkstatus_get_v2_list(void);
 download_status_t *router_get_dl_status_by_descriptor_digest(const char *d);
-routerstatus_t *router_get_consensus_status_by_id(const char *digest);
-routerstatus_t *router_get_consensus_status_by_descriptor_digest(
+const routerstatus_t *router_get_consensus_status_by_id(const char *digest);
+routerstatus_t *router_get_mutable_consensus_status_by_id(
+                                   const char *digest);
+const routerstatus_t *router_get_consensus_status_by_descriptor_digest(
+                                   networkstatus_t *consensus,
+                                   const char *digest);
+routerstatus_t *router_get_mutable_consensus_status_by_descriptor_digest(
                                    networkstatus_t *consensus,
                                    const char *digest);
-routerstatus_t *router_get_consensus_status_by_nickname(const char *nickname,
+const routerstatus_t *router_get_consensus_status_by_nickname(const char *nickname,
                                                        int warn_if_unnamed);
 const char *networkstatus_get_router_digest_by_nickname(const char *nickname);
 int networkstatus_nickname_is_unnamed(const char *nickname);
@@ -83,7 +92,7 @@ void routers_update_status_from_consensus_networkstatus(smartlist_t *routers,
 void signed_descs_update_status_from_consensus_networkstatus(
                                                          smartlist_t *descs);
 
-char *networkstatus_getinfo_helper_single(routerstatus_t *rs);
+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);
 int32_t get_net_param_from_list(smartlist_t *net_params, const char *name,
diff --git a/src/or/nodelist.c b/src/or/nodelist.c
index 9c8714c..b620b40 100644
--- a/src/or/nodelist.c
+++ b/src/or/nodelist.c
@@ -122,7 +122,7 @@ nodelist_add_microdesc(microdesc_t *md)
 {
   networkstatus_t *ns =
     networkstatus_get_latest_consensus_by_flavor(FLAV_MICRODESC);
-  routerstatus_t *rs;
+  const routerstatus_t *rs;
   node_t *node;
   if (ns == NULL)
     return NULL;
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index d2edead..0f1bfc0 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -39,9 +39,9 @@
 /****************************************************************************/
 
 /* static function prototypes */
-static routerstatus_t *router_pick_directory_server_impl(
+static const routerstatus_t *router_pick_directory_server_impl(
                                            authority_type_t auth, int flags);
-static routerstatus_t *router_pick_trusteddirserver_impl(
+static const routerstatus_t *router_pick_trusteddirserver_impl(
                           authority_type_t auth, int flags, int *n_busy_out);
 static void mark_all_trusteddirservers_up(void);
 static int router_nickname_matches(const routerinfo_t *router,
@@ -927,10 +927,10 @@ router_get_trusted_dir_servers(void)
  * Don't pick an authority if any non-authority is viable; try to avoid using
  * servers that have returned 503 recently.
  */
-routerstatus_t *
+const routerstatus_t *
 router_pick_directory_server(authority_type_t type, int flags)
 {
-  routerstatus_t *choice;
+  const routerstatus_t *choice;
   if (get_options()->PreferTunneledDirConns)
     flags |= _PDS_PREFER_TUNNELED_DIR_CONNS;
 
@@ -960,7 +960,7 @@ router_get_my_share_of_directory_requests(double *v2_share_out,
                                           double *v3_share_out)
 {
   const routerinfo_t *me = router_get_my_routerinfo();
-  routerstatus_t *rs;
+  const routerstatus_t *rs;
   const int pds_flags = PDS_ALLOW_SELF|PDS_IGNORE_FASCISTFIREWALL;
   *v2_share_out = *v3_share_out = 0.0;
   if (!me)
@@ -1033,10 +1033,10 @@ trusteddirserver_get_by_v3_auth_digest(const char *digest)
 /** Try to find a running trusted dirserver.  Flags are as for
  * router_pick_directory_server.
  */
-routerstatus_t *
+const routerstatus_t *
 router_pick_trusteddirserver(authority_type_t type, int flags)
 {
-  routerstatus_t *choice;
+  const routerstatus_t *choice;
   int busy = 0;
   if (get_options()->PreferTunneledDirConns)
     flags |= _PDS_PREFER_TUNNELED_DIR_CONNS;
@@ -1069,10 +1069,10 @@ router_pick_trusteddirserver(authority_type_t type, int flags)
  * If the _PDS_PREFER_TUNNELED_DIR_CONNS flag is set, prefer directory servers
  * that we can use with BEGINDIR.
  */
-static routerstatus_t *
+static const routerstatus_t *
 router_pick_directory_server_impl(authority_type_t type, int flags)
 {
-  routerstatus_t *result;
+  const routerstatus_t *result;
   smartlist_t *direct, *tunnel;
   smartlist_t *trusted_direct, *trusted_tunnel;
   smartlist_t *overloaded_direct, *overloaded_tunnel;
@@ -1163,14 +1163,14 @@ router_pick_directory_server_impl(authority_type_t type, int flags)
 /** Choose randomly from among the trusted dirservers that are up.  Flags
  * are as for router_pick_directory_server_impl().
  */
-static routerstatus_t *
+static const routerstatus_t *
 router_pick_trusteddirserver_impl(authority_type_t type, int flags,
                                   int *n_busy_out)
 {
   smartlist_t *direct, *tunnel;
   smartlist_t *overloaded_direct, *overloaded_tunnel;
   const routerinfo_t *me = router_get_my_routerinfo();
-  routerstatus_t *result;
+  const routerstatus_t *result;
   time_t now = time(NULL);
   const int requireother = ! (flags & PDS_ALLOW_SELF);
   const int fascistfirewall = ! (flags & PDS_IGNORE_FASCISTFIREWALL);
@@ -1273,7 +1273,7 @@ mark_all_trusteddirservers_up(void)
       routerstatus_t *rs;
       dir->is_running = 1;
       download_status_reset(&dir->v2_ns_dl_status);
-      rs = router_get_consensus_status_by_id(dir->digest);
+      rs = router_get_mutable_consensus_status_by_id(dir->digest);
       if (rs && !rs->is_running) {
         rs->is_running = 1;
         rs->last_dir_503_at = 0;
@@ -1748,7 +1748,7 @@ smartlist_choose_by_bandwidth_weights(smartlist_t *sl,
       if (router_digest_is_me(status->identity_digest))
         is_me = 1;
     } else {
-      routerstatus_t *rs;
+      const routerstatus_t *rs;
       routerinfo_t *router = smartlist_get(sl, i);
       rs = router_get_consensus_status_by_id(
              router->cache_info.identity_digest);
@@ -1911,7 +1911,7 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, bandwidth_weight_rule_t rule,
         flags |= is_guard ? 4 : 0;
       }
     } else {
-      routerstatus_t *rs;
+      const routerstatus_t *rs;
       router = smartlist_get(sl, i);
       rs = router_get_consensus_status_by_id(
              router->cache_info.identity_digest);
@@ -2112,7 +2112,7 @@ routerlist_sl_choose_by_bandwidth(smartlist_t *sl,
 /** Choose a random element of status list <b>sl</b>, weighted by
  * the advertised bandwidth of each status.
  */
-routerstatus_t *
+const routerstatus_t *
 routerstatus_sl_choose_by_bandwidth(smartlist_t *sl,
                                     bandwidth_weight_rule_t rule)
 {
@@ -2317,15 +2317,14 @@ router_get_by_nickname(const char *nickname, int warn_if_unnamed)
     if (warn_if_unnamed && n_matches > 1) {
       smartlist_t *fps = smartlist_create();
       int any_unwarned = 0;
-      SMARTLIST_FOREACH(routerlist->routers, routerinfo_t *, router,
-        {
+      SMARTLIST_FOREACH_BEGIN(routerlist->routers, routerinfo_t *, router) {
           routerstatus_t *rs;
           char *desc;
           size_t dlen;
           char fp[HEX_DIGEST_LEN+1];
           if (strcasecmp(router->nickname, nickname))
             continue;
-          rs = router_get_consensus_status_by_id(
+          rs = router_get_mutable_consensus_status_by_id(
                                           router->cache_info.identity_digest);
           if (rs && !rs->name_lookup_warned) {
             rs->name_lookup_warned = 1;
@@ -2338,7 +2337,7 @@ router_get_by_nickname(const char *nickname, int warn_if_unnamed)
           tor_snprintf(desc, dlen, "\"$%s\" for the one at %s:%d",
                        fp, router->address, router->or_port);
           smartlist_add(fps, desc);
-        });
+      } SMARTLIST_FOREACH_END(router);
       if (any_unwarned) {
         char *alternatives = smartlist_join_strings(fps, "; ",0,NULL);
         log_warn(LD_CONFIG,
@@ -2351,7 +2350,7 @@ router_get_by_nickname(const char *nickname, int warn_if_unnamed)
       SMARTLIST_FOREACH(fps, char *, cp, tor_free(cp));
       smartlist_free(fps);
     } else if (warn_if_unnamed) {
-      routerstatus_t *rs = router_get_consensus_status_by_id(
+      routerstatus_t *rs = router_get_mutable_consensus_status_by_id(
           best_match->cache_info.identity_digest);
       if (rs && !rs->name_lookup_warned) {
         char fp[HEX_DIGEST_LEN+1];
@@ -3180,7 +3179,7 @@ router_set_status(const char *digest, int up)
                "addresses reachable?");
     router->is_running = up;
   }
-  status = router_get_consensus_status_by_id(digest);
+  status = router_get_mutable_consensus_status_by_id(digest);
   if (status && status->is_running != up) {
     status->is_running = up;
     control_event_networkstatus_changed_single(status);
@@ -3282,14 +3281,15 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg,
   SMARTLIST_FOREACH(networkstatus_v2_list, networkstatus_v2_t *, ns,
   {
     routerstatus_t *rs =
-      networkstatus_v2_find_entry(ns, id_digest);
+      networkstatus_v2_find_mutable_entry(ns, id_digest);
     if (rs && !memcmp(rs->descriptor_digest,
                       router->cache_info.signed_descriptor_digest,
                       DIGEST_LEN))
       rs->need_to_mirror = 0;
   });
   if (consensus) {
-    routerstatus_t *rs = networkstatus_vote_find_entry(consensus, id_digest);
+    routerstatus_t *rs = networkstatus_vote_find_mutable_entry(
+                                                     consensus, id_digest);
     if (rs && !memcmp(rs->descriptor_digest,
                       router->cache_info.signed_descriptor_digest,
                       DIGEST_LEN)) {
@@ -3889,7 +3889,7 @@ router_load_extrainfo_from_string(const char *s, const char *eos,
 static int
 signed_desc_digest_is_recognized(signed_descriptor_t *desc)
 {
-  routerstatus_t *rs;
+  const routerstatus_t *rs;
   networkstatus_t *consensus = networkstatus_get_latest_consensus();
   int caches = directory_caches_dir_info(get_options());
   const smartlist_t *networkstatus_v2_list = networkstatus_get_v2_list();
@@ -4144,7 +4144,7 @@ list_pending_microdesc_downloads(digestmap_t *result)
  * otherwise, download from an appropriate random directory server.
  */
 static void
-initiate_descriptor_downloads(routerstatus_t *source,
+initiate_descriptor_downloads(const routerstatus_t *source,
                               int purpose,
                               smartlist_t *digests,
                               int lo, int hi, int pds_flags)
@@ -4256,7 +4256,7 @@ client_would_use_router(routerstatus_t *rs, time_t now, or_options_t *options)
 void
 launch_descriptor_downloads(int purpose,
                             smartlist_t *downloadable,
-                            routerstatus_t *source, time_t now)
+                            const routerstatus_t *source, time_t now)
 {
   int should_delay = 0, n_downloadable;
   or_options_t *options = get_options();
@@ -5540,7 +5540,7 @@ routerset_contains_router(const routerset_t *set, const routerinfo_t *ri)
 
 /** Return true iff <b>rs</b> is in <b>set</b>. */
 int
-routerset_contains_routerstatus(const routerset_t *set, routerstatus_t *rs)
+routerset_contains_routerstatus(const routerset_t *set, const routerstatus_t *rs)
 {
   tor_addr_t addr;
   tor_addr_from_ipv4h(&addr, rs->addr);
@@ -5752,7 +5752,7 @@ hid_serv_acting_as_directory(void)
 {
   const routerinfo_t *me = router_get_my_routerinfo();
   networkstatus_t *c;
-  routerstatus_t *rs;
+  const routerstatus_t *rs;
   if (!me)
     return 0;
   if (!get_options()->HidServDirectoryV2) {
diff --git a/src/or/routerlist.h b/src/or/routerlist.h
index a805469..90975e7 100644
--- a/src/or/routerlist.h
+++ b/src/or/routerlist.h
@@ -27,10 +27,10 @@ int router_reload_router_list(void);
 int authority_cert_dl_looks_uncertain(const char *id_digest);
 smartlist_t *router_get_trusted_dir_servers(void);
 
-routerstatus_t *router_pick_directory_server(authority_type_t type, int flags);
+const routerstatus_t *router_pick_directory_server(authority_type_t type, int flags);
 trusted_dir_server_t *router_get_trusteddirserver_by_digest(const char *d);
 trusted_dir_server_t *trusteddirserver_get_by_v3_auth_digest(const char *d);
-routerstatus_t *router_pick_trusteddirserver(authority_type_t type, int flags);
+const routerstatus_t *router_pick_trusteddirserver(authority_type_t type, int flags);
 int router_get_my_share_of_directory_requests(double *v2_share_out,
                                               double *v3_share_out);
 void router_reset_status_download_failures(void);
@@ -50,7 +50,7 @@ uint32_t router_get_advertised_bandwidth_capped(const routerinfo_t *router);
 
 const routerinfo_t *routerlist_sl_choose_by_bandwidth(smartlist_t *sl,
                                                 bandwidth_weight_rule_t rule);
-routerstatus_t *routerstatus_sl_choose_by_bandwidth(smartlist_t *sl,
+const routerstatus_t *routerstatus_sl_choose_by_bandwidth(smartlist_t *sl,
                                                 bandwidth_weight_rule_t rule);
 
 const routerinfo_t *router_choose_random_node(smartlist_t *excludedsmartlist,
@@ -172,7 +172,7 @@ int routerset_is_list(const routerset_t *set);
 int routerset_needs_geoip(const routerset_t *set);
 int routerset_contains_router(const routerset_t *set, const routerinfo_t *ri);
 int routerset_contains_routerstatus(const routerset_t *set,
-                                    routerstatus_t *rs);
+                                    const routerstatus_t *rs);
 int routerset_contains_extendinfo(const routerset_t *set,
                                   const extend_info_t *ei);
 void routerset_get_all_routers(smartlist_t *out, const routerset_t *routerset,
@@ -198,7 +198,7 @@ int hid_serv_responsible_for_desc_id(const char *id);
 void list_pending_microdesc_downloads(digestmap_t *result);
 void launch_descriptor_downloads(int purpose,
                                  smartlist_t *downloadable,
-                                 routerstatus_t *source,
+                                 const routerstatus_t *source,
                                  time_t now);
 
 #endif
-- 
1.7.1




More information about the tor-commits mailing list