Browse Source

Better fix for last bug: avoids trying to double-mark circuits.

svn:r5511
Nick Mathewson 20 years ago
parent
commit
d2123388ad
3 changed files with 16 additions and 23 deletions
  1. 14 10
      src/or/circuitlist.c
  2. 1 12
      src/or/circuituse.c
  3. 1 1
      src/or/or.h

+ 14 - 10
src/or/circuitlist.c

@@ -458,20 +458,24 @@ circuit_get_by_edge_conn(connection_t *conn)
   return circ;
 }
 
-/** Return a new list of all circuits that have <b>conn</b> as n_conn or
- * p_conn, including those marked for close.
+/** For each circuits that have <b>conn</b> as n_conn or p_conn, unlink the
+ * circuit from the orconn,circid map, and mark it for close if it hasn't
+ * been marked already.
  */
-smartlist_t *
-circuit_get_all_on_orconn(connection_t *conn)
+void
+circuit_unlink_all_from_or_conn(connection_t *conn)
 {
-  smartlist_t *res = smartlist_create();
   circuit_t *circ;
-
-  for (circ=global_circuitlist;circ;circ = circ->next) {
-    if (circ->p_conn == conn || circ->n_conn == conn)
-      smartlist_add(res, circ);
+  for (circ = global_circuitlist; circ; circ = circ->next) {
+    if (circ->n_conn == conn || circ->p_conn == conn) {
+      if (circ->n_conn == conn)
+        circuit_set_circid_orconn(circ, 0, NULL, N_CONN_CHANGED);
+      if (circ->p_conn == conn)
+        circuit_set_circid_orconn(circ, 0, NULL, P_CONN_CHANGED);
+      if (!circ->marked_for_close)
+        circuit_mark_for_close(circ);
+    }
   }
-  return res;
 }
 
 /** Return a circ such that:

+ 1 - 12
src/or/circuituse.c

@@ -515,21 +515,10 @@ circuit_about_to_close_connection(connection_t *conn)
    */
   switch (conn->type) {
     case CONN_TYPE_OR: {
-      smartlist_t *circs;
       /* Inform any pending (not attached) circs that they should give up. */
       circuit_n_conn_done(conn, 0);
-      circs = circuit_get_all_on_orconn(conn);
       /* Now close all the attached circuits on it. */
-      SMARTLIST_FOREACH(circs, circuit_t *, circ, {
-        if (circ->n_conn == conn)
-          /* it's closing in front of us */
-          circuit_set_circid_orconn(circ, 0, NULL, N_CONN_CHANGED);
-        if (circ->p_conn == conn)
-          /* it's closing behind us */
-          circuit_set_circid_orconn(circ, 0, NULL, P_CONN_CHANGED);
-        circuit_mark_for_close(circ);
-      });
-      smartlist_free(circs);
+      circuit_unlink_all_from_or_conn(conn);
       return;
     }
     case CONN_TYPE_AP:

+ 1 - 1
src/or/or.h

@@ -1446,7 +1446,7 @@ circuit_t *circuit_new(uint16_t p_circ_id, connection_t *p_conn);
 circuit_t *circuit_get_by_circid_orconn(uint16_t circ_id, connection_t *conn);
 int circuit_id_used_on_conn(uint16_t circ_id, connection_t *conn);
 circuit_t *circuit_get_by_edge_conn(connection_t *conn);
-smartlist_t *circuit_get_all_on_orconn(connection_t *conn);
+void circuit_unlink_all_from_or_conn(connection_t *conn);
 circuit_t *circuit_get_by_global_id(uint32_t id);
 circuit_t *circuit_get_by_rend_query_and_purpose(const char *rend_query, uint8_t purpose);
 circuit_t *circuit_get_next_by_pk_and_purpose(circuit_t *start,