[or-cvs] r11823: Give better messages and return values from signature upload (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Tue Oct 9 23:02:03 UTC 2007


Author: nickm
Date: 2007-10-09 19:02:02 -0400 (Tue, 09 Oct 2007)
New Revision: 11823

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/or/directory.c
   tor/trunk/src/or/dirvote.c
   tor/trunk/src/or/or.h
Log:
 r15608 at catbus:  nickm | 2007-10-09 19:01:50 -0400
 Give better messages and return values from signature uploads and downlaods; also, log actual errors when we screw up.



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

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-10-09 22:49:30 UTC (rev 11822)
+++ tor/trunk/ChangeLog	2007-10-09 23:02:02 UTC (rev 11823)
@@ -42,6 +42,8 @@
     - When we get a valid consensus, recompute the voting schedule.
     - Base the valid-after time of a vote on the consensus voting schedule,
       not on our preferred schedule.
+    - Make the return values and messages from signature uploads and downloads
+      more sensible.
 
   o Minor bugfixes (performance):
     - Use a slightly simpler string hashing algorithm (copying Python's

Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c	2007-10-09 22:49:30 UTC (rev 11822)
+++ tor/trunk/src/or/directory.c	2007-10-09 23:02:02 UTC (rev 11823)
@@ -1465,6 +1465,7 @@
     }
   }
   if (conn->_base.purpose == DIR_PURPOSE_FETCH_DETACHED_SIGNATURES) {
+    const char *msg = NULL;
     log_info(LD_DIR,"Got detached signatures (size %d) from server %s:%d",
              (int) body_len, conn->_base.address, conn->_base.port);
     if (status_code != 200) {
@@ -1476,7 +1477,10 @@
       tor_free(body); tor_free(headers); tor_free(reason);
       return -1;
     }
-    dirvote_add_signatures(body);
+    if (dirvote_add_signatures(body, &msg)<0) {
+      log_warn(LD_DIR, "Problem adding detached signatures from %s:%d: %s",
+               conn->_base.address, conn->_base.port, msg?msg:"???");
+    }
   }
 
   if (conn->_base.purpose == DIR_PURPOSE_FETCH_SERVERDESC ||
@@ -2561,10 +2565,13 @@
 
   if (authdir_mode_v3(options) &&
       !strcmp(url,"/tor/post/consensus-signature")) { /* sigs on consensus. */
-    if (dirvote_add_signatures(body)>=0) {
-      write_http_status_line(conn, 200, "Signatures stored");
+    const char *msg = NULL;
+    if (dirvote_add_signatures(body, &msg)>=0) {
+      write_http_status_line(conn, 200, msg?msg:"Signatures stored");
     } else {
-      write_http_status_line(conn, 400, "Unable to store signatures");
+      log_warn(LD_DIR, "Unable to store signatures posted by %s: %s",
+               conn->_base.address, msg?msg:"???");
+      write_http_status_line(conn, 400, msg?msg:"Unable to store signatures");
     }
     goto done;
   }

Modified: tor/trunk/src/or/dirvote.c
===================================================================
--- tor/trunk/src/or/dirvote.c	2007-10-09 22:49:30 UTC (rev 11822)
+++ tor/trunk/src/or/dirvote.c	2007-10-09 23:02:02 UTC (rev 11823)
@@ -812,11 +812,13 @@
  * <b>src_voter_list</b> that should be added to <b>target.  (A signature
  * should be added if we have no signature for that voter in <b>target</b>
  * yet, or if we have no verifiable signature and the new signature is
- * verifiable.)   Return the number of signatures added or changed. */
+ * verifiable.)   Return the number of signatures added or changed, or
+ * -1 on error. */
 static int
 networkstatus_add_signatures_impl(networkstatus_vote_t *target,
                                   smartlist_t *src_voter_list)
 {
+  /*XXXX020 merge with the only function that calls it. */
   int r = 0;
   tor_assert(target);
   tor_assert(!target->is_vote);
@@ -862,7 +864,7 @@
   return r;
 }
 
-/** As networkstatus_add_consensus_signature_impl, but takes new signatures
+/** As networkstatus_add_signature_impl, but takes new signatures
  * from the detached signatures document <b>sigs</b>. */
 int
 networkstatus_add_detached_signatures(networkstatus_vote_t *target,
@@ -1645,9 +1647,11 @@
     }
     tor_free(pending_consensus_signatures);
     pending_consensus_signatures = new_detached;
+    *msg_out = "Signatures added";
+  } else {
+    *msg_out = "Digest mismatch when adding detached signatures";
   }
 
-  *msg_out = "ok";
   goto done;
  err:
   if (!msg_out)
@@ -1661,22 +1665,22 @@
 /** Helper: we just got the <b>deteached_signatures_body</b> sent to us as
  * signatures on the currently pending consensus.  Add them to the pending
  * consensus (if we have one); otherwise queue them until we have a
- * consensus. */
+ * consensus.  Return negative on failure, nonnegative on success. */
 int
-dirvote_add_signatures(const char *detached_signatures_body)
+dirvote_add_signatures(const char *detached_signatures_body,
+                       const char **msg)
 {
-  /*XXXX020 return value is senseless. */
   if (pending_consensus) {
-    const char *msg=NULL;
     log_notice(LD_DIR, "Got a signature. Adding it to the pending consensus.");
     return dirvote_add_signatures_to_pending_consensus(
-                                         detached_signatures_body, &msg);
+                                     detached_signatures_body, msg);
   } else {
     log_notice(LD_DIR, "Got a signature. Queueing it for the next consensus.");
     if (!pending_consensus_signature_list)
       pending_consensus_signature_list = smartlist_create();
     smartlist_add(pending_consensus_signature_list,
                   tor_strdup(detached_signatures_body));
+    *msg = "Signature queued";
     return 0;
   }
 }

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-10-09 22:49:30 UTC (rev 11822)
+++ tor/trunk/src/or/or.h	2007-10-09 23:02:02 UTC (rev 11823)
@@ -2939,7 +2939,8 @@
 struct pending_vote_t * dirvote_add_vote(const char *vote_body,
                                          const char **msg_out,
                                          int *status_out);
-int dirvote_add_signatures(const char *detached_signatures_body);
+int dirvote_add_signatures(const char *detached_signatures_body,
+                           const char **msg_out);
 
 /* Item access */
 const char *dirvote_get_pending_consensus(void);



More information about the tor-commits mailing list