summaryrefslogtreecommitdiff
path: root/src/or/circuit.c
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2003-11-18 09:53:03 +0000
committerRoger Dingledine <arma@torproject.org>2003-11-18 09:53:03 +0000
commitf0cccc567ecfd318305c4b6bab05091a50532e2a (patch)
tree8665d2934579eca13cb6510c3e25bd8024dd6f67 /src/or/circuit.c
parentac56486bf64df4eb3264e87538ac415ce42eefd9 (diff)
downloadtor-f0cccc567ecfd318305c4b6bab05091a50532e2a.tar.gz
tor-f0cccc567ecfd318305c4b6bab05091a50532e2a.zip
bugfix: don't ask for ->next of an expired circuit
bugfix: keep going when a circ fails in circuit_n_conn_open (make circuit_enumerate_by_naddr_nport obsolete) bugfix: make circuit_n_conn_open only look at circ's that start at us bugfix: only try circuit_n_conn_open if we're an OP. Otherwise we expect connections to always already be up. bugfix: when choosing path length, pay attention to whether the directory says a router is down. bugfix: when picking good exit, skip routers which are known to be down (more work needs to be done on this one) svn:r838
Diffstat (limited to 'src/or/circuit.c')
-rw-r--r--src/or/circuit.c63
1 files changed, 24 insertions, 39 deletions
diff --git a/src/or/circuit.c b/src/or/circuit.c
index 7849bda7fb..1a673b2562 100644
--- a/src/or/circuit.c
+++ b/src/or/circuit.c
@@ -141,20 +141,6 @@ static circ_id_t get_unique_circ_id_by_conn(connection_t *conn, int circ_id_type
return test_circ_id;
}
-circuit_t *circuit_enumerate_by_naddr_nport(circuit_t *circ, uint32_t naddr, uint16_t nport) {
-
- if(!circ) /* use circ if it's defined, else start from the beginning */
- circ = global_circuitlist;
- else
- circ = circ->next;
-
- for( ; circ; circ = circ->next) {
- if(circ->n_addr == naddr && circ->n_port == nport)
- return circ;
- }
- return NULL;
-}
-
circuit_t *circuit_get_by_circ_id_conn(circ_id_t circ_id, connection_t *conn) {
circuit_t *circ;
connection_t *tmpconn;
@@ -258,21 +244,23 @@ circuit_t *circuit_get_newest(connection_t *conn, int must_be_open) {
/* close all circuits that start at us, aren't open, and were born
* at least MIN_SECONDS_BEFORE_EXPIRING_CIRC seconds ago */
void circuit_expire_building(void) {
- circuit_t *circ;
int now = time(NULL);
+ circuit_t *victim, *circ = global_circuitlist;
- for(circ=global_circuitlist;circ;circ = circ->next) {
- if(circ->cpath &&
- circ->state != CIRCUIT_STATE_OPEN &&
- circ->timestamp_created + MIN_SECONDS_BEFORE_EXPIRING_CIRC+1 < now) {
- if(circ->n_conn)
+ while(circ) {
+ victim = circ;
+ circ = circ->next;
+ if(victim->cpath &&
+ victim->state != CIRCUIT_STATE_OPEN &&
+ victim->timestamp_created + MIN_SECONDS_BEFORE_EXPIRING_CIRC+1 < now) {
+ if(victim->n_conn)
log_fn(LOG_INFO,"Abandoning circ %s:%d:%d (state %d:%s)",
- circ->n_conn->address, circ->n_port, circ->n_circ_id,
- circ->state, circuit_state_to_string[circ->state]);
+ victim->n_conn->address, victim->n_port, victim->n_circ_id,
+ victim->state, circuit_state_to_string[victim->state]);
else
- log_fn(LOG_INFO,"Abandoning circ %d (state %d:%s)", circ->n_circ_id,
- circ->state, circuit_state_to_string[circ->state]);
- circuit_close(circ);
+ log_fn(LOG_INFO,"Abandoning circ %d (state %d:%s)", victim->n_circ_id,
+ victim->state, circuit_state_to_string[victim->state]);
+ circuit_close(victim);
}
}
}
@@ -793,21 +781,18 @@ int circuit_establish_circuit(void) {
void circuit_n_conn_open(connection_t *or_conn) {
circuit_t *circ;
- log_fn(LOG_DEBUG,"Starting.");
- circ = circuit_enumerate_by_naddr_nport(NULL, or_conn->addr, or_conn->port);
- for(;;) {
- if(!circ)
- return;
-
- assert(circ->state == CIRCUIT_STATE_OR_WAIT);
- log_fn(LOG_DEBUG,"Found circ, sending onion skin.");
- circ->n_conn = or_conn;
- if(circuit_send_next_onion_skin(circ) < 0) {
- log_fn(LOG_INFO,"send_next_onion_skin failed; circuit marked for closing.");
- circuit_close(circ);
- return; /* FIXME will want to try the other circuits too? */
+ for(circ=global_circuitlist;circ;circ = circ->next) {
+ if(circ->cpath && circ->n_addr == or_conn->addr && circ->n_port == or_conn->port) {
+ assert(circ->state == CIRCUIT_STATE_OR_WAIT);
+ log_fn(LOG_DEBUG,"Found circ %d, sending onion skin.", circ->n_circ_id);
+ circ->n_conn = or_conn;
+ if(circuit_send_next_onion_skin(circ) < 0) {
+ log_fn(LOG_INFO,"send_next_onion_skin failed; circuit marked for closing.");
+ circuit_close(circ);
+ continue;
+ /* XXX could this be bad, eg if next_onion_skin failed because conn died? */
+ }
}
- circ = circuit_enumerate_by_naddr_nport(circ, or_conn->addr, or_conn->port);
}
}