[or-cvs] r11812: Change dirvote_get_vote to take named flags rather than 3 bo (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Tue Oct 9 19:14:49 UTC 2007


Author: nickm
Date: 2007-10-09 15:14:48 -0400 (Tue, 09 Oct 2007)
New Revision: 11812

Modified:
   tor/trunk/
   tor/trunk/src/or/directory.c
   tor/trunk/src/or/dirvote.c
   tor/trunk/src/or/or.h
Log:
 r15590 at catbus:  nickm | 2007-10-09 15:14:42 -0400
 Change dirvote_get_vote to take named flags rather than 3 boolean inputs.  Fix a bug that was caused by the order of the boolean inputs in or.h not matching the order of boolean inputs in dirvote.c.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r15590] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c	2007-10-09 19:14:46 UTC (rev 11811)
+++ tor/trunk/src/or/directory.c	2007-10-09 19:14:48 UTC (rev 11812)
@@ -2182,25 +2182,24 @@
         smartlist_add(items, (char*)item);
     } else if (!strcmp(url, "authority")) {
       const cached_dir_t *d;
-      if ((d=dirvote_get_vote(NULL, 1, current, !current)))
+      int flags = DGV_BY_ID |
+        (current ? DGV_INCLUDE_PREVIOUS : DGV_INCLUDE_PENDING);
+      if ((d=dirvote_get_vote(NULL, flags)))
         smartlist_add(dir_items, (cached_dir_t*)d);
     } else {
       const cached_dir_t *d;
       smartlist_t *fps = smartlist_create();
-      int by_id, include_pending, include_previous;
+      int flags;
       if (!strcmpstart(url, "d/")) {
         url += 2;
-        by_id = 0;
-        include_pending = include_previous = 1;
+        flags = DGV_BY_ID | DGV_INCLUDE_PENDING | DGV_INCLUDE_PREVIOUS;
       } else {
-        by_id = 1;
-        include_pending = current;
-        include_previous = !current;
+        flags = DGV_BY_ID |
+          (current ? DGV_INCLUDE_PREVIOUS : DGV_INCLUDE_PENDING);
       }
       dir_split_resource_into_fingerprints(url, fps, NULL, 1, 1);
       SMARTLIST_FOREACH(fps, char *, fp, {
-          if ((d = dirvote_get_vote(fp, by_id,
-                                    include_pending, include_previous)))
+          if ((d = dirvote_get_vote(fp, flags)))
             smartlist_add(dir_items, (cached_dir_t*)d);
           tor_free(fp);
         });

Modified: tor/trunk/src/or/dirvote.c
===================================================================
--- tor/trunk/src/or/dirvote.c	2007-10-09 19:14:46 UTC (rev 11811)
+++ tor/trunk/src/or/dirvote.c	2007-10-09 19:14:48 UTC (rev 11812)
@@ -1235,7 +1235,8 @@
     {
       if (!(ds->type & V3_AUTHORITY))
         continue;
-      if (!dirvote_get_vote(ds->v3_identity_digest, 1, 0, 1)) {
+      if (!dirvote_get_vote(ds->v3_identity_digest,
+                            DGV_BY_ID|DGV_INCLUDE_PENDING)) {
         char *cp = tor_malloc(HEX_DIGEST_LEN+1);
         base16_encode(cp, HEX_DIGEST_LEN+1, ds->v3_identity_digest,
                       DIGEST_LEN);
@@ -1744,9 +1745,12 @@
  * consensus that's in progress.  May return NULL if we have no vote for the
  * authority in question. */
 const cached_dir_t *
-dirvote_get_vote(const char *fp, int by_id, int include_previous,
-                 int include_pending)
+dirvote_get_vote(const char *fp, int flags)
 {
+  int by_id = flags & DGV_BY_ID;
+  const int include_pending = flags & DGV_INCLUDE_PENDING;
+  const int include_previous = flags & DGV_INCLUDE_PREVIOUS;
+
   if (!pending_vote_list && !previous_vote_list)
     return NULL;
   if (fp == NULL) {

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-10-09 19:14:46 UTC (rev 11811)
+++ tor/trunk/src/or/or.h	2007-10-09 19:14:48 UTC (rev 11812)
@@ -2944,9 +2944,10 @@
 /* Item access */
 const char *dirvote_get_pending_consensus(void);
 const char *dirvote_get_pending_detached_signatures(void);
-const cached_dir_t *dirvote_get_vote(const char *fp, int by_id,
-                                     int include_pending,
-                                     int include_previous);
+#define DGV_BY_ID 1
+#define DGV_INCLUDE_PENDING 2
+#define DGV_INCLUDE_PREVIOUS 4
+const cached_dir_t *dirvote_get_vote(const char *fp, int flags);
 
 #ifdef DIRVOTE_PRIVATE
 int networkstatus_check_voter_signature(networkstatus_vote_t *consensus,



More information about the tor-commits mailing list