[tor-commits] [tor/master] Use symbolic constants for statuses in microdescs_add_to_cache.

nickm at torproject.org nickm at torproject.org
Mon Oct 13 18:33:50 UTC 2014


commit 39795e117f55fc951ea9ba0802ce5ce91e65ae33
Author: Nick Mathewson <nickm at torproject.org>
Date:   Mon Oct 13 13:43:07 2014 -0400

    Use symbolic constants for statuses in microdescs_add_to_cache.
    
    Suggested by Andrea in her review of 11243.
---
 src/or/microdesc.c |   19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/or/microdesc.c b/src/or/microdesc.c
index 8a2ece2..14faa2e 100644
--- a/src/or/microdesc.c
+++ b/src/or/microdesc.c
@@ -147,6 +147,10 @@ microdescs_add_to_cache(microdesc_cache_t *cache,
                         int no_save, time_t listed_at,
                         smartlist_t *requested_digests256)
 {
+  void * const DIGEST_REQUESTED = (void*)1;
+  void * const DIGEST_RECEIVED = (void*)2;
+  void * const DIGEST_INVALID = (void*)3;
+
   smartlist_t *descriptors, *added;
   const int allow_annotations = (where != SAVED_NOWHERE);
   smartlist_t *invalid_digests = smartlist_new();
@@ -162,15 +166,16 @@ microdescs_add_to_cache(microdesc_cache_t *cache,
     digestmap_t *requested; /* XXXX actually we should just use a
                                digest256map */
     requested = digestmap_new();
-    /* Set requested[d] to 1 for every md we requested. */
+    /* Set requested[d] to DIGEST_REQUESTED for every md we requested. */
     SMARTLIST_FOREACH(requested_digests256, const char *, cp,
-      digestmap_set(requested, cp, (void*)1));
-    /* Set requested[d] to 3 for every md we requested which we will never be
-     * able to parse.  Remove the ones we didn't request from invalid_digests.
+      digestmap_set(requested, cp, DIGEST_REQUESTED));
+    /* Set requested[d] to DIGEST_INVALID for every md we requested which we
+     * will never be able to parse.  Remove the ones we didn't request from
+     * invalid_digests.
      */
     SMARTLIST_FOREACH_BEGIN(invalid_digests, char *, cp) {
       if (digestmap_get(requested, cp)) {
-        digestmap_set(requested, cp, (void*)3);
+        digestmap_set(requested, cp, DIGEST_INVALID);
       } else {
         tor_free(cp);
         SMARTLIST_DEL_CURRENT(invalid_digests, cp);
@@ -181,7 +186,7 @@ microdescs_add_to_cache(microdesc_cache_t *cache,
      */
     SMARTLIST_FOREACH_BEGIN(descriptors, microdesc_t *, md) {
       if (digestmap_get(requested, md->digest)) {
-        digestmap_set(requested, md->digest, (void*)2);
+        digestmap_set(requested, md->digest, DIGEST_RECEIVED);
       } else {
         log_fn(LOG_PROTOCOL_WARN, LD_DIR, "Received non-requested microdesc");
         microdesc_free(md);
@@ -192,7 +197,7 @@ microdescs_add_to_cache(microdesc_cache_t *cache,
      */
     SMARTLIST_FOREACH_BEGIN(requested_digests256, char *, cp) {
       void *status = digestmap_get(requested, cp);
-      if (status == (void*)2 || status == (void*)3) {
+      if (status == DIGEST_RECEIVED || status == DIGEST_INVALID) {
         tor_free(cp);
         SMARTLIST_DEL_CURRENT(requested_digests256, cp);
       }





More information about the tor-commits mailing list