[or-cvs] break circuit_build_needed_circs into its own func

Roger Dingledine arma at seul.org
Mon Apr 12 22:47:14 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 main.c or.h 
Log Message:
break circuit_build_needed_circs into its own func


Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.202
retrieving revision 1.203
diff -u -d -r1.202 -r1.203
--- circuit.c	9 Apr 2004 20:08:13 -0000	1.202
+++ circuit.c	12 Apr 2004 22:47:11 -0000	1.203
@@ -514,6 +514,43 @@
   return 0;
 }
 
+void circuit_build_needed_circs(time_t now) {
+  static long time_to_new_circuit = 0;
+  circuit_t *circ;
+
+  if (options.SocksPort)
+    /* launch a new circ for any pending streams that need one */
+    connection_ap_attach_pending();
+
+/* Build a new test circuit every 5 minutes */
+#define TESTING_CIRCUIT_INTERVAL 300
+
+  circ = circuit_get_best(NULL, 1, CIRCUIT_PURPOSE_C_GENERAL);
+  if(time_to_new_circuit < now) {
+    client_dns_clean();
+    circuit_expire_unused_circuits();
+    circuit_reset_failure_count();
+    if(circ && circ->timestamp_dirty) {
+      log_fn(LOG_INFO,"Youngest circuit dirty; launching replacement.");
+      /* make a new circuit */
+      circuit_launch_new(CIRCUIT_PURPOSE_C_GENERAL, NULL);
+    } else if (options.RunTesting && circ &&
+               circ->timestamp_created + TESTING_CIRCUIT_INTERVAL < now) {
+      log_fn(LOG_INFO,"Creating a new testing circuit.");
+      circuit_launch_new(CIRCUIT_PURPOSE_C_GENERAL, NULL);
+    }
+    time_to_new_circuit = now + options.NewCircuitPeriod;
+    time_to_new_circuit = now + options.NewCircuitPeriod;
+  }
+#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(CIRCUIT_PURPOSE_C_GENERAL, NULL);
+  }
+}
+
 /* update digest from the payload of cell. assign integrity part to cell. */
 static void relay_set_digest(crypto_digest_env_t *digest, cell_t *cell) {
   char integrity[4];

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.236
retrieving revision 1.237
diff -u -d -r1.236 -r1.237
--- main.c	9 Apr 2004 20:08:13 -0000	1.236
+++ main.c	12 Apr 2004 22:47:12 -0000	1.237
@@ -338,8 +338,6 @@
  */
 static void run_scheduled_events(time_t now) {
   static long time_to_fetch_directory = 0;
-  static long time_to_new_circuit = 0;
-  circuit_t *circ;
   int i;
 
   /* 1. Every DirFetchPostPeriod seconds, we get a new directory and upload
@@ -388,49 +386,19 @@
    *    and we make a new circ if there are no clean circuits.
    */
   if(has_fetched_directory &&
-     (options.SocksPort || options.RunTesting)) {
-
-    if (options.SocksPort)
-      /* launch a new circ for any pending streams that need one */
-      connection_ap_attach_pending();
-
-/* Build a new test circuit every 5 minutes */
-#define TESTING_CIRCUIT_INTERVAL 300
-
-    circ = circuit_get_best(NULL, 1, CIRCUIT_PURPOSE_C_GENERAL);
-    if(time_to_new_circuit < now) {
-      client_dns_clean();
-      circuit_expire_unused_circuits();
-      circuit_reset_failure_count();
-      if(circ && circ->timestamp_dirty) {
-        log_fn(LOG_INFO,"Youngest circuit dirty; launching replacement.");
-        /* make a new circuit */
-        circuit_launch_new(CIRCUIT_PURPOSE_C_GENERAL, NULL);
-      } else if (options.RunTesting && circ &&
-                 circ->timestamp_created + TESTING_CIRCUIT_INTERVAL < now) {
-        log_fn(LOG_INFO,"Creating a new testing circuit.");
-        circuit_launch_new(CIRCUIT_PURPOSE_C_GENERAL, NULL);
-      }
-      time_to_new_circuit = now + options.NewCircuitPeriod;
-    }
-#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(CIRCUIT_PURPOSE_C_GENERAL, NULL);
-    }
-  }
+     (options.SocksPort || options.RunTesting))
+    circuit_build_needed_circs(now);
 
-  /* 5. We do housekeeping for each connection... */
+  /* 4. We do housekeeping for each connection... */
   for(i=0;i<nfds;i++) {
     run_connection_housekeeping(i, now);
   }
 
-  /* 6. And remove any marked circuits... */
+  /* 5. And remove any marked circuits... */
   circuit_close_all_marked();
 
-  /* 7. and blow away any connections that need to die. can't do this later
+#if 0
+  /* 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
@@ -438,6 +406,7 @@
    */
   for(i=0;i<nfds;i++)
     conn_close_if_marked(i);
+#endif
 }
 
 static int prepare_for_poll(void) {

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.311
retrieving revision 1.312
diff -u -d -r1.311 -r1.312
--- or.h	9 Apr 2004 20:02:16 -0000	1.311
+++ or.h	12 Apr 2004 22:47:12 -0000	1.312
@@ -716,6 +716,7 @@
 void circuit_expire_building(void);
 int circuit_count_building(void);
 int circuit_stream_is_being_handled(connection_t *conn);
+void circuit_build_needed_circs(time_t now);
 
 int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ,
                                int cell_direction);



More information about the tor-commits mailing list