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

[or-cvs] r9929: Fix the first half of bug 411: when we make a circuit active (in tor/trunk: . src/or)



Author: nickm
Date: 2007-04-09 16:09:28 -0400 (Mon, 09 Apr 2007)
New Revision: 9929

Modified:
   tor/trunk/
   tor/trunk/src/or/circuitlist.c
Log:
 r12318@catbus:  nickm | 2007-04-09 16:08:20 -0400
 Fix the first half of bug 411: when we make a circuit active inactive on a connection, it _must_ actually be on that connection.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r12318] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/src/or/circuitlist.c
===================================================================
--- tor/trunk/src/or/circuitlist.c	2007-04-09 20:09:26 UTC (rev 9928)
+++ tor/trunk/src/or/circuitlist.c	2007-04-09 20:09:28 UTC (rev 9929)
@@ -78,14 +78,30 @@
  * remove the circuit from the list of active circuits on old_conn and add it
  * to the list of active circuits on conn. */
 static void
-circuit_set_circid_orconn_helper(circuit_t *circ, uint16_t id,
+circuit_set_circid_orconn_helper(circuit_t *circ, int direction,
+                                 uint16_t id,
                                  or_connection_t *conn,
-                                 uint16_t old_id, or_connection_t *old_conn,
                                  int active)
 {
   orconn_circid_circuit_map_t search;
   orconn_circid_circuit_map_t *found;
+  or_connection_t *old_conn, **conn_ptr;
+  uint16_t old_id, *circid_ptr;
 
+  if (direction == CELL_DIRECTION_OUT) {
+    conn_ptr = &circ->n_conn;
+    circid_ptr = &circ->n_circ_id;
+  } else {
+    or_circuit_t *c = TO_OR_CIRCUIT(circ);
+    conn_ptr = &c->p_conn;
+    circid_ptr = &c->p_circ_id;
+  }
+  old_conn = *conn_ptr;
+  old_id = *circid_ptr;
+
+  if (id == old_id && conn == old_conn)
+    return;
+
   if (_last_circid_orconn_ent &&
       ((old_id == _last_circid_orconn_ent->circ_id &&
         old_conn == _last_circid_orconn_ent->or_conn) ||
@@ -107,6 +123,11 @@
       make_circuit_inactive_on_conn(circ,old_conn);
   }
 
+  /* Change the values only after we have possibly made the circuit inactive
+   * on the previous conn. */
+  *conn_ptr = conn;
+  *circid_ptr = id;
+
   if (conn == NULL)
     return;
 
@@ -136,21 +157,16 @@
 circuit_set_p_circid_orconn(or_circuit_t *circ, uint16_t id,
                             or_connection_t *conn)
 {
-  uint16_t old_id;
-  or_connection_t *old_conn;
   int active;
 
-  old_id = circ->p_circ_id;
-  old_conn = circ->p_conn;
-  circ->p_circ_id = id;
-  circ->p_conn = conn;
   active = circ->p_conn_cells.n > 0;
   tor_assert(bool_eq(active, circ->next_active_on_p_conn));
 
-  if (id == old_id && conn == old_conn)
-    return;
-  circuit_set_circid_orconn_helper(TO_CIRCUIT(circ), id, conn,
-                                   old_id, old_conn, active);
+  circuit_set_circid_orconn_helper(TO_CIRCUIT(circ), CELL_DIRECTION_IN,
+                                   id, conn, active);
+
+  if (conn)
+    tor_assert(bool_eq(active, circ->next_active_on_p_conn));
 }
 
 /** Set the n_conn field of a circuit <b>circ</b>, along
@@ -160,20 +176,16 @@
 circuit_set_n_circid_orconn(circuit_t *circ, uint16_t id,
                             or_connection_t *conn)
 {
-  uint16_t old_id;
-  or_connection_t *old_conn;
   int active;
 
-  old_id = circ->n_circ_id;
-  old_conn = circ->n_conn;
-  circ->n_circ_id = id;
-  circ->n_conn = conn;
   active = circ->n_conn_cells.n > 0;
   tor_assert(bool_eq(active, circ->next_active_on_n_conn));
 
-  if (id == old_id && conn == old_conn)
-    return;
-  circuit_set_circid_orconn_helper(circ, id, conn, old_id, old_conn, active);
+  circuit_set_circid_orconn_helper(circ, CELL_DIRECTION_OUT,
+                                   id, conn, active);
+
+  if (conn)
+    tor_assert(bool_eq(active, circ->next_active_on_n_conn));
 }
 
 /** Change the state of <b>circ</b> to <b>state</b>, adding it to or removing