summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-03-21 03:03:10 +0000
committerNick Mathewson <nickm@torproject.org>2004-03-21 03:03:10 +0000
commitb7c2b18bd696f79e6866ae70c58373dfbedf91f0 (patch)
tree4674f7f0ab23e4b4d4c148c832cdf1a76092fadc
parent0d8feba6d8225f012cadbfccb001236260f83bf5 (diff)
downloadtor-b7c2b18bd696f79e6866ae70c58373dfbedf91f0.tar.gz
tor-b7c2b18bd696f79e6866ae70c58373dfbedf91f0.zip
Add a RunTesting option to try to learn link state by creating test circuits, even when SocksPort is off.
svn:r1327
-rw-r--r--src/or/circuit.c20
-rw-r--r--src/or/config.c3
-rw-r--r--src/or/connection_or.c5
-rw-r--r--src/or/main.c14
-rw-r--r--src/or/or.h1
5 files changed, 31 insertions, 12 deletions
diff --git a/src/or/circuit.c b/src/or/circuit.c
index 45b10ee252..c4f51e79a4 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. */
diff --git a/src/or/config.c b/src/or/config.c
index 799eb97966..a472f7ea49 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -201,7 +201,8 @@ static int config_assign(or_options_t *options, struct config_line *list) {
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 {
diff --git a/src/or/connection_or.c b/src/or/connection_or.c
index 39f3f27551..c61f3117b0 100644
--- a/src/or/connection_or.c
+++ b/src/or/connection_or.c
@@ -243,11 +243,8 @@ static int connection_tls_finish_handshake(connection_t *conn) {
}
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;
diff --git a/src/or/main.c b/src/or/main.c
index 86ea5923e4..491a5ef82d 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -354,10 +354,14 @@ static void run_scheduled_events(time_t now) {
* 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) {
+
+ if (options.SocksPort)
+ /* launch a new circ for any pending streams that need one */
+ connection_ap_attach_pending();
- /* 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 @@ static void run_scheduled_events(time_t now) {
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;
}
diff --git a/src/or/or.h b/src/or/or.h
index 8754e4468b..feb2d0fd84 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -544,6 +544,7 @@ typedef struct {
int BandwidthBurst;
int NumCpus;
int loglevel;
+ int RunTesting;
} or_options_t;
/* XXX are these good enough defaults? */