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

[or-cvs] fix the bug where we sometimes would fail to send some crea...



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

Modified Files:
	circuitbuild.c 
Log Message:
fix the bug where we sometimes would fail to send some create cells
once we'd connected to a(nother) tor server.


Index: circuitbuild.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/circuitbuild.c,v
retrieving revision 1.238
retrieving revision 1.239
diff -u -p -d -r1.238 -r1.239
--- circuitbuild.c	5 Jun 2006 09:47:19 -0000	1.238
+++ circuitbuild.c	6 Jun 2006 03:33:24 -0000	1.239
@@ -404,6 +404,7 @@ void
 circuit_n_conn_done(connection_t *or_conn, int status)
 {
   extern smartlist_t *circuits_pending_or_conns;
+  smartlist_t *changed_circs;
 
   log_debug(LD_CIRC,"or_conn to %s, status=%d",
             or_conn->nickname ? or_conn->nickname : "NULL", status);
@@ -411,6 +412,8 @@ circuit_n_conn_done(connection_t *or_con
   if (!circuits_pending_or_conns)
     return;
 
+  changed_circs = smartlist_create();
+
   SMARTLIST_FOREACH(circuits_pending_or_conns, circuit_t *, circ,
   {
     if (circ->marked_for_close)
@@ -454,18 +457,18 @@ circuit_n_conn_done(connection_t *or_con
           continue;
         }
         tor_free(circ->onionskin);
-        circuit_set_state(circ, CIRCUIT_STATE_OPEN);
-        /* XXX: Since circuit_set_state removes circ from the
-         * circuits_pending_or_conns, we will skip over whatever
-         * the next entry is when we proceed with the SMARTLIST_FOREACH.
-         * Thus if there's ever more than one entry, we will miss some.
-         *
-         * Is this true? If so, is the fix to decrement circ_sl_idx
-         * here too? -RD
-         */
+        /* We don't want to change circ's state here, since the act
+         * of doing that modifies the circuits_pending_or_conns list
+         * that we're looping through right now. So collect a list of
+         * circs to change their state when we're done. */
+        smartlist_add(changed_circs, circ);
       }
     }
   });
+
+  SMARTLIST_FOREACH(changed_circs, circuit_t *, circ,
+    circuit_set_state(circ, CIRCUIT_STATE_OPEN));
+  smartlist_free(changed_circs);
 }
 
 /** Find a new circid that isn't currently in use on the circ->n_conn