[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r10069: (Needs review.) Allow directory authorities to accept multip (in tor/trunk: . src/or)



Author: nickm
Date: 2007-04-30 15:48:33 -0400 (Mon, 30 Apr 2007)
New Revision: 10069

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/or/directory.c
   tor/trunk/src/or/dirserv.c
   tor/trunk/src/or/or.h
   tor/trunk/src/or/router.c
Log:
 r12585@catbus:  nickm | 2007-04-30 14:38:37 -0400
 (Needs review.) Allow directory authorities to accept multiple router descriptors and extra info documents in a single POST.  This will make implementing the client side of proposal 104 a lot simpler.



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

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-04-30 17:46:19 UTC (rev 10068)
+++ tor/trunk/ChangeLog	2007-04-30 19:48:33 UTC (rev 10069)
@@ -62,6 +62,9 @@
       should be about 60%.  (Limitation: servers do not yet upload extra-info
       documents; authorities do not yet cache them.)  [Partially implements
       proposal 104.]
+    - Directory authorities allow multiple router descriptors and/or extra
+      info documents to be uploaded in a single go.  This will make
+      implementing proposal 104 simpler.
 
   o Minor features (controller):
     - Add a new config option __DisablePredictedCircuits designed for

Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c	2007-04-30 17:46:19 UTC (rev 10068)
+++ tor/trunk/src/or/directory.c	2007-04-30 19:48:33 UTC (rev 10069)
@@ -1875,7 +1875,7 @@
 
   if (!strcmp(url,"/tor/")) { /* server descriptor post */
     const char *msg;
-    int r = dirserv_add_descriptor(body, &msg);
+    int r = dirserv_add_multiple_descriptors(body, &msg);
     tor_assert(msg);
     if (r > 0)
       dirserv_get_directory(); /* rebuild and write to disk */

Modified: tor/trunk/src/or/dirserv.c
===================================================================
--- tor/trunk/src/or/dirserv.c	2007-04-30 17:46:19 UTC (rev 10068)
+++ tor/trunk/src/or/dirserv.c	2007-04-30 19:48:33 UTC (rev 10069)
@@ -522,6 +522,41 @@
   return 0;
 }
 
+/** As for dirserv_add_descriptor, but accepts multiple documents, and
+ * returns the most severe error that occurred for any one of them. */
+int
+dirserv_add_multiple_descriptors(const char *desc, const char **msg)
+{
+  int r=100; /* higher than any actual return value. */
+  int r_tmp;
+  const char *msg_out;
+
+  while (desc && *desc) {
+    const char *eos = strstr(desc, "\nrouter-signature");
+    const char *next = NULL;
+    if (eos) {
+      char *next_extra = strstr(eos, "\nextra-info");
+      char *next_routerinfo = strstr(eos, "\nrouter ");
+      if (next_extra)
+        next = next_extra;
+      if (!next || (next_routerinfo && next_routerinfo < next))
+        next = next_routerinfo;
+    }
+    if (next)
+      ++next;
+
+    r_tmp = dirserv_add_descriptor(desc, next, &msg_out);
+    desc = next;
+
+    if (r_tmp < r) {
+      r = r_tmp;
+      *msg = msg_out;
+    }
+  }
+
+  return r <= 2 ? r : -2;
+}
+
 /** Parse the server descriptor at <b>desc</b> and maybe insert it into
  * the list of server descriptors. Set *<b>msg</b> to a message that
  * should be passed back to the origin of this descriptor.
@@ -533,7 +568,7 @@
  * -2 if we can't find a router descriptor in <b>desc</b>.
  */
 int
-dirserv_add_descriptor(const char *desc, const char **msg)
+dirserv_add_descriptor(const char *desc, const char *end, const char **msg)
 {
   int r;
   routerinfo_t *ri = NULL, *ri_old = NULL;
@@ -545,7 +580,7 @@
   if (!strcmpstart(desc, "extra-info")) {
     /* It's an extra-info thingie. */
     routerlist_t *rl = router_get_routerlist();
-    ei = extrainfo_parse_entry_from_string(desc, NULL, 1, rl->identity_map);
+    ei = extrainfo_parse_entry_from_string(desc, end, 1, rl->identity_map);
     if (!ei) {
       log_warn(LD_DIRSERV, "Couldn't parse uploaded extra-info descriptor");
       *msg = "Rejected: couldn't parse extra-info descriptor";
@@ -567,7 +602,7 @@
   }
 
   /* Check: is the descriptor syntactically valid? */
-  ri = router_parse_entry_from_string(desc, NULL, 1);
+  ri = router_parse_entry_from_string(desc, end, 1);
   if (!ri) {
     log_warn(LD_DIRSERV, "Couldn't parse uploaded server descriptor");
     *msg = "Rejected: Couldn't parse server descriptor.";

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-04-30 17:46:19 UTC (rev 10068)
+++ tor/trunk/src/or/or.h	2007-04-30 19:48:33 UTC (rev 10069)
@@ -2518,7 +2518,9 @@
 int dirserv_load_fingerprint_file(void);
 void dirserv_free_fingerprint_list(void);
 const char *dirserv_get_nickname_by_digest(const char *digest);
-int dirserv_add_descriptor(const char *desc, const char **msg);
+int dirserv_add_multiple_descriptors(const char *desc, const char **msg);
+int dirserv_add_descriptor(const char *desc, const char *end,
+                           const char **msg);
 int getinfo_helper_dirserv_unregistered(control_connection_t *conn,
                                         const char *question, char **answer);
 void dirserv_free_descriptors(void);

Modified: tor/trunk/src/or/router.c
===================================================================
--- tor/trunk/src/or/router.c	2007-04-30 17:46:19 UTC (rev 10068)
+++ tor/trunk/src/or/router.c	2007-04-30 19:48:33 UTC (rev 10069)
@@ -327,7 +327,7 @@
       log_err(LD_GENERAL,"Error initializing descriptor.");
       return -1;
     }
-    if (dirserv_add_descriptor(mydesc, &m) < 0) {
+    if (dirserv_add_descriptor(mydesc, NULL, &m) < 0) {
       log_err(LD_GENERAL,"Unable to add own descriptor to directory: %s",
               m?m:"<unknown error>");
       return -1;