[or-cvs] Better messages when POSTDESCRIPTOR fails

Nick Mathewson nickm at seul.org
Sat Apr 2 22:02:16 UTC 2005


Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv12319/src/or

Modified Files:
	control.c or.h routerlist.c 
Log Message:
Better messages when POSTDESCRIPTOR fails

Index: control.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -d -r1.72 -r1.73
--- control.c	1 Apr 2005 20:15:55 -0000	1.72
+++ control.c	2 Apr 2005 22:02:13 -0000	1.73
@@ -230,6 +230,8 @@
 
 static void send_control_done2(connection_t *conn, const char *msg, size_t len)
 {
+  if (len==0)
+    len = strlen(msg);
   send_control_message(conn, CONTROL_CMD_DONE, len, msg);
 }
 
@@ -760,10 +762,16 @@
 handle_control_postdescriptor(connection_t *conn, uint32_t len,
                               const char *body)
 {
-  if (router_load_single_router(body)<0) {
-    /* XXXX a more specific error would be nice. */
-    send_control_error(conn,ERR_UNSPECIFIED,
-                       "Could not parse descriptor or add it");
+  const char *msg;
+  switch (router_load_single_router(body, &msg)) {
+  case -1:
+    send_control_error(conn,ERR_SYNTAX,msg?msg: "Could not parse descriptor");
+    break;
+  case 0:
+    send_control_done2(conn,msg?msg: "Descriptor not added",0);
+    break;
+  case 1:
+    send_control_done(conn);
     return 0;
   }
 

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.580
retrieving revision 1.581
diff -u -d -r1.580 -r1.581
--- or.h	1 Apr 2005 20:15:55 -0000	1.580
+++ or.h	2 Apr 2005 22:02:13 -0000	1.581
@@ -1796,7 +1796,7 @@
 routerinfo_t *routerinfo_copy(const routerinfo_t *router);
 void router_mark_as_down(const char *digest);
 void routerlist_remove_old_routers(int age);
-int router_load_single_router(const char *s);
+int router_load_single_router(const char *s, const char **msg);
 int router_load_routerlist_from_directory(const char *s,crypto_pk_env_t *pkey,
                                         int dir_is_recent, int dir_is_cached);
 addr_policy_result_t router_compare_addr_to_addr_policy(uint32_t addr,

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.223
retrieving revision 1.224
diff -u -d -r1.223 -r1.224
--- routerlist.c	1 Apr 2005 20:15:55 -0000	1.223
+++ routerlist.c	2 Apr 2005 22:02:13 -0000	1.224
@@ -769,9 +769,11 @@
  * their pointers to <b>router</b> after invoking this function; <b>router</b>
  * will either be inserted into the routerlist or freed.  Returns 0 if the
  * router was added; -1 if it was not.
+ *
+ * DOCDOC msg
  */
 static int
-router_add_to_routerlist(routerinfo_t *router) {
+router_add_to_routerlist(routerinfo_t *router, const char **msg) {
   int i;
   routerinfo_t *r;
   char id_digest[DIGEST_LEN];
@@ -797,11 +799,12 @@
         smartlist_set(routerlist->routers, i, router);
         return 0;
       } else {
-        log_fn(LOG_DEBUG, "Skipping old entry for router '%s'",
+        log_fn(LOG_DEBUG, "Skipping not-new descriptor for router '%s'",
                router->nickname);
         /* Update the is_running status to whatever we were told. */
         r->is_running = router->is_running;
         routerinfo_free(router);
+        if (msg) *msg = "Router descriptor was not new.";
         return -1;
       }
     } else if (!strcasecmp(router->nickname, r->nickname)) {
@@ -827,6 +830,7 @@
         log_fn(LOG_DEBUG, "Skipping unverified entry for verified router '%s'",
                router->nickname);
         routerinfo_free(router);
+        if (msg) *msg = "Already have verified router with different key and same nickname";
         return -1;
       }
     }
@@ -865,15 +869,19 @@
 }
 
 /*
- * Code to parse router descriptors and directories.
+ * Code to parse a single router descriptors and insert it into the
+ * directory.  Return -1 if the descriptor was ill-formed; 0 if the
+ * descriptor was well-formed but could not be added; and 1 if the
+ * descriptor was added.
  */
 int
-router_load_single_router(const char *s)
+router_load_single_router(const char *s, const char **msg)
 {
   routerinfo_t *ri;
 
   if (!(ri = router_parse_entry_from_string(s, NULL))) {
     log_fn(LOG_WARN, "Error parsing router descriptor; dropping.");
+    if (msg) *msg = "Couldn't parse router descriptor";
     return -1;
   }
   if (routerlist && routerlist->running_routers) {
@@ -883,9 +891,10 @@
                                         rr->running_routers,
                                         rr->is_running_routers_format);
   }
-  if (router_add_to_routerlist(ri)<0) {
+  if (router_add_to_routerlist(ri, msg)<0) {
     log_fn(LOG_WARN, "Couldn't add router to list; dropping.");
-    return -1;
+    if (msg && !*msg) *msg = "Couldn't add router to list.";
+    return 0;
   } else {
     smartlist_t *changed = smartlist_create();
     smartlist_add(changed, ri);
@@ -893,7 +902,7 @@
     smartlist_free(changed);
   }
   log_fn(LOG_DEBUG, "Added router to list");
-  return 0;
+  return 1;
 }
 
 /** Add to the current routerlist each router stored in the
@@ -922,7 +931,7 @@
     smartlist_t *changed = smartlist_create();
     SMARTLIST_FOREACH(new_list->routers, routerinfo_t *, r,
     {
-      if (router_add_to_routerlist(r)==0)
+      if (router_add_to_routerlist(r,NULL)==0)
         smartlist_add(changed, r);
     });
     smartlist_clear(new_list->routers);



More information about the tor-commits mailing list