[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Separate failure-count tracking from circuit-launching.
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv11957/or
Modified Files:
circuit.c connection_edge.c main.c or.h
Log Message:
Separate failure-count tracking from circuit-launching.
Increment failure counts only when circuits close without having been built.
Reset failure counts only on the second, and when circuits are done building.
Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -d -r1.107 -r1.108
--- circuit.c 18 Nov 2003 21:12:17 -0000 1.107
+++ circuit.c 19 Nov 2003 02:22:52 -0000 1.108
@@ -566,6 +566,10 @@
for(conn=circ->p_streams; conn; conn=conn->next_stream) {
connection_send_destroy(circ->p_circ_id, conn);
}
+ if (circ->state != CIRCUIT_STATE_OPEN && circ->cpath) {
+ /* If we never built the circuit, note it as a failure. */
+ circuit_increment_failure_count();
+ }
circuit_free(circ);
}
@@ -686,37 +690,42 @@
}
}
+/* Number of failures so far this second; should only be touched by
+ * circuit_launch_new and circuit_*_failure_count.
+ */
+static int n_circuit_failures = 0;
+
/* failure_status code: negative means reset failures to 0. Other values mean
* add that value to the current number of failures, then if we don't have too
* many failures on record, try to make a new circuit.
*
* Return -1 if you aren't going to try to make a circuit, 0 if you did try.
*/
-int circuit_launch_new(int failure_status) {
- static int failures=0;
+int circuit_launch_new(void) {
if(!options.SocksPort) /* we're not an application proxy. no need for circuits. */
return -1;
- if(failure_status == -1) { /* I was called because a circuit succeeded */
- failures = 0;
- return -1;
- }
-
- failures += failure_status;
-
- if(failures > 5) {
+ if(n_circuit_failures > 5) {
return -1;
}
if(circuit_establish_circuit() < 0) {
+ ++n_circuit_failures;
return 0;
}
- failures = 0;
return 0;
}
+void circuit_increment_failure_count(void) {
+ ++n_circuit_failures;
+}
+
+void circuit_reset_failure_count(void) {
+ n_circuit_failures = 0;
+}
+
int circuit_establish_circuit(void) {
routerinfo_t *firsthop;
connection_t *n_conn;
@@ -840,6 +849,7 @@
/* done building the circuit. whew. */
circ->state = CIRCUIT_STATE_OPEN;
log_fn(LOG_INFO,"circuit built!");
+ circuit_reset_failure_count();
/* Tell any AP connections that have been waiting for a new
* circuit that one is ready. */
connection_ap_attach_pending();
Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_edge.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- connection_edge.c 18 Nov 2003 08:20:19 -0000 1.64
+++ connection_edge.c 19 Nov 2003 02:22:52 -0000 1.65
@@ -257,7 +257,7 @@
client_dns_set_entry(conn->socks_request->address, addr);
conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
if(connection_ap_handshake_attach_circuit(conn) < 0)
- circuit_launch_new(1); /* Build another circuit to handle this stream */
+ circuit_launch_new(); /* Build another circuit to handle this stream */
return 0;
}
log_fn(LOG_INFO,"end cell (%s) for stream %d. Removing stream.",
@@ -499,7 +499,7 @@
if (connection_ap_handshake_attach_circuit(carray[i])<0) {
if(!circuit_get_newest(carray[i], 0)) {
/* if there are no acceptable clean or not-very-dirty circs on the way */
- circuit_launch_new(1);
+ circuit_launch_new();
}
}
}
@@ -558,7 +558,7 @@
conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
if(connection_ap_handshake_attach_circuit(conn) < 0)
- circuit_launch_new(1); /* Build another circuit to handle this stream */
+ circuit_launch_new(); /* Build another circuit to handle this stream */
return 0;
}
Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.150
retrieving revision 1.151
diff -u -d -r1.150 -r1.151
--- main.c 19 Nov 2003 02:09:43 -0000 1.150
+++ main.c 19 Nov 2003 02:22:52 -0000 1.151
@@ -356,19 +356,20 @@
if(time_to_new_circuit < now) {
client_dns_clean();
circuit_expire_unused_circuits();
- circuit_launch_new(-1); /* tell it to forget about previous failures */
+ circuit_reset_failure_count();
if(circ && circ->timestamp_dirty) {
log_fn(LOG_INFO,"Youngest circuit dirty; launching replacement.");
- circuit_launch_new(0); /* make a new circuit */
+ circuit_launch_new(); /* make a new circuit */
}
time_to_new_circuit = now + options.NewCircuitPeriod;
}
#define CIRCUIT_MIN_BUILDING 2
- if(!circ && circuit_count_building() < CIRCUIT_MIN_BUILDING)
+ if(!circ && circuit_count_building() < CIRCUIT_MIN_BUILDING) {
/* if there's no open circ, and less than 2 are on the way,
* go ahead and try another.
*/
- circuit_launch_new(1);
+ circuit_launch_new();
+ }
}
/* 4. Every second, we check how much bandwidth we've consumed and
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.192
retrieving revision 1.193
diff -u -d -r1.192 -r1.193
--- or.h 18 Nov 2003 09:53:03 -0000 1.192
+++ or.h 19 Nov 2003 02:22:52 -0000 1.193
@@ -535,7 +535,9 @@
void circuit_dump_by_conn(connection_t *conn, int severity);
void circuit_expire_unused_circuits(void);
-int circuit_launch_new(int failure_status);
+int circuit_launch_new(void);
+void circuit_increment_failure_count(void);
+void circuit_reset_failure_count(void);
int circuit_establish_circuit(void);
void circuit_n_conn_open(connection_t *or_conn);
int circuit_send_next_onion_skin(circuit_t *circ);