[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Compute paths as we build them.



Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv17914/or

Modified Files:
	circuit.c onion.c or.h 
Log Message:
Compute paths as we build them.


Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -d -r1.85 -r1.86
--- circuit.c	12 Nov 2003 02:32:20 -0000	1.85
+++ circuit.c	12 Nov 2003 02:55:38 -0000	1.86
@@ -647,9 +647,18 @@
 
   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 @@
   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 @@
     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) {

Index: onion.c
===================================================================
RCS file: /home/or/cvsroot/src/or/onion.c,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- onion.c	12 Nov 2003 02:32:20 -0000	1.77
+++ onion.c	12 Nov 2003 02:55:38 -0000	1.78
@@ -212,6 +212,13 @@
   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;

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.179
retrieving revision 1.180
diff -u -d -r1.179 -r1.180
--- or.h	12 Nov 2003 02:32:20 -0000	1.179
+++ or.h	12 Nov 2003 02:55:38 -0000	1.180
@@ -409,6 +409,7 @@
   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 */
@@ -709,6 +710,8 @@
                              char *handshake_reply,/* Must be DH_KEY_LEN bytes long*/
                              char *key_out,
                              int key_out_len);
+
+int onion_new_route_len(void);
 
 /********************************* routers.c ***************************/