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

[or-cvs] if router_resolve fails on the descriptor the controller



Update of /home2/or/cvsroot/tor/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/tor/src/or

Modified Files:
	routerlist.c 
Log Message:
if router_resolve fails on the descriptor the controller
gives us, we shouldn't leave the routerinfo in the list.


Index: routerlist.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.231
retrieving revision 1.232
diff -u -d -r1.231 -r1.232
--- routerlist.c	14 May 2005 00:13:17 -0000	1.231
+++ routerlist.c	14 May 2005 05:01:41 -0000	1.232
@@ -796,7 +796,7 @@
 
 /** Add <b>router</b> to the routerlist, if we don't already have it.  Replace
  * older entries (if any) with the same name.  Note: Callers should not hold
- * their pointers to <b>router</b> after invoking this function; <b>router</b>
+ * 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.
  *
@@ -914,6 +914,18 @@
     if (msg) *msg = "Couldn't parse router descriptor";
     return -1;
   }
+  if (router_is_me(ri)) {
+    log_fn(LOG_WARN, "Router's identity key matches mine; dropping.");
+    if (msg && !*msg) *msg = "Router's identity key matches mine.";
+    routerinfo_free(ri);
+    return 0;
+  }
+  if (router_resolve(ri)<0) {
+    log_fn(LOG_WARN, "Couldn't resolve router address; dropping.");
+    if (msg && !*msg) *msg = "Couldn't resolve router address.";
+    routerinfo_free(ri);
+    return 0;
+  }
   if (routerlist && routerlist->running_routers) {
     running_routers_t *rr = routerlist->running_routers;
     router_update_status_from_smartlist(ri,
@@ -923,6 +935,7 @@
   if (router_add_to_routerlist(ri, msg)<0) {
     log_fn(LOG_WARN, "Couldn't add router to list; dropping.");
     if (msg && !*msg) *msg = "Couldn't add router to list.";
+    /* ri is already freed */
     return 0;
   } else {
     smartlist_t *changed = smartlist_create();
@@ -931,11 +944,6 @@
     smartlist_free(changed);
   }
 
-  if (router_resolve(ri)<0) {
-    if (msg && !*msg) *msg = "Couldn't resolve router address.";
-    return 0;
-  }
-
   log_fn(LOG_DEBUG, "Added router to list");
   return 1;
 }