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

[or-cvs] Now do address rewriting when the controller asks us to att...



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

Modified Files:
	connection_edge.c control.c or.h 
Log Message:
Now do address rewriting when the controller asks us to attach
to a particular circuit too. This will let Blossom specify
"moria2.exit" without having to learn what moria2's IP address is.

It may also cause other controller authors some angst. Let us know.


Index: connection_edge.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/connection_edge.c,v
retrieving revision 1.382
retrieving revision 1.383
diff -u -p -d -r1.382 -r1.383
--- connection_edge.c	5 Mar 2006 09:50:25 -0000	1.382
+++ connection_edge.c	12 Mar 2006 05:04:16 -0000	1.383
@@ -930,7 +930,9 @@ addressmap_get_mappings(smartlist_t *sl,
 }
 
 /* Connection <b>conn</b> just finished its socks handshake, or the
- * controller asked us to take care of it.
+ * controller asked us to take care of it. If <b>circ</b> is defined,
+ * then that's where we'll want to attach it. Otherwise we have to
+ * figure it out ourselves.
  *
  * First, parse whether it's a .exit address, remap it, and so on. Then
  * it's for a general circuit, try to attach it to a circuit (or launch
@@ -939,7 +941,8 @@ addressmap_get_mappings(smartlist_t *sl,
  * rendezvous descriptor is already here and fresh enough).
  */
 int
-connection_ap_handshake_rewrite_and_attach(connection_t *conn)
+connection_ap_handshake_rewrite_and_attach(connection_t *conn,
+                                           circuit_t *circ)
 {
   socks_request_t *socks = conn->socks_request;
   hostname_type_t addresstype;
@@ -1048,7 +1051,7 @@ connection_ap_handshake_rewrite_and_atta
         return -1;
       }
 
-      if (!conn->chosen_exit_name) {
+      if (!conn->chosen_exit_name && !circ) {
         /* see if we can find a suitable enclave exit */
         routerinfo_t *r =
           router_find_exact_exit_enclave(socks->address, socks->port);
@@ -1067,7 +1070,10 @@ connection_ap_handshake_rewrite_and_atta
       rep_hist_note_used_port(socks->port, time(NULL));
     }
     conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
-    if (connection_ap_handshake_attach_circuit(conn) < 0) {
+    if ((circ &&
+         connection_ap_handshake_attach_chosen_circuit(conn, circ) < 0) ||
+        (!circ &&
+         connection_ap_handshake_attach_circuit(conn) < 0)) {
       connection_mark_unattached_ap(conn, END_STREAM_REASON_CANT_ATTACH);
       return -1;
     }
@@ -1089,6 +1095,13 @@ connection_ap_handshake_rewrite_and_atta
       return -1;
     }
 
+    if (circ) {
+      log_warn(LD_CONTROL, "Attachstream to a circuit is not "
+               "supported for .onion addresses currently. Failing.");
+      connection_mark_unattached_ap(conn, END_STREAM_REASON_TORPROTOCOL);
+      return -1;
+    }
+
     strlcpy(conn->rend_query, socks->address, sizeof(conn->rend_query));
     log_info(LD_REND,"Got a hidden service request for ID '%s'",
              safe_str(conn->rend_query));
@@ -1183,8 +1196,8 @@ connection_ap_handshake_process_socks(co
   if (options->LeaveStreamsUnattached) {
     conn->state = AP_CONN_STATE_CONTROLLER_WAIT;
     return 0;
-  } else
-    return connection_ap_handshake_rewrite_and_attach(conn);
+  }
+  return connection_ap_handshake_rewrite_and_attach(conn, NULL);
 }
 
 /** Iterate over the two bytes of stream_id until we get one that is not

Index: control.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.177
retrieving revision 1.178
diff -u -p -d -r1.177 -r1.178
--- control.c	12 Mar 2006 04:33:29 -0000	1.177
+++ control.c	12 Mar 2006 05:04:16 -0000	1.178
@@ -1840,12 +1840,7 @@ handle_control_attachstream(connection_t
     ap_conn->state = AP_CONN_STATE_CONTROLLER_WAIT;
   }
 
-  if (zero_circ) {
-    connection_ap_handshake_rewrite_and_attach(ap_conn);
-    send_control_done(conn);
-    return 0;
-  }
-  if (circ->state != CIRCUIT_STATE_OPEN) {
+  if (circ && circ->state != CIRCUIT_STATE_OPEN) {
     if (STATE_IS_V0(conn->state))
       send_control0_error(conn, ERR_INTERNAL,
                           "Refuse to attach stream to non-open circ.");
@@ -1855,7 +1850,7 @@ handle_control_attachstream(connection_t
                           conn);
     return 0;
   }
-  if (connection_ap_handshake_attach_chosen_circuit(ap_conn, circ) != 1) {
+  if (connection_ap_handshake_rewrite_and_attach(ap_conn, circ) < 0) {
     if (STATE_IS_V0(conn->state))
       send_control0_error(conn, ERR_INTERNAL, "Unable to attach stream.");
     else

Index: or.h
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.802
retrieving revision 1.803
diff -u -p -d -r1.802 -r1.803
--- or.h	11 Mar 2006 02:21:30 -0000	1.802
+++ or.h	12 Mar 2006 05:04:16 -0000	1.803
@@ -1758,8 +1758,8 @@ int address_is_in_virtual_range(const ch
 const char *addressmap_register_virtual_address(int type, char *new_address);
 void addressmap_get_mappings(smartlist_t *sl, time_t min_expires,
                              time_t max_expires);
-int
-connection_ap_handshake_rewrite_and_attach(connection_t *conn);
+int connection_ap_handshake_rewrite_and_attach(connection_t *conn,
+                                               circuit_t *circ);
 
 void parse_socks_policy(void);
 void free_socks_policy(void);