[or-cvs] make circ->onionskin a pointer, not a static array. moria2 ...

arma at seul.org arma at seul.org
Sat Oct 29 19:13:50 UTC 2005


Update of /home2/or/cvsroot/tor/src/or
In directory moria:/home/arma/work/onion/cvs/tor/src/or

Modified Files:
	circuitbuild.c circuitlist.c command.c cpuworker.c or.h 
Log Message:
make circ->onionskin a pointer, not a static array. moria2 was using
125000 circuit_t's after it had been up for a few weeks, which translates
to 20+ megs of wasted space.


Index: circuitbuild.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/circuitbuild.c,v
retrieving revision 1.156
retrieving revision 1.157
diff -u -d -r1.156 -r1.157
--- circuitbuild.c	25 Oct 2005 18:01:01 -0000	1.156
+++ circuitbuild.c	29 Oct 2005 19:13:48 -0000	1.157
@@ -414,10 +414,12 @@
         }
       } else {
         /* pull the create cell out of circ->onionskin, and send it */
+        tor_assert(circ->onionskin);
         if (circuit_deliver_create_cell(circ,CELL_CREATE,circ->onionskin) < 0) {
           circuit_mark_for_close(circ);
           continue;
         }
+        tor_free(circ->onionskin);
       }
     }
   }
@@ -522,7 +524,7 @@
         return -1;
       }
     } else {
-      /* We are not an OR, and we building the first hop of a circuit to
+      /* We are not an OR, and we're building the first hop of a circuit to
        * a new OR: we can be speedy. */
       cell_type = CELL_CREATE_FAST;
       memset(payload, 0, sizeof(payload));
@@ -643,6 +645,7 @@
     info(LD_CIRC|LD_OR,"Next router (%s:%d) not connected. Connecting.",
            tmpbuf, circ->n_port);
 
+    circ->onionskin = tor_malloc(ONIONSKIN_CHALLENGE_LEN);
     memcpy(circ->onionskin, onionskin, ONIONSKIN_CHALLENGE_LEN);
     circ->state = CIRCUIT_STATE_OR_WAIT;
 
@@ -1197,6 +1200,8 @@
       smartlist_subtract(sl,excludedexits);
       if (options->StrictExitNodes || smartlist_overlap(sl,preferredexits))
         smartlist_intersect(sl,preferredexits);
+        /* XXX sometimes the above results in null, when the requested
+         * exit node is down. we should pick it anyway. */
       router = routerlist_sl_choose_by_bandwidth(sl);
       if (router)
         break;

Index: circuitlist.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/circuitlist.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- circuitlist.c	25 Oct 2005 18:01:01 -0000	1.67
+++ circuitlist.c	29 Oct 2005 19:13:48 -0000	1.68
@@ -250,6 +250,7 @@
       circuit_free_cpath_node(circ->build_state->pending_final_cpath);
   }
   tor_free(circ->build_state);
+  tor_free(circ->onionskin);
   circuit_free_cpath(circ->cpath);
   if (circ->rend_splice) {
     circ->rend_splice->rend_splice = NULL;
@@ -792,6 +793,7 @@
   tor_assert(c->deliver_window >= 0);
   tor_assert(c->package_window >= 0);
   if (c->state == CIRCUIT_STATE_OPEN) {
+    tor_assert(!c->onionskin);
     if (c->cpath) {
       tor_assert(CIRCUIT_IS_ORIGIN(c));
       tor_assert(!c->n_crypto);

Index: command.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/command.c,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- command.c	25 Oct 2005 18:01:01 -0000	1.98
+++ command.c	29 Oct 2005 19:13:48 -0000	1.99
@@ -200,6 +200,7 @@
   circ->purpose = CIRCUIT_PURPOSE_OR;
   circ->state = CIRCUIT_STATE_ONIONSKIN_PENDING;
   if (cell->command == CELL_CREATE) {
+    circ->onionskin = tor_malloc(ONIONSKIN_CHALLENGE_LEN);
     memcpy(circ->onionskin, cell->payload, ONIONSKIN_CHALLENGE_LEN);
 
     /* hand it off to the cpuworkers, and then return */

Index: cpuworker.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/cpuworker.c,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -d -r1.91 -r1.92
--- cpuworker.c	25 Oct 2005 19:01:48 -0000	1.91
+++ cpuworker.c	29 Oct 2005 19:13:48 -0000	1.92
@@ -428,6 +428,7 @@
 
   if (question_type == CPUWORKER_TASK_ONION) {
     circ = task;
+    tor_assert(circ->onionskin);
 
     if (num_cpuworkers_busy == num_cpuworkers) {
       debug(LD_OR,"No idle cpuworkers. Queuing.");
@@ -453,6 +454,7 @@
     connection_write_to_buf((char*)&question_type, 1, cpuworker);
     connection_write_to_buf(tag, sizeof(tag), cpuworker);
     connection_write_to_buf(circ->onionskin, ONIONSKIN_CHALLENGE_LEN, cpuworker);
+    tor_free(circ->onionskin);
   }
   return 0;
 }

Index: or.h
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.728
retrieving revision 1.729
diff -u -d -r1.728 -r1.729
--- or.h	29 Oct 2005 18:19:37 -0000	1.728
+++ or.h	29 Oct 2005 19:13:48 -0000	1.729
@@ -1068,8 +1068,11 @@
    */
   crypt_path_t *cpath;
 
-  /** For storage while passing to cpuworker, or while n_conn is pending. */
-  char onionskin[ONIONSKIN_CHALLENGE_LEN];
+  /** For storage while passing to cpuworker (state
+    * CIRCUIT_STATE_ONIONSKIN_PENDING), or while n_conn is pending
+    * (state CIRCUIT_STATE_OR_WAIT). When defined, it is always
+    * length ONIONSKIN_CHALLENGE_LEN. */
+  char *onionskin;
 
   char handshake_digest[DIGEST_LEN]; /**< Stores KH for intermediate hops. */
 



More information about the tor-commits mailing list