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

[or-cvs] r9021: Merge circuit_about_to_close_connection and connection_about (in tor/trunk: . src/or)



Author: nickm
Date: 2006-12-04 00:55:40 -0500 (Mon, 04 Dec 2006)
New Revision: 9021

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/or/circuituse.c
   tor/trunk/src/or/connection.c
   tor/trunk/src/or/main.c
   tor/trunk/src/or/or.h
Log:
 r9855@Kushana:  nickm | 2006-12-04 00:55:09 -0500
 Merge circuit_about_to_close_connection and connection_about_to_close_connection.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r9855] on c95137ef-5f19-0410-b913-86e773d04f59

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2006-12-04 05:09:09 UTC (rev 9020)
+++ tor/trunk/ChangeLog	2006-12-04 05:55:40 UTC (rev 9021)
@@ -3,6 +3,11 @@
     - Fix a bug when a PF socket is first used.  (Patch from Fabian
       Keil)
 
+  o Controller bugfixes:
+    - Report the circuit number correctly in STREAM CLOSED events. (Bug
+      reported by Mike Perry)
+
+
 Changes in version 0.1.2.4-alpha - 2006-12-03
   o Major features:
     - Add support for using natd; this allows FreeBSDs earlier than

Modified: tor/trunk/src/or/circuituse.c
===================================================================
--- tor/trunk/src/or/circuituse.c	2006-12-04 05:09:09 UTC (rev 9020)
+++ tor/trunk/src/or/circuituse.c	2006-12-04 05:55:40 UTC (rev 9021)
@@ -518,50 +518,6 @@
   tor_assert(0); /* should never get here */
 }
 
-/** Notify the global circuit list that <b>conn</b> is about to be
- * removed and then freed.
- *
- * If it's an OR conn, then mark-for-close all the circuits that use
- * that conn.
- *
- * If it's an edge conn, then detach it from its circ, so we don't
- * try to reference it later.
- */
-void
-circuit_about_to_close_connection(connection_t *conn)
-{
-  /* currently, we assume it's too late to flush conn's buf here.
-   * down the road, maybe we'll consider that eof doesn't mean can't-write
-   */
-  switch (conn->type) {
-    case CONN_TYPE_OR: {
-      if (!connection_state_is_open(conn)) {
-        /* Inform any pending (not attached) circs that they should
-         * give up. */
-        circuit_n_conn_done(TO_OR_CONN(conn), 0);
-      }
-      /* Now close all the attached circuits on it. */
-      circuit_unlink_all_from_or_conn(TO_OR_CONN(conn),
-                                      END_CIRC_REASON_OR_CONN_CLOSED);
-      return;
-    }
-    case CONN_TYPE_AP:
-    case CONN_TYPE_EXIT: {
-      circuit_t *circ;
-      /* It's an edge conn. Need to remove it from the linked list of
-       * conn's for this circuit. Confirm that 'end' relay command has
-       * been sent. But don't kill the circuit.
-       */
-
-      circ = circuit_get_by_edge_conn(TO_EDGE_CONN(conn));
-      if (!circ)
-        return;
-
-      circuit_detach_stream(circ, TO_EDGE_CONN(conn));
-    }
-  } /* end switch */
-}
-
 /** Find each circuit that has been unused for too long, or dirty
  * for too long and has no streax=ms on it: mark it for close.
  */

Modified: tor/trunk/src/or/connection.c
===================================================================
--- tor/trunk/src/or/connection.c	2006-12-04 05:09:09 UTC (rev 9020)
+++ tor/trunk/src/or/connection.c	2006-12-04 05:55:40 UTC (rev 9021)
@@ -393,6 +393,7 @@
  *   - Exit conns need to call connection_dns_remove() if necessary.
  *   - AP and Exit conns need to send an end cell if they can.
  *   - DNS conns need to fail any resolves that are pending on them.
+ *   - OR and edge connections need to be unlinked from circuits.
  */
 void
 connection_about_to_close_connection(connection_t *conn)
