summaryrefslogtreecommitdiff
path: root/src/or/circuit.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2003-11-12 02:55:38 +0000
committerNick Mathewson <nickm@torproject.org>2003-11-12 02:55:38 +0000
commit7d441ec6b4135739eae184a5770362dc6872a213 (patch)
tree0e52d942e21fa60683bb4885d24b18887a061592 /src/or/circuit.c
parente6296a4e2f32e29e2b5227934d0db30a67d52992 (diff)
downloadtor-7d441ec6b4135739eae184a5770362dc6872a213.tar.gz
tor-7d441ec6b4135739eae184a5770362dc6872a213.zip
Compute paths as we build them.
svn:r793
Diffstat (limited to 'src/or/circuit.c')
-rw-r--r--src/or/circuit.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/or/circuit.c b/src/or/circuit.c
index f84d288166..94ae20e436 100644
--- a/src/or/circuit.c
+++ b/src/or/circuit.c
@@ -647,9 +647,18 @@ int circuit_establish_circuit(void) {
circ = circuit_new(0, NULL); /* sets circ->p_circ_id and circ->p_conn */
circ->state = CIRCUIT_STATE_OR_WAIT;
- circ->cpath = onion_generate_cpath(&firsthop);
+ circ->desired_cpath_len = onion_new_route_len();
+
+ if (circ->desired_cpath_len < 0) {
+ log_fn(LOG_INFO,"Generating cpath length failed.");
+ circuit_close(circ);
+ return -1;
+ }
+
+ onion_extend_cpath(&circ->cpath, circ->desired_cpath_len,
+ &firsthop);
if(!circ->cpath) {
- log_fn(LOG_INFO,"Generating cpath failed.");
+ log_fn(LOG_INFO,"Generating first cpath hop failed.");
circuit_close(circ);
return -1;
}
@@ -720,8 +729,9 @@ int circuit_send_next_onion_skin(circuit_t *circ) {
cell_t cell;
crypt_path_t *hop;
routerinfo_t *router;
+ int r;
- assert(circ && circ->cpath);
+ assert(circ);
if(circ->cpath->state == CPATH_STATE_CLOSED) {
@@ -747,17 +757,20 @@ int circuit_send_next_onion_skin(circuit_t *circ) {
assert(circ->cpath->state == CPATH_STATE_OPEN);
assert(circ->state == CIRCUIT_STATE_BUILDING);
log_fn(LOG_DEBUG,"starting to send subsequent skin.");
- for(hop=circ->cpath->next;
- hop != circ->cpath && hop->state == CPATH_STATE_OPEN;
- hop=hop->next) ;
- if(hop == circ->cpath) { /* done building the circuit. whew. */
+ r = onion_extend_cpath(&circ->cpath, circ->desired_cpath_len, &router);
+ if (r==1) {
+ /* done building the circuit. whew. */
circ->state = CIRCUIT_STATE_OPEN;
- log_fn(LOG_INFO,"circuit built!");
+ log_fn(LOG_INFO,"circuit built! (%d hops long)",circ->desired_cpath_len);
/* Tell any AP connections that have been waiting for a new
* circuit that one is ready. */
connection_ap_attach_pending();
return 0;
+ } else if (r<0) {
+ log_fn(LOG_WARN,"Unable to extend circuit path.");
+ return -1;
}
+ hop = circ->cpath->prev;
router = router_get_by_addr_port(hop->addr,hop->port);
if(!router) {