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

[or-cvs] don"t build too many circs at once



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

Modified Files:
	circuit.c command.c main.c or.h 
Log Message:
don't build too many circs at once
expire circs that have been building for too long


Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -d -r1.103 -r1.104
--- circuit.c	17 Nov 2003 18:40:56 -0000	1.103
+++ circuit.c	18 Nov 2003 07:48:00 -0000	1.104
@@ -250,6 +250,46 @@
   return NULL;
 }
 
+#define MIN_SECONDS_BEFORE_EXPIRING_CIRC 2
+/* circuits that were born at the end of their second might be expired
+ * after 2.1 seconds; circuits born at the beginning might be expired
+ * after closer to 3 seconds.
+ */
+
+/* close all circuits that start at us, aren't open, and were born
+ * at least MIN_SECONDS_BEFORE_EXPIRING_CIRC seconds ago */
+void circuit_expire_building(void) {
+  circuit_t *circ;
+  int now = time(NULL);
+
+  for(circ=global_circuitlist;circ;circ = circ->next) {
+    if(circ->cpath &&
+       circ->state != CIRCUIT_STATE_OPEN &&
+       circ->timestamp_created + MIN_SECONDS_BEFORE_EXPIRING_CIRC+1 < now) {
+      if(circ->n_conn)
+        log_fn(LOG_INFO,"Abandoning circ %s:%d:%d (state %d:%s)",
+               circ->n_conn->address, circ->n_port, circ->n_circ_id,
+               circ->state, circuit_state_to_string[circ->state]);
+      else
+        log_fn(LOG_INFO,"Abandoning circ %d (state %d:%s)", circ->n_circ_id,
+               circ->state, circuit_state_to_string[circ->state]);
+      circuit_close(circ);
+    }
+  }
+}
+
+/* count the number of circs starting at us that aren't open */
+int circuit_count_building(void) {
+  circuit_t *circ;
+  int num=0;
+
+  for(circ=global_circuitlist;circ;circ = circ->next) {
+    if(circ->cpath && circ->state != CIRCUIT_STATE_OPEN)
+      num++;
+  }
+  return num;
+}
+
 int circuit_deliver_relay_cell(cell_t *cell, circuit_t *circ,
                                int cell_direction, crypt_path_t *layer_hint) {
   connection_t *conn=NULL;
@@ -818,7 +858,7 @@
       connection_ap_attach_pending();
       return 0;
     } else if (r<0) {
-      log_fn(LOG_WARN,"Unable to extend circuit path.");
+      log_fn(LOG_INFO,"Unable to extend circuit path.");
       return -1;
     }
     hop = circ->cpath->prev;

Index: command.c
===================================================================
RCS file: /home/or/cvsroot/src/or/command.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- command.c	16 Nov 2003 17:31:19 -0000	1.47
+++ command.c	18 Nov 2003 07:48:00 -0000	1.48
@@ -146,8 +146,8 @@
     }
     log_fn(LOG_DEBUG,"Moving to next skin.");
     if(circuit_send_next_onion_skin(circ) < 0) {
-      log_fn(LOG_WARN,"circuit_send_next_onion_skin failed.");
-      circuit_close(circ);
+      log_fn(LOG_INFO,"circuit_send_next_onion_skin failed.");
+      circuit_close(circ); /* XXX push this circuit_close lower */
       return;
     }
   } else { /* pack it into an extended relay cell, and send it. */

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.147
retrieving revision 1.148
diff -u -d -r1.147 -r1.148
--- main.c	17 Nov 2003 00:57:56 -0000	1.147
+++ main.c	18 Nov 2003 07:48:00 -0000	1.148
@@ -335,7 +335,14 @@
     time_to_fetch_directory = now + options.DirFetchPostPeriod;
   }
 
-  /* 2. Every second, we try a new circuit if there are no valid
+  /* 2. Every second, we examine pending circuits and prune the
+   *    ones which have been pending for more than 2 seconds.
+   *    We do this before step 3, so it can try building more if
+   *    it's not comfortable with the number of available circuits.
+   */
+  circuit_expire_building();
+
+  /* 3. Every second, we try a new circuit if there are no valid
    *    circuits. Every NewCircuitPeriod seconds, we expire circuits
    *    that became dirty more than NewCircuitPeriod seconds ago,
    *    and we make a new circ if there are no clean circuits.
@@ -356,11 +363,15 @@
       }
       time_to_new_circuit = now + options.NewCircuitPeriod;
     }
-    if(!circ)
+#define CIRCUIT_MIN_BUILDING 3
+    if(!circ && circuit_count_building() < CIRCUIT_MIN_BUILDING)
+      /* if there's no open circ, and less than 3 are on the way,
+       * go ahead and try another.
+       */
       circuit_launch_new(1);
   }
 
-  /* 3. Every second, we check how much bandwidth we've consumed and 
+  /* 4. Every second, we check how much bandwidth we've consumed and 
    *    increment global_read_bucket.
    */
   stats_n_bytes_read += stats_prev_global_read_bucket-global_read_bucket;
@@ -370,12 +381,12 @@
   }
   stats_prev_global_read_bucket = global_read_bucket;
 
-  /* 4. We do houskeeping for each connection... */
+  /* 5. We do housekeeping for each connection... */
   for(i=0;i<nfds;i++) {
     run_connection_housekeeping(i, now);
   }
 
-  /* 5. and blow away any connections that need to die. can't do this later
+  /* 6. and blow away any connections that need to die. can't do this later
    * because we might open up a circuit and not realize we're about to cull
    * the connection it's running over.
    * XXX we can remove this step once we audit circuit-building to make sure

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.190
retrieving revision 1.191
diff -u -d -r1.190 -r1.191
--- or.h	17 Nov 2003 00:57:56 -0000	1.190
+++ or.h	18 Nov 2003 07:48:00 -0000	1.191
@@ -110,7 +110,6 @@
 
 #define CIRC_ID_TYPE_LOWER 0
 #define CIRC_ID_TYPE_HIGHER 1
-#define CIRC_ID_TYPE_BOTH 2
 
 #define _CONN_TYPE_MIN 3
 #define CONN_TYPE_OR_LISTENER 3
@@ -517,6 +516,9 @@
 circuit_t *circuit_get_by_circ_id_conn(circ_id_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);
+
+void circuit_expire_building(void);
+int circuit_count_building(void);
 
 int circuit_deliver_relay_cell(cell_t *cell, circuit_t *circ,
                                int cell_direction, crypt_path_t *layer_hint);