[or-cvs] allow conns to demand to be attached to a clean circuit

Roger Dingledine arma at seul.org
Wed Mar 31 23:06:19 UTC 2004


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

Modified Files:
	circuit.c connection_edge.c main.c or.h 
Log Message:
allow conns to demand to be attached to a clean circuit
(nobody uses this yet)


Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.161
retrieving revision 1.162
diff -u -d -r1.161 -r1.162
--- circuit.c	30 Mar 2004 22:59:00 -0000	1.161
+++ circuit.c	31 Mar 2004 23:06:16 -0000	1.162
@@ -249,18 +249,22 @@
  * If !conn, return newest.
  *
  * If must_be_open, ignore circs not in CIRCUIT_STATE_OPEN.
+ * If must_be_clean, ignore circs that have been used before.
  */
-circuit_t *circuit_get_newest(connection_t *conn, int must_be_open) {
+circuit_t *circuit_get_newest(connection_t *conn,
+                              int must_be_open, int must_be_clean) {
   circuit_t *circ, *newest=NULL, *leastdirty=NULL;
   routerinfo_t *exitrouter;
 
-  for(circ=global_circuitlist;circ;circ = circ->next) {
-    if(!circ->cpath)
+  for (circ=global_circuitlist;circ;circ = circ->next) {
+    if (!circ->cpath)
       continue; /* this circ doesn't start at us */
-    if(must_be_open && (circ->state != CIRCUIT_STATE_OPEN || !circ->n_conn))
+    if (must_be_open && (circ->state != CIRCUIT_STATE_OPEN || !circ->n_conn))
       continue; /* ignore non-open circs */
     if (circ->marked_for_close)
       continue;
+    if (must_be_clean && circ->timestamp_dirty)
+      continue; /* ignore dirty circs */
     if(conn) {
       if(circ->state == CIRCUIT_STATE_OPEN && circ->n_conn) /* open */
         exitrouter = router_get_by_addr_port(circ->cpath->prev->addr, circ->cpath->prev->port);

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_edge.c,v
retrieving revision 1.120
retrieving revision 1.121
diff -u -d -r1.120 -r1.121
--- connection_edge.c	31 Mar 2004 22:02:13 -0000	1.120
+++ connection_edge.c	31 Mar 2004 23:06:16 -0000	1.121
@@ -9,8 +9,10 @@
 extern char *conn_state_to_string[][_CONN_TYPE_MAX+1];
 
 static int connection_ap_handshake_process_socks(connection_t *conn);
-static int connection_ap_handshake_attach_circuit(connection_t *conn);
-static int connection_ap_handshake_attach_circuit_helper(connection_t *conn);
+static int connection_ap_handshake_attach_circuit(connection_t *conn,
+                                                  int must_be_clean);
+static int connection_ap_handshake_attach_circuit_helper(connection_t *conn,
+                                                         int must_be_clean);
 static void connection_ap_handshake_send_begin(connection_t *ap_conn, circuit_t *circ);
 
 static int connection_exit_begin_conn(cell_t *cell, circuit_t *circ);
@@ -367,7 +369,8 @@
         addr = ntohl(addr);
         client_dns_set_entry(conn->socks_request->address, addr);
         conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
-        if(connection_ap_handshake_attach_circuit(conn) >= 0)
+        /* attaching to a dirty circuit is fine */
+        if(connection_ap_handshake_attach_circuit(conn, 0) >= 0)
           return 0;
         /* else, conn will get closed below */
       }
@@ -635,7 +638,8 @@
       circ->timestamp_dirty -= options.NewCircuitPeriod;
       /* give our stream another 15 seconds to try */
       conn->timestamp_lastread += 15;
-      if(connection_ap_handshake_attach_circuit(conn)<0) {
+      /* attaching to a dirty circuit is fine */
+      if(connection_ap_handshake_attach_circuit(conn,0)<0) {
         /* it will never work */
         /* Don't need to send end -- we're not connected */
         connection_mark_for_close(conn, 0);
@@ -658,7 +662,8 @@
     if (conn->type != CONN_TYPE_AP ||
         conn->state != AP_CONN_STATE_CIRCUIT_WAIT)
       continue;
-    if(connection_ap_handshake_attach_circuit(conn) < 0) {
+    /* attaching to a dirty circuit is fine */
+    if(connection_ap_handshake_attach_circuit(conn,0) < 0) {
       /* -1 means it will never work */
       /* Don't send end; there is no 'other side' yet */
       connection_mark_for_close(conn,0);
@@ -720,18 +725,22 @@
   } /* else socks handshake is done, continue processing */
 
   conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
-  return connection_ap_handshake_attach_circuit(conn);
+  /* attaching to a dirty circuit is fine */
+  return connection_ap_handshake_attach_circuit(conn,0);
 }
 
-static int connection_ap_handshake_attach_circuit(connection_t *conn) {
+static int connection_ap_handshake_attach_circuit(connection_t *conn,
+                                                  int must_be_clean) {
   /* try attaching. launch new circuit if needed.
    * return -1 if conn needs to die, else 0. */
-  switch(connection_ap_handshake_attach_circuit_helper(conn)) {
+  switch(connection_ap_handshake_attach_circuit_helper(conn, must_be_clean)) {
     case -1: /* it will never work */
       return -1;
     case 0: /* no useful circuits available */
-      if(!circuit_get_newest(conn, 0)) /* is one already on the way? */
+      if(!circuit_get_newest(conn, 0, must_be_clean)) {
+        /* is one already on the way? */
         circuit_launch_new();
+      }
       return 0;
     default: /* case 1, it succeeded, great */
       return 0;
@@ -744,7 +753,8 @@
  * Otherwise, associate conn with a safe live circuit, start
  * sending a BEGIN cell down the circuit, and return 1.
  */
-static int connection_ap_handshake_attach_circuit_helper(connection_t *conn) {
+static int connection_ap_handshake_attach_circuit_helper(connection_t *conn,
+                                                         int must_be_clean) {
   circuit_t *circ;
   uint32_t addr;
 
@@ -754,7 +764,7 @@
   assert(conn->socks_request);
 
   /* find the circuit that we should use, if there is one. */
-  circ = circuit_get_newest(conn, 1);
+  circ = circuit_get_newest(conn, 1, must_be_clean);
 
   if(!circ) {
     log_fn(LOG_INFO,"No safe circuit ready for edge connection; delaying.");
@@ -903,7 +913,8 @@
   conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
   connection_start_reading(conn);
 
-  if (connection_ap_handshake_attach_circuit(conn) < 0) {
+  /* attaching to a dirty circuit is fine */
+  if (connection_ap_handshake_attach_circuit(conn, 0) < 0) {
     connection_mark_for_close(conn, 0);
     close(fd[1]);
     return -1;

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.216
retrieving revision 1.217
diff -u -d -r1.216 -r1.217
--- main.c	31 Mar 2004 22:02:13 -0000	1.216
+++ main.c	31 Mar 2004 23:06:16 -0000	1.217
@@ -381,7 +381,7 @@
 /* Build a new test circuit every 5 minutes */
 #define TESTING_CIRCUIT_INTERVAL 300
 
-    circ = circuit_get_newest(NULL, 1);
+    circ = circuit_get_newest(NULL, 1, 0);
     if(time_to_new_circuit < now) {
       client_dns_clean();
       circuit_expire_unused_circuits();

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.268
retrieving revision 1.269
diff -u -d -r1.268 -r1.269
--- or.h	31 Mar 2004 22:02:13 -0000	1.268
+++ or.h	31 Mar 2004 23:06:16 -0000	1.269
@@ -658,7 +658,8 @@
 
 circuit_t *circuit_get_by_circ_id_conn(uint16_t circ_id, connection_t *conn);
 circuit_t *circuit_get_by_conn(connection_t *conn);
-circuit_t *circuit_get_newest(connection_t *conn, int must_be_open);
+circuit_t *circuit_get_newest(connection_t *conn,
+                              int must_be_open, int must_be_clean);
 circuit_t *circuit_get_by_service_and_purpose(const char *servid, int purpose);
 
 void circuit_expire_building(void);



More information about the tor-commits mailing list