@@ -436,6 +437,9 @@
           router_set_status(or_conn->identity_digest, 0);
           control_event_or_conn_status(or_conn, OR_CONN_EVENT_FAILED);
         }
+        /* Inform any pending (not attached) circs that they should
+         * give up. */
+        circuit_n_conn_done(TO_OR_CONN(conn), 0);
       } else if (conn->hold_open_until_flushed) {
         /* XXXX009 We used to have an arg that told us whether we closed the
          * connection on purpose or not.  Can we use hold_open_until_flushed
@@ -452,6 +456,9 @@
         rep_hist_note_connection_died(or_conn->identity_digest, now);
         control_event_or_conn_status(or_conn, OR_CONN_EVENT_CLOSED);
       }
+      /* Now close all the attached circuits on it. */
+      circuit_unlink_all_from_or_conn(TO_OR_CONN(conn),
+                                      END_CIRC_REASON_OR_CONN_CLOSED);
       break;
     case CONN_TYPE_AP:
       edge_conn = TO_EDGE_CONN(conn);
@@ -463,20 +470,23 @@
                  conn->marked_for_close_file, conn->marked_for_close);
       }
       if (!edge_conn->end_reason) {
-        // XXXX Disable this before 0.1.2.x-final ships.
+        // XXXX012 Disable this before 0.1.2.x-final ships.
         log_warn(LD_BUG,"Bug: Closing stream (marked at %s:%d) without having"
                  " set end_reason. Please tell Nick.",
                  conn->marked_for_close_file, conn->marked_for_close);
       }
       control_event_stream_status(edge_conn, STREAM_EVENT_CLOSED,
                                   edge_conn->end_reason);
+      circ = circuit_get_by_edge_conn(edge_conn);
+      if (circ)
+        circuit_detach_stream(circ, edge_conn);
       break;
     case CONN_TYPE_EXIT:
       edge_conn = TO_EDGE_CONN(conn);
+      circ = circuit_get_by_edge_conn(edge_conn);
+      if (circ)
+        circuit_detach_stream(circ, edge_conn);
       if (conn->state == EXIT_CONN_STATE_RESOLVING) {
-        circ = circuit_get_by_edge_conn(edge_conn);
-        if (circ)
-          circuit_detach_stream(circ, edge_conn);
         connection_dns_remove(edge_conn);
       }
       break;

Modified: tor/trunk/src/or/main.c
===================================================================
--- tor/trunk/src/or/main.c	2006-12-04 05:09:09 UTC (rev 9020)
+++ tor/trunk/src/or/main.c	2006-12-04 05:55:40 UTC (rev 9021)
@@ -208,7 +208,6 @@
 static void
 connection_unlink(connection_t *conn, int remove)
 {
-  circuit_about_to_close_connection(conn);
   connection_about_to_close_connection(conn);
   if (remove) {
     connection_remove(conn);

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2006-12-04 05:09:09 UTC (rev 9020)
+++ tor/trunk/src/or/or.h	2006-12-04 05:55:40 UTC (rev 9021)
@@ -673,7 +673,8 @@
                                      * conn? */
   unsigned edge_has_sent_end:1; /**< For debugging; only used on edge
                          * connections.  Set once we've set the stream end,
-                         * and check in circuit_about_to_close_connection(). */
+                         * and check in connection_about_to_close_connection().
+                         */
   /** Used for OR conns that shouldn't get any new circs attached to them. */
   unsigned int or_is_obsolete:1;
   /** For AP connections only. If 1, and we fail to reach the chosen exit,
@@ -1835,7 +1836,6 @@
                                     int min);
 void circuit_build_needed_circs(time_t now);
 void circuit_detach_stream(circuit_t *circ, edge_connection_t *conn);
-void circuit_about_to_close_connection(connection_t *conn);
 
 void reset_bandwidth_test(void);
 int circuit_enough_testing_circs(void);