aboutsummaryrefslogtreecommitdiff
path: root/src/or
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
parente6296a4e2f32e29e2b5227934d0db30a67d52992 (diff)
downloadtor-7d441ec6b4135739eae184a5770362dc6872a213.tar
tor-7d441ec6b4135739eae184a5770362dc6872a213.tar.gz
Compute paths as we build them.
svn:r793
Diffstat (limited to 'src/or')
-rw-r--r--src/or/circuit.c29
-rw-r--r--src/or/onion.c7
-rw-r--r--src/or/or.h3
3 files changed, 31 insertions, 8 deletions
diff --git a/src/or/circuit.c b/src/or/circuit.c
index f84d28816..94ae20e43 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) {
diff --git a/src/or/onion.c b/src/or/onion.c
index 8b8a87cfe..848b7e866 100644
--- a/src/or/onion.c
+++ b/src/or/onion.c
@@ -212,6 +212,13 @@ static int new_route_len(double cw, routerinfo_t **rarray, int rarray_len) {
return routelen;
}
+int onion_new_route_len(void) {
+ directory_t *dir;
+
+ router_get_directory(&dir);
+ return new_route_len(options.CoinWeight, dir->routers, dir->n_routers);
+}
+
static int count_acceptable_routers(routerinfo_t **rarray, int rarray_len) {
int i, j;
int num=0;
diff --git a/src/or/or.h b/src/or/or.h
index e3293e7da..b0ba5cc7f 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -409,6 +409,7 @@ struct circuit_t {
crypto_cipher_env_t *p_crypto; /* used only for intermediate hops */
crypto_cipher_env_t *n_crypto;
+ int desired_cpath_len;
crypt_path_t *cpath;
char onionskin[DH_ONIONSKIN_LEN]; /* for storage while onionskin pending */
@@ -710,6 +711,8 @@ int onion_skin_client_handshake(crypto_dh_env_t *handshake_state,
char *key_out,
int key_out_len);
+int onion_new_route_len(void);
+
/********************************* routers.c ***************************/
int learn_my_address(struct sockaddr_in *me);