[or-cvs] Raise common code for "detach this stream and try it with a...

Nick Mathewson nickm at seul.org
Mon Mar 14 03:13:02 UTC 2005


Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv7794/src/or

Modified Files:
	connection_edge.c or.h relay.c 
Log Message:
Raise common code for "detach this stream and try it with a different circuit" into a separate function; make that function handle controller-managed streams right.

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection_edge.c,v
retrieving revision 1.296
retrieving revision 1.297
diff -u -d -r1.296 -r1.297
--- connection_edge.c	12 Mar 2005 04:22:01 -0000	1.296
+++ connection_edge.c	14 Mar 2005 03:12:59 -0000	1.297
@@ -296,9 +296,6 @@
     connection_edge_end(conn, END_STREAM_REASON_TIMEOUT, conn->cpath_layer);
     /* un-mark it as ending, since we're going to reuse it */
     conn->has_sent_end = 0;
-    /* move it back into 'pending' state. */
-    conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
-    circuit_detach_stream(circ, conn);
     /* kludge to make us not try this circuit again, yet to allow
      * current streams on it to survive if they can: make it
      * unattractive to use for new streams */
@@ -306,8 +303,8 @@
     circ->timestamp_dirty -= options->MaxCircuitDirtiness;
     /* give our stream another 15 seconds to try */
     conn->timestamp_lastread += 15;
-    /* attaching to a dirty circuit is fine */
-    if (connection_ap_handshake_attach_circuit(conn)<0) {
+    /* move it back into 'pending' state, and try to attach. */
+    if (connection_ap_detach_retriable(conn, circ)<0) {
       /* it will never work */
       /* Don't need to send end -- we're not connected */
       conn->has_sent_end = 1;
@@ -342,6 +339,26 @@
   }
 }
 
+/** DOCDOC
+ * -1 on err, 1 on success, 0 on not-yet-sure.
+ */
+int
+connection_ap_detach_retriable(connection_t *conn, circuit_t *circ)
+{
+  control_event_stream_status(conn, STREAM_EVENT_FAILED_RETRIABLE);
+  if (get_options()->ManageConnections) {
+    conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
+    circuit_detach_stream(circ,conn);
+    /* Muck with timestamps? */
+    return connection_ap_handshake_attach_circuit(conn);
+  } else {
+    conn->state = AP_CONN_STATE_CONTROLLER_WAIT;
+    circuit_detach_stream(circ,conn);
+    return 0;
+  }
+}
+
+
 /** A client-side struct to remember requests to rewrite addresses
  * to new addresses. These structs make up a tree, with addressmap
  * below as its root.
@@ -839,7 +856,7 @@
         return 0;
       }
       rep_hist_note_used_resolve(time(NULL)); /* help predict this next time */
-            control_event_stream_status(conn, STREAM_EVENT_NEW_RESOLVE);
+      control_event_stream_status(conn, STREAM_EVENT_NEW_RESOLVE);
     } else { /* socks->command == SOCKS_COMMAND_CONNECT */
       if (socks->port == 0) {
         log_fn(LOG_NOTICE,"Application asked to connect to port 0. Refusing.");

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.556
retrieving revision 1.557
diff -u -d -r1.556 -r1.557
--- or.h	12 Mar 2005 20:13:38 -0000	1.556
+++ or.h	14 Mar 2005 03:12:59 -0000	1.557
@@ -1321,6 +1321,7 @@
 int connection_ap_can_use_exit(connection_t *conn, routerinfo_t *exit);
 void connection_ap_expire_beginning(void);
 void connection_ap_attach_pending(void);
+int connection_ap_detach_retriable(connection_t *conn, circuit_t *circ);
 
 void addressmap_init(void);
 void addressmap_clean(time_t now);
@@ -1378,7 +1379,8 @@
   STREAM_EVENT_FAILED       = 3,
   STREAM_EVENT_CLOSED       = 4,
   STREAM_EVENT_NEW          = 5,
-  STREAM_EVENT_NEW_RESOLVE  = 6
+  STREAM_EVENT_NEW_RESOLVE  = 6,
+  STREAM_EVENT_FAILED_RETRIABLE = 7
 } stream_status_event_t;
 
 typedef enum or_conn_status_event_t {

Index: relay.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/relay.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- relay.c	13 Mar 2005 05:53:17 -0000	1.47
+++ relay.c	14 Mar 2005 03:12:59 -0000	1.48
@@ -623,10 +623,9 @@
           router_parse_addr_policy_from_string("reject *:*");
       }
 
-      conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
-      circuit_detach_stream(circ,conn);
-      if (connection_ap_handshake_attach_circuit(conn) >= 0)
+      if (connection_ap_detach_retriable(conn, circ) >= 0)
         return 0;
+
       log_fn(LOG_INFO,"Giving up on retrying (from exitpolicy); conn can't be handled.");
       /* else, conn will get closed below */
     } else if (rh->length && reason == END_STREAM_REASON_RESOLVEFAILED) {
@@ -640,14 +639,14 @@
         log_fn(LOG_INFO,"Resolve of '%s' failed, trying again.",
                conn->socks_request->address);
         circuit_log_path(LOG_INFO,circ);
-        conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
-        circuit_detach_stream(circ,conn);
         tor_assert(circ->timestamp_dirty);
         circ->timestamp_dirty -= get_options()->MaxCircuitDirtiness;
         /* make sure not to expire/retry the stream quite yet */
         conn->timestamp_lastread = time(NULL);
-        if (connection_ap_handshake_attach_circuit(conn) >= 0)
+
+        if (connection_ap_detach_retriable(conn, circ) >= 0)
           return 0;
+
         /* else, conn will get closed below */
         log_fn(LOG_INFO,"Giving up on retrying (from resolvefailed); conn can't be handled.");
       } else {



More information about the tor-commits mailing list