From b7c2b18bd696f79e6866ae70c58373dfbedf91f0 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 21 Mar 2004 03:03:10 +0000 Subject: Add a RunTesting option to try to learn link state by creating test circuits, even when SocksPort is off. svn:r1327 --- src/or/circuit.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/or/circuit.c') diff --git a/src/or/circuit.c b/src/or/circuit.c index 45b10ee25..c4f51e79a 100644 --- a/src/or/circuit.c +++ b/src/or/circuit.c @@ -907,6 +907,9 @@ void circuit_dump_by_conn(connection_t *conn, int severity) { } } +/* 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 @@ void circuit_expire_unused_circuits(void) { 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 @@ static int n_circuit_failures = 0; /* 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. */ -- cgit v1.2.3