[or-cvs] Add a RunTesting option to try to learn link state by creat...

Nick Mathewson nickm at seul.org
Sun Mar 21 03:03:13 UTC 2004


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

Modified Files:
	circuit.c config.c connection_or.c main.c or.h 
Log Message:
Add a RunTesting option to try to learn link state by creating test circuits, even when SocksPort is off.

Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.155
retrieving revision 1.156
diff -u -d -r1.155 -r1.156
--- circuit.c	20 Mar 2004 20:21:20 -0000	1.155
+++ circuit.c	21 Mar 2004 03:03:10 -0000	1.156
@@ -907,6 +907,9 @@
   }
 }
 
+/* Expire unused testing circuits after 10 minutes. */
+#define TESTING_CIRCUIT_MAX_AGE 600
+
 void circuit_expire_unused_circuits(void) {
   circuit_t *circ, *tmpcirc;
   time_t now = time(NULL);
@@ -915,9 +918,18 @@
   while(circ) {
     tmpcirc = circ;
     circ = circ->next;
-    if(tmpcirc->timestamp_dirty &&
-       tmpcirc->timestamp_dirty + options.NewCircuitPeriod < now &&
-       !tmpcirc->p_conn && !tmpcirc->p_streams && !tmpcirc->marked_for_close) {
+    /* If the circuit has been dirty for too long, and there are no streams
+     * on it, mark it for close.
+     * If we are creating test circuits, and the circuit is old, and has
+     * no streams, shut it down even if it isn't dirty.
+     */
+    if(((tmpcirc->timestamp_dirty &&
+         tmpcirc->timestamp_dirty + options.NewCircuitPeriod < now) ||
+        (options.RunTesting &&
+         tmpcirc->timestamp_created + TESTING_CIRCUIT_MAX_AGE < now))
+       && !tmpcirc->p_conn
+       && !tmpcirc->p_streams
+       && !tmpcirc->marked_for_close) {
       log_fn(LOG_DEBUG,"Closing n_circ_id %d",tmpcirc->n_circ_id);
       circuit_mark_for_close(tmpcirc);
     }
@@ -932,7 +944,7 @@
 /* Return -1 if you aren't going to try to make a circuit, 0 if you did try. */
 int circuit_launch_new(void) {
 
-  if(!options.SocksPort) /* we're not an application proxy. no need for circuits. */
+  if(!(options.SocksPort||options.RunTesting)) /* no need for circuits. */
     return -1;
 
   if(n_circuit_failures > 5) { /* too many failed circs in a row. don't try. */

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.99
retrieving revision 1.100
diff -u -d -r1.99 -r1.100
--- config.c	20 Mar 2004 20:28:53 -0000	1.99
+++ config.c	21 Mar 2004 03:03:10 -0000	1.100
@@ -201,7 +201,8 @@
 
     config_compare(list, "TrafficShaping", CONFIG_TYPE_BOOL, &options->TrafficShaping) ||
 
-    config_compare(list, "User",           CONFIG_TYPE_STRING, &options->User)
+    config_compare(list, "User",           CONFIG_TYPE_STRING, &options->User) ||
+    config_compare(list, "RunTesting",     CONFIG_TYPE_BOOL, &options->RunTesting)
     ) {
       /* then we're ok. it matched something. */
     } else {

Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_or.c,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -d -r1.88 -r1.89
--- connection_or.c	20 Mar 2004 04:59:29 -0000	1.88
+++ connection_or.c	21 Mar 2004 03:03:10 -0000	1.89
@@ -243,11 +243,8 @@
   }
   if (!options.ORPort) { /* If I'm an OP... */
     conn->receiver_bucket = conn->bandwidth = DEFAULT_BANDWIDTH_OP;
-    circuit_n_conn_open(conn); /* send the pending creates, if any. */
-    /* XXXX ORs may need to send creates for test circuits; "I am an OR"
-     * doesn't mean "I have no pending creates", right?
-     */
   }
+  circuit_n_conn_open(conn); /* send the pending creates, if any. */
   /* Note the success */
   rep_hist_note_connect_succeeded(nickname, time(NULL));
   return 0;

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.206
retrieving revision 1.207
diff -u -d -r1.206 -r1.207
--- main.c	20 Mar 2004 23:27:22 -0000	1.206
+++ main.c	21 Mar 2004 03:03:10 -0000	1.207
@@ -354,10 +354,14 @@
    *    that became dirty more than NewCircuitPeriod seconds ago,
    *    and we make a new circ if there are no clean circuits.
    */
-  if(options.SocksPort) {
+  if(options.SocksPort || options.RunTesting) {
 
-    /* launch a new circ for any pending streams that need one */
-    connection_ap_attach_pending();
+    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_newest(NULL, 1);
     if(time_to_new_circuit < now) {
@@ -367,6 +371,10 @@
       if(circ && circ->timestamp_dirty) {
         log_fn(LOG_INFO,"Youngest circuit dirty; launching replacement.");
         circuit_launch_new(); /* make a new circuit */
+      } else if (options.RunTesting && circ &&
+                 circ->timestamp_created + TESTING_CIRCUIT_INTERVAL < now) {
+        log_fn(LOG_INFO,"Creating a new testing circuit.");
+        circuit_launch_new();
       }
       time_to_new_circuit = now + options.NewCircuitPeriod;
     }

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.255
retrieving revision 1.256
diff -u -d -r1.255 -r1.256
--- or.h	20 Mar 2004 04:59:29 -0000	1.255
+++ or.h	21 Mar 2004 03:03:10 -0000	1.256
@@ -544,6 +544,7 @@
   int BandwidthBurst;
   int NumCpus;
   int loglevel;
+  int RunTesting;
 } or_options_t;
 
 /* XXX are these good enough defaults? */



More information about the tor-commits mailing list