[or-cvs] Change the return values on dirserv_add_descriptor

Nick Mathewson nickm at seul.org
Fri Aug 26 21:46:26 UTC 2005


Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv3664/src/or

Modified Files:
	directory.c dirserv.c routerlist.c 
Log Message:
Change the return values on dirserv_add_descriptor

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/directory.c,v
retrieving revision 1.248
retrieving revision 1.249
diff -u -d -r1.248 -r1.249
--- directory.c	26 Aug 2005 21:28:15 -0000	1.248
+++ directory.c	26 Aug 2005 21:46:24 -0000	1.249
@@ -1196,12 +1196,11 @@
         log_fn(LOG_NOTICE,"Rejected descriptor published by %s.", origin);
         break;
       case 0:
-        /* descriptor was well-formed but server has not been approved */
-        write_http_status_line(conn, 200, msg?msg:"Unverified server descriptor accepted");
+        write_http_status_line(conn, 200, msg?msg:"Server okay, but not accepted.");
         break;
       case 1:
         dirserv_get_directory(&cp, 0); /* rebuild and write to disk */
-        write_http_status_line(conn, 200, msg?msg:"Verified server descriptor accepted");
+        write_http_status_line(conn, 200, msg?msg:"Server descriptor accepted");
         break;
     }
     goto done;

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.192
retrieving revision 1.193
diff -u -d -r1.192 -r1.193
--- dirserv.c	26 Aug 2005 21:30:52 -0000	1.192
+++ dirserv.c	26 Aug 2005 21:46:24 -0000	1.193
@@ -266,6 +266,7 @@
   return 0;
 }
 
+/** DOCDOC */
 int
 dirserv_wants_to_reject_router(routerinfo_t *ri, int *verified,
                                const char **msg)
@@ -329,13 +330,14 @@
  * origin of this descriptor, or to NULL.
  *
  * Return 1 if descriptor is well-formed and accepted;
- *  0 if well-formed and server is unapproved but accepted;
+ *  0 if well-formed and server is well-formed but rejected for timeliness.
  * -1 if it looks vaguely like a router descriptor but rejected;
  * -2 if we can't find a router descriptor in *desc.
  */
 int
 dirserv_add_descriptor(const char *desc, const char **msg)
 {
+  int r;
   routerinfo_t *ri = NULL;
   tor_assert(msg);
   *msg = NULL;
@@ -347,14 +349,18 @@
     *msg = "Rejected: Couldn't parse server descriptor.";
     return -1;
   }
-  if (router_add_to_routerlist(ri, msg)) {
-    return -1;
+  if ((r = router_add_to_routerlist(ri, msg))<0) {
+    return r == -1 ? 0 : -1;
   } else {
     smartlist_t *changed = smartlist_create();
     smartlist_add(changed, ri);
     control_event_descriptors_changed(changed);
     smartlist_free(changed);
-    return ri->is_verified ? 1 : 0;
+    if (!*msg) {
+      *msg =  ri->is_verified ? "Verified server descriptor accepted" :
+        "Unverified server descriptor accepted";
+    }
+    return 1;
   }
 }
 

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.258
retrieving revision 1.259
diff -u -d -r1.258 -r1.259
--- routerlist.c	26 Aug 2005 21:28:16 -0000	1.258
+++ routerlist.c	26 Aug 2005 21:46:24 -0000	1.259
@@ -855,11 +855,15 @@
  * older entries (if any) with the same name.  Note: Callers should not hold
  * their pointers to <b>router</b> if this function fails; <b>router</b>
  * will either be inserted into the routerlist or freed.  Returns 0 if the
- * router was added; -1 if it was not.
+ * router was added; less than 0 if it was not.
  *
- * If we're returning -1 and <b>msg</b> is not NULL, then assign to
+ * If we're returning an error and <b>msg</b> is not NULL, then assign to
  * *<b>msg</b> a static string describing the reason for refusing the
  * routerinfo.
+ *
+ * If the return value is less than -1, there was a problem with the
+ * routerinfo.  If the return value is equal to -1, then the routerinfo was
+ * fine, but out-of-date.
  */
 int
 router_add_to_routerlist(routerinfo_t *router, const char **msg)
@@ -878,7 +882,7 @@
 
   if (authdir) {
     if (dirserv_wants_to_reject_router(router, &authdir_verified, msg))
-      return -1;
+      return -2;
     router->is_verified = authdir_verified;
     if (tor_version_as_new_as(router->platform,"0.1.0.2-rc"))
       router->is_verified = 1;
@@ -943,7 +947,7 @@
                router->nickname);
         routerinfo_free(router);
         if (msg) *msg = "Already have verified router with same nickname and different key.";
-        return -1;
+        return -2;
       }
     }
   }



More information about the tor-commits mailing list