[or-cvs] only choose routers for the onion that are currently connec...

Roger Dingledine arma at seul.org
Mon Jul 22 04:38:38 UTC 2002


Update of /home/or/cvsroot/src/or
In directory moria.seul.org:/home/arma/work/onion/cvs/src/or

Modified Files:
	onion.c 
Log Message:
only choose routers for the onion that are currently connected to us



Index: onion.c
===================================================================
RCS file: /home/or/cvsroot/src/or/onion.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- onion.c	20 Jul 2002 01:59:28 -0000	1.5
+++ onion.c	22 Jul 2002 04:38:36 -0000	1.6
@@ -100,8 +100,8 @@
   unsigned int *route = NULL;
   unsigned int oldchoice, choice;
   
-  if ( (cw >= 0) && (cw < 1) && (rarray) && (rlen) ) /* valid parameters */
-  {
+  assert((cw >= 0) && (cw < 1) && (rarray) && (rlen) ); /* valid parameters */
+
     routelen = chooselen(cw);
     if (routelen == -1)
     {
@@ -109,6 +109,9 @@
       return NULL;
     }
     log(LOG_DEBUG,"new_route(): Chosen route length %u.",routelen);
+
+    /* FIXME need to figure out how many routers we can actually choose from.
+     * We can get into an infinite loop if there are too few. */
   
     /* allocate memory for the new route */
     route = (unsigned int *)malloc(routelen * sizeof(unsigned int));
@@ -132,8 +135,11 @@
       choice = choice % (rarray_len);
       log(LOG_DEBUG,"new_route() : Chosen router %u.",choice);
       if (choice == oldchoice ||
-        (oldchoice < rarray_len && !pkey_cmp(rarray[choice]->pkey, rarray[oldchoice]->pkey))) {
-        /* same router, or router twin. try again. */
+        (oldchoice < rarray_len && !pkey_cmp(rarray[choice]->pkey, rarray[oldchoice]->pkey)) ||
+        !connection_twin_get_by_addr_port(rarray[choice]->addr, rarray[choice]->or_port)) {
+        /* Same router as last choice, or router twin,
+         *   or no routers with that key are connected to us.
+         * Try again. */
 	i--;
 	continue;
       }
@@ -143,9 +149,6 @@
    
     *rlen = routelen;
     return route;
-  } /* valid parameters */
-  else /* invalid parameters */
-    return NULL;
 }
 
 /* creates a new onion from route, stores it and its length into bufp and lenp respectively */



More information about the tor-commits mailing list