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

[or-cvs] fix paul gardner"s assert bug.



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

Modified Files:
	circuituse.c 
Log Message:
fix paul gardner's assert bug.
sometimes circuit_get_open_circ_or_launch() can return 0 but not
return a circuit, e.g. because too many circuits have failed recently
so the new one didn't launch. we need to tolerate that.


Index: circuituse.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuituse.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- circuituse.c	11 Oct 2004 01:17:42 -0000	1.15
+++ circuituse.c	11 Oct 2004 22:19:12 -0000	1.16
@@ -775,6 +775,7 @@
       return retval;
 
     /* We have found a suitable circuit for our conn. Hurray. */
+    tor_assert(circ);
 
     log_fn(LOG_DEBUG,"Attaching apconn to general circ %d (stream %d sec old).",
            circ->n_circ_id, conn_age);
@@ -801,9 +802,9 @@
 
     retval = circuit_get_open_circ_or_launch(conn, CIRCUIT_PURPOSE_C_REND_JOINED, &rendcirc);
     if(retval < 0) return -1; /* failed */
-    tor_assert(rendcirc);
 
     if(retval > 0) {
+      tor_assert(rendcirc);
       /* one is already established, attach */
       log_fn(LOG_INFO,"rend joined circ %d already here. attaching. (stream %d sec old)",
              rendcirc->n_circ_id, conn_age);
@@ -813,7 +814,7 @@
       return 1;
     }
 
-    if(rendcirc->purpose == CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED) {
+    if(rendcirc && rendcirc->purpose == CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED) {
       log_fn(LOG_INFO,"pending-join circ %d already here, with intro ack. Stalling. (stream %d sec old)", rendcirc->n_circ_id, conn_age);
       return 0;
     }
@@ -821,21 +822,20 @@
     /* it's on its way. find an intro circ. */
     retval = circuit_get_open_circ_or_launch(conn, CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT, &introcirc);
     if(retval < 0) return -1; /* failed */
-    tor_assert(introcirc);
 
     if(retval > 0) {
       /* one has already sent the intro. keep waiting. */
+      tor_assert(introcirc);
       log_fn(LOG_INFO,"Intro circ %d present and awaiting ack (rend %d). Stalling. (stream %d sec old)",
-             introcirc->n_circ_id, rendcirc->n_circ_id, conn_age);
+             introcirc->n_circ_id, rendcirc ? rendcirc->n_circ_id : 0, conn_age);
       return 0;
     }
 
-    /* now both rendcirc and introcirc are defined, and neither is finished */
+    /* now rendcirc and introcirc are each either undefined or not finished */
 
-    if(rendcirc->purpose == CIRCUIT_PURPOSE_C_REND_READY) {
+    if(rendcirc && introcirc && rendcirc->purpose == CIRCUIT_PURPOSE_C_REND_READY) {
       log_fn(LOG_INFO,"ready rend circ %d already here (no intro-ack yet on intro %d). (stream %d sec old)",
              rendcirc->n_circ_id, introcirc->n_circ_id, conn_age);
-      /* look around for any new intro circs that should introduce */
 
       tor_assert(introcirc->purpose == CIRCUIT_PURPOSE_C_INTRODUCING);
       if(introcirc->state == CIRCUIT_STATE_OPEN) {
@@ -853,7 +853,9 @@
       }
     }
 
-    log_fn(LOG_INFO,"Intro (%d) and rend (%d) circs are not both ready. Stalling conn. (%d sec old)", introcirc->n_circ_id, rendcirc->n_circ_id, conn_age);
+    log_fn(LOG_INFO,"Intro (%d) and rend (%d) circs are not both ready. Stalling conn. (%d sec old)",
+                     introcirc ? introcirc->n_circ_id : 0,
+                     rendcirc ? rendcirc->n_circ_id : 0, conn_age);
     return 0;
   }
 }