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

[or-cvs] use tor_assert



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

Modified Files:
	buffers.c circuit.c config.c connection.c connection_edge.c 
	connection_or.c cpuworker.c directory.c dns.c main.c onion.c 
	rendclient.c rendcommon.c rendservice.c rephist.c router.c 
	routerlist.c test.c 
Log Message:
use tor_assert
remove obsolete BUF_OK macro


Index: buffers.c
===================================================================
RCS file: /home/or/cvsroot/src/or/buffers.c,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -d -r1.78 -r1.79
--- buffers.c	8 Apr 2004 02:19:35 -0000	1.78
+++ buffers.c	25 Apr 2004 20:37:37 -0000	1.79
@@ -22,13 +22,12 @@
  * out smaller than this, but they will never autoshrink to less
  * than this size. */
 #define MIN_BUF_SHRINK_SIZE (16*1024)
-#define BUF_OK(b) ((b) && (b)->mem && (b)->datalen <= (b)->len)
 
 /* Change a buffer's capacity.  Must only be called when */
 static INLINE void buf_resize(buf_t *buf, size_t new_capacity)
 {
-  assert(buf->datalen <= new_capacity);
-  assert(new_capacity);
+  tor_assert(buf->datalen <= new_capacity);
+  tor_assert(new_capacity);
   buf->mem = tor_realloc(buf->mem, new_capacity);
   buf->len = new_capacity;
 }
@@ -83,7 +82,7 @@
 /* Remove the first 'n' bytes from buf.
  */
 static INLINE void buf_remove_from_front(buf_t *buf, size_t n) {
-  assert(buf->datalen >= n);
+  tor_assert(buf->datalen >= n);
   buf->datalen -= n;
   memmove(buf->mem, buf->mem+n, buf->datalen);
   buf_shrink_if_underfull(buf);
@@ -99,7 +98,7 @@
   const char *location;
   const char *last_possible = buf + buf_len - str_len;
 
-  assert(str && str_len > 0 && buf);
+  tor_assert(str && str_len > 0 && buf);
 
   if(buf_len < str_len)
     return -1;
@@ -126,7 +125,7 @@
   buf->datalen = 0;
 //  memset(buf->mem,0,size);
 
-  assert(BUF_OK(buf));
+  assert_buf_ok(buf);
   return buf;
 }
 
@@ -176,7 +175,8 @@
   int e;
 #endif
 
-  assert(BUF_OK(buf) && reached_eof && (s>=0));
+  assert_buf_ok(buf);
+  tor_assert(reached_eof && (s>=0));
 
   if (buf_ensure_capacity(buf,buf->datalen+at_most))
     return -1;
@@ -214,7 +214,8 @@
 
 int read_to_buf_tls(tor_tls *tls, int at_most, buf_t *buf) {
   int r;
-  assert(tls && BUF_OK(buf));
+  tor_assert(tls);
+  assert_buf_ok(buf);
 
   if (buf_ensure_capacity(buf, at_most+buf->datalen))
     return -1;
@@ -245,7 +246,8 @@
   int e;
 #endif
 
-  assert(BUF_OK(buf) && buf_flushlen && (s>=0) && (*buf_flushlen <= buf->datalen));
+  assert_buf_ok(buf);
+  tor_assert(buf_flushlen && (s>=0) && (*buf_flushlen <= buf->datalen));
 
   if(*buf_flushlen == 0) /* nothing to flush */
     return 0;
@@ -253,7 +255,7 @@
   write_result = send(s, buf->mem, *buf_flushlen, 0);
   if (write_result < 0) {
     if(!ERRNO_EAGAIN(errno)) { /* it's a real error */
-      assert(errno != EPIPE); /* get a stack trace to find epipe bugs */
+      tor_assert(errno != EPIPE); /* get a stack trace to find epipe bugs */
       return -1;
     }
 #ifdef MS_WINDOWS
@@ -277,7 +279,8 @@
 int flush_buf_tls(tor_tls *tls, buf_t *buf, int *buf_flushlen)
 {
   int r;
-  assert(tls && BUF_OK(buf) && buf_flushlen);
+  assert_buf_ok(buf);
+  tor_assert(tls && buf_flushlen);
 
   /* we want to let tls write even if flushlen is zero, because it might
    * have a partial record pending */
@@ -298,7 +301,8 @@
    * return total number of bytes on the buf
    */
 
-  assert(string && BUF_OK(buf));
+  tor_assert(string);
+  assert_buf_ok(buf);
 
   if (buf_ensure_capacity(buf, buf->datalen+string_len)) {
     log_fn(LOG_WARN, "buflen too small, can't hold %d bytes.", (int)buf->datalen+string_len);
@@ -318,8 +322,9 @@
    *
    * Return the number of bytes still on the buffer. */
 
-  assert(string && BUF_OK(buf));
-  assert(string_len <= buf->datalen); /* make sure we don't ask for too much */
+  tor_assert(string);
+  tor_assert(string_len <= buf->datalen); /* make sure we don't ask for too much */
+  assert_buf_ok(buf);
 
   memcpy(string,buf->mem,string_len);
   buf_remove_from_front(buf, string_len);
@@ -347,7 +352,7 @@
   int i;
   int headerlen, bodylen, contentlen;
 
-  assert(BUF_OK(buf));
+  assert_buf_ok(buf);
 
   headers = buf->mem;
   i = find_on_inbuf("\r\n\r\n", 4, buf);
@@ -390,7 +395,7 @@
     (*headers_out)[headerlen] = 0; /* null terminate it */
   }
   if(body_out) {
-    assert(body_used);
+    tor_assert(body_used);
     *body_used = bodylen;
     *body_out = tor_malloc(bodylen+1);
     memcpy(*body_out,buf->mem+headerlen,bodylen);
@@ -431,7 +436,7 @@
 
       if(req->socks_version != 5) { /* we need to negotiate a method */
         unsigned char nummethods = (unsigned char)*(buf->mem+1);
-        assert(!req->socks_version);
+        tor_assert(!req->socks_version);
         if(buf->datalen < 2+nummethods)
           return 0;
         if(!nummethods || !memchr(buf->mem+2, 0, nummethods)) {
@@ -494,7 +499,7 @@
           log_fn(LOG_WARN,"socks5: unsupported address type %d. Rejecting.",*(buf->mem+3));
           return -1;
       }
-      assert(0);
+      tor_assert(0);
     case 4: /* socks4 */
       /* http://archive.socks.permeo.com/protocol/socks4.protocol */
       /* http://archive.socks.permeo.com/protocol/socks4a.protocol */
@@ -587,14 +592,16 @@
   }
 }
 
+
 void assert_buf_ok(buf_t *buf)
 {
-  assert(buf);
-  assert(buf->magic == BUFFER_MAGIC);
-  assert(buf->mem);
-  assert(buf->datalen <= buf->len);
+  tor_assert(buf);
+  tor_assert(buf->magic == BUFFER_MAGIC);
+  tor_assert(buf->mem);
+  tor_assert(buf->datalen <= buf->len);
 }
 
+
 /*
   Local Variables:
   mode:c

Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.218
retrieving revision 1.219
diff -u -d -r1.218 -r1.219
--- circuit.c	25 Apr 2004 19:04:11 -0000	1.218
+++ circuit.c	25 Apr 2004 20:37:37 -0000	1.219
@@ -51,7 +51,7 @@
 void circuit_remove(circuit_t *circ) {
   circuit_t *tmpcirc;
 
-  assert(circ && global_circuitlist);
+  tor_assert(circ && global_circuitlist);
 
   if(global_circuitlist == circ) {
     global_circuitlist = global_circuitlist->next;
@@ -120,8 +120,8 @@
 }
 
 void circuit_free(circuit_t *circ) {
-  assert(circ);
-  assert(circ->magic == CIRCUIT_MAGIC);
+  tor_assert(circ);
+  tor_assert(circ->magic == CIRCUIT_MAGIC);
   if (circ->n_crypto)
     crypto_free_cipher_env(circ->n_crypto);
   if (circ->p_crypto)
@@ -182,7 +182,7 @@
   int attempts=0;
   uint16_t high_bit;
 
-  assert(conn && conn->type == CONN_TYPE_OR);
+  tor_assert(conn && conn->type == CONN_TYPE_OR);
   high_bit = (circ_id_type == CIRC_ID_TYPE_HIGHER) ? 1<<15 : 0;
   do {
     /* Sequentially iterate over test_circ_id=1...1<<15-1 until we find a
@@ -377,11 +377,11 @@
   circuit_t *circ, *best=NULL;
   time_t now = time(NULL);
 
-  assert(conn);
+  tor_assert(conn);
 
-  assert(purpose == CIRCUIT_PURPOSE_C_GENERAL ||
-         purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT ||
-         purpose == CIRCUIT_PURPOSE_C_REND_JOINED);
+  tor_assert(purpose == CIRCUIT_PURPOSE_C_GENERAL ||
+             purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT ||
+             purpose == CIRCUIT_PURPOSE_C_REND_JOINED);
 
   for (circ=global_circuitlist;circ;circ = circ->next) {
     if (!circuit_is_acceptable(circ,conn,must_be_open,purpose,now))
@@ -705,8 +705,8 @@
   crypt_path_t *layer_hint=NULL;
   char recognized=0;
 
-  assert(cell && circ);
-  assert(cell_direction == CELL_DIRECTION_OUT || cell_direction == CELL_DIRECTION_IN);
+  tor_assert(cell && circ);
+  tor_assert(cell_direction == CELL_DIRECTION_OUT || cell_direction == CELL_DIRECTION_IN);
   if (circ->marked_for_close)
     return 0;
 
@@ -747,8 +747,8 @@
 
   if(!conn) {
     if (circ->rend_splice && cell_direction == CELL_DIRECTION_OUT) {
-      assert(circ->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED);
-      assert(circ->rend_splice->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED);
+      tor_assert(circ->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED);
+      tor_assert(circ->rend_splice->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED);
       cell->circ_id = circ->rend_splice->p_circ_id;
       if (circuit_receive_relay_cell(cell, circ->rend_splice, CELL_DIRECTION_IN)<0) {
         log_fn(LOG_WARN, "Error relaying cell across rendezvous; closing circuits");
@@ -773,20 +773,20 @@
   crypt_path_t *thishop;
   relay_header_t rh;
 
-  assert(circ && cell && recognized);
-  assert(cell_direction == CELL_DIRECTION_IN || cell_direction == CELL_DIRECTION_OUT);
+  tor_assert(circ && cell && recognized);
+  tor_assert(cell_direction == CELL_DIRECTION_IN || cell_direction == CELL_DIRECTION_OUT);
 
   if(cell_direction == CELL_DIRECTION_IN) {
     if(CIRCUIT_IS_ORIGIN(circ)) { /* we're at the beginning of the circuit.
                                      We'll want to do layered crypts. */
-      assert(circ->cpath);
+      tor_assert(circ->cpath);
       thishop = circ->cpath;
       if(thishop->state != CPATH_STATE_OPEN) {
         log_fn(LOG_WARN,"Relay cell before first created cell? Closing.");
         return -1;
       }
       do { /* Remember: cpath is in forward order, that is, first hop first. */
-        assert(thishop);
+        tor_assert(thishop);
 
         if(relay_crypt_one_payload(thishop->b_crypto, cell->payload, 0) < 0)
           return -1;
@@ -852,7 +852,7 @@
     thishop = layer_hint;
     /* moving from farthest to nearest hop */
     do {
-      assert(thishop);
+      tor_assert(thishop);
 
       log_fn(LOG_DEBUG,"crypting a layer of the relay cell.");
       if(relay_crypt_one_payload(thishop->f_crypto, cell->payload, 1) < 0) {
@@ -1002,7 +1002,7 @@
     circuit_rep_hist_note_result(circ);
   }
   if (circ->purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT) {
-    assert(circ->state == CIRCUIT_STATE_OPEN);
+    tor_assert(circ->state == CIRCUIT_STATE_OPEN);
     /* treat this like getting a nack from it */
     log_fn(LOG_INFO,"Failed intro circ %s to %s (awaiting ack). Removing from descriptor.",
            circ->rend_query, circ->build_state->chosen_exit);
@@ -1033,8 +1033,7 @@
 void circuit_detach_stream(circuit_t *circ, connection_t *conn) {
   connection_t *prevconn;
 
-  assert(circ);
-  assert(conn);
+  tor_assert(circ && conn);
 
   if(conn == circ->p_streams) {
     circ->p_streams = conn->next_stream;
@@ -1055,7 +1054,7 @@
     return;
   }
   log_fn(LOG_ERR,"edge conn not in circuit's list?");
-  assert(0); /* should never get here */
+  tor_assert(0); /* should never get here */
 }
 
 void circuit_about_to_close_connection(connection_t *conn) {
@@ -1104,7 +1103,7 @@
   struct crypt_path_t *hop;
   char *states[] = {"closed", "waiting for keys", "open"};
   routerinfo_t *router;
-  assert(CIRCUIT_IS_ORIGIN(circ) && circ->cpath);
+  tor_assert(CIRCUIT_IS_ORIGIN(circ) && circ->cpath);
 
   snprintf(s, sizeof(buf)-1, "circ (length %d, exit %s): ",
           circ->build_state->desired_path_len, circ->build_state->chosen_exit);
@@ -1277,7 +1276,7 @@
       break;
     default:
       log_fn(LOG_ERR,"unhandled purpose %d",circ->purpose);
-      assert(0);
+      tor_assert(0);
   }
 }
 
@@ -1344,7 +1343,7 @@
     default:
       /* Other cases are impossible, since this function is only called with
        * unbuilt circuits. */
-      assert(0);
+      tor_assert(0);
   }
 }
 
@@ -1448,7 +1447,7 @@
     if (circ->marked_for_close)
       continue;
     if(CIRCUIT_IS_ORIGIN(circ) && circ->n_addr == or_conn->addr && circ->n_port == or_conn->port) {
-      assert(circ->state == CIRCUIT_STATE_OR_WAIT);
+      tor_assert(circ->state == CIRCUIT_STATE_OR_WAIT);
       log_fn(LOG_DEBUG,"Found circ %d, sending onion skin.", circ->n_circ_id);
       circ->n_conn = or_conn;
       if(circuit_send_next_onion_skin(circ) < 0) {
@@ -1471,10 +1470,10 @@
   int circ_id_type;
   char payload[2+4+ONIONSKIN_CHALLENGE_LEN];
 
-  assert(circ && CIRCUIT_IS_ORIGIN(circ));
+  tor_assert(circ && CIRCUIT_IS_ORIGIN(circ));
 
   if(circ->cpath->state == CPATH_STATE_CLOSED) {
-    assert(circ->n_conn && circ->n_conn->type == CONN_TYPE_OR);
+    tor_assert(circ->n_conn && circ->n_conn->type == CONN_TYPE_OR);
 
     log_fn(LOG_DEBUG,"First skin; sending create cell.");
     circ_id_type = decide_circ_id_type(options.Nickname,
@@ -1505,8 +1504,8 @@
     circ->state = CIRCUIT_STATE_BUILDING;
     log_fn(LOG_DEBUG,"first skin; finished sending create cell.");
   } else {
-    assert(circ->cpath->state == CPATH_STATE_OPEN);
-    assert(circ->state == CIRCUIT_STATE_BUILDING);
+    tor_assert(circ->cpath->state == CPATH_STATE_OPEN);
+    tor_assert(circ->state == CIRCUIT_STATE_BUILDING);
     log_fn(LOG_DEBUG,"starting to send subsequent skin.");
     r = onion_extend_cpath(&circ->cpath, circ->build_state, &router);
     if (r==1) {
@@ -1622,9 +1621,9 @@
   crypto_digest_env_t *tmp_digest;
   crypto_cipher_env_t *tmp_crypto;
 
-  assert(cpath && key_data);
-  assert(!(cpath->f_crypto || cpath->b_crypto ||
-           cpath->f_digest || cpath->b_digest));
+  tor_assert(cpath && key_data);
+  tor_assert(!(cpath->f_crypto || cpath->b_crypto ||
+             cpath->f_digest || cpath->b_digest));
 
   memset(iv, 0, CIPHER_IV_LEN);
 
@@ -1664,7 +1663,7 @@
   unsigned char keys[CPATH_KEY_MATERIAL_LEN];
   crypt_path_t *hop;
 
-  assert(CIRCUIT_IS_ORIGIN(circ));
+  tor_assert(CIRCUIT_IS_ORIGIN(circ));
   if(circ->cpath->state == CPATH_STATE_AWAITING_KEYS)
     hop = circ->cpath;
   else {
@@ -1676,7 +1675,7 @@
       return -1;
     }
   }
-  assert(hop->state == CPATH_STATE_AWAITING_KEYS);
+  tor_assert(hop->state == CPATH_STATE_AWAITING_KEYS);
 
   if(onion_skin_client_handshake(hop->handshake_state, reply, keys,
                                  DIGEST_LEN*2+CIPHER_KEY_LEN*2) < 0) {
@@ -1703,8 +1702,8 @@
   crypt_path_t *victim;
   connection_t *stream;
 
-  assert(circ && CIRCUIT_IS_ORIGIN(circ));
-  assert(layer);
+  tor_assert(circ && CIRCUIT_IS_ORIGIN(circ));
+  tor_assert(layer);
 
   /* XXX Since we don't ask for truncates currently, getting a truncated
    *     means that a connection broke or an extend failed. For now,
@@ -1738,24 +1737,24 @@
 
 void assert_cpath_layer_ok(const crypt_path_t *cp)
 {
-  assert(cp->f_crypto);
-  assert(cp->b_crypto);
-//  assert(cp->addr); /* these are zero for rendezvous extra-hops */
-//  assert(cp->port);
+  tor_assert(cp->f_crypto);
+  tor_assert(cp->b_crypto);
+//  tor_assert(cp->addr); /* these are zero for rendezvous extra-hops */
+//  tor_assert(cp->port);
   switch(cp->state)
     {
     case CPATH_STATE_CLOSED:
     case CPATH_STATE_OPEN:
-      assert(!cp->handshake_state);
+      tor_assert(!cp->handshake_state);
       break;
     case CPATH_STATE_AWAITING_KEYS:
-      assert(cp->handshake_state);
+      tor_assert(cp->handshake_state);
       break;
     default:
-      assert(0);
+      tor_assert(0);
     }
-  assert(cp->package_window >= 0);
-  assert(cp->deliver_window >= 0);
+  tor_assert(cp->package_window >= 0);
+  tor_assert(cp->deliver_window >= 0);
 }
 
 void assert_cpath_ok(const crypt_path_t *cp)
@@ -1768,10 +1767,10 @@
     /* layers must be in sequence of: "open* awaiting? closed*" */
     if (cp->prev) {
       if (cp->prev->state == CPATH_STATE_OPEN) {
-        assert(cp->state == CPATH_STATE_CLOSED ||
-               cp->state == CPATH_STATE_AWAITING_KEYS);
+        tor_assert(cp->state == CPATH_STATE_CLOSED ||
+                   cp->state == CPATH_STATE_AWAITING_KEYS);
       } else {
-        assert(cp->state == CPATH_STATE_CLOSED);
+        tor_assert(cp->state == CPATH_STATE_CLOSED);
       }
     }
     cp = cp->next;
@@ -1782,35 +1781,35 @@
 {
   connection_t *conn;
 
-  assert(c);
-  assert(c->magic == CIRCUIT_MAGIC);
-  assert(c->purpose >= _CIRCUIT_PURPOSE_MIN &&
-         c->purpose <= _CIRCUIT_PURPOSE_MAX);
+  tor_assert(c);
+  tor_assert(c->magic == CIRCUIT_MAGIC);
+  tor_assert(c->purpose >= _CIRCUIT_PURPOSE_MIN &&
+             c->purpose <= _CIRCUIT_PURPOSE_MAX);
 
   if (c->n_conn)
-    assert(c->n_conn->type == CONN_TYPE_OR);
+    tor_assert(c->n_conn->type == CONN_TYPE_OR);
   if (c->p_conn)
-    assert(c->p_conn->type == CONN_TYPE_OR);
+    tor_assert(c->p_conn->type == CONN_TYPE_OR);
   for (conn = c->p_streams; conn; conn = conn->next_stream)
-    assert(conn->type == CONN_TYPE_AP);
+    tor_assert(conn->type == CONN_TYPE_AP);
   for (conn = c->n_streams; conn; conn = conn->next_stream)
-    assert(conn->type == CONN_TYPE_EXIT);
+    tor_assert(conn->type == CONN_TYPE_EXIT);
 
-  assert(c->deliver_window >= 0);
-  assert(c->package_window >= 0);
+  tor_assert(c->deliver_window >= 0);
+  tor_assert(c->package_window >= 0);
   if (c->state == CIRCUIT_STATE_OPEN) {
     if (c->cpath) {
-      assert(CIRCUIT_IS_ORIGIN(c));
-      assert(!c->n_crypto);
-      assert(!c->p_crypto);
-      assert(!c->n_digest);
-      assert(!c->p_digest);
+      tor_assert(CIRCUIT_IS_ORIGIN(c));
+      tor_assert(!c->n_crypto);
+      tor_assert(!c->p_crypto);
+      tor_assert(!c->n_digest);
+      tor_assert(!c->p_digest);
     } else {
-      assert(!CIRCUIT_IS_ORIGIN(c));
-      assert(c->n_crypto);
-      assert(c->p_crypto);
-      assert(c->n_digest);
-      assert(c->p_digest);
+      tor_assert(!CIRCUIT_IS_ORIGIN(c));
+      tor_assert(c->n_crypto);
+      tor_assert(c->p_crypto);
+      tor_assert(c->n_digest);
+      tor_assert(c->p_digest);
     }
   }
   if (c->cpath) {
@@ -1818,12 +1817,12 @@
   }
   if (c->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED) {
     if (!c->marked_for_close) {
-      assert(c->rend_splice);
-      assert(c->rend_splice->rend_splice == c);
+      tor_assert(c->rend_splice);
+      tor_assert(c->rend_splice->rend_splice == c);
     }
-    assert(c->rend_splice != c);
+    tor_assert(c->rend_splice != c);
   } else {
-    assert(!c->rend_splice);
+    tor_assert(!c->rend_splice);
   }
 }
 

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -d -r1.107 -r1.108
--- config.c	24 Apr 2004 22:17:50 -0000	1.107
+++ config.c	25 Apr 2004 20:37:37 -0000	1.108
@@ -25,7 +25,7 @@
 
 /* open configuration file for reading */
 static FILE *config_open(const unsigned char *filename) {
-  assert(filename);
+  tor_assert(filename);
   if (strspn(filename,CONFIG_LEGAL_FILENAME_CHARACTERS) != strlen(filename)) {
     /* filename has illegal letters */
     return NULL;
@@ -35,7 +35,7 @@
 
 /* close configuration file */
 static int config_close(FILE *f) {
-  assert(f);
+  tor_assert(f);
   return fclose(f);
 }
 
@@ -396,7 +396,7 @@
       log_fn(LOG_WARN,"Could not resolve Address %s. Failing.", options->Address);
       return -1;
     }
-    assert(rent->h_length == 4);
+    tor_assert(rent->h_length == 4);
     memcpy(&in.s_addr, rent->h_addr,rent->h_length);
   }
   if(!explicit_ip && is_internal_IP(htonl(in.s_addr))) {

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.198
retrieving revision 1.199
diff -u -d -r1.198 -r1.199
--- connection.c	25 Apr 2004 19:04:11 -0000	1.198
+++ connection.c	25 Apr 2004 20:37:37 -0000	1.199
@@ -99,8 +99,8 @@
 }
 
 void connection_free(connection_t *conn) {
-  assert(conn);
-  assert(conn->magic == CONNECTION_MAGIC);
+  tor_assert(conn);
+  tor_assert(conn->magic == CONNECTION_MAGIC);
 
   if(!connection_is_listener(conn)) {
     buf_free(conn->inbuf);
@@ -245,7 +245,7 @@
      * for 15 seconds...
      */
     if (conn->hold_open_until_flushed) {
-      assert(conn->marked_for_close);
+      tor_assert(conn->marked_for_close);
       if (now - conn->timestamp_lastwritten >= 15) {
         log_fn(LOG_WARN,"Giving up on marked_for_close conn that's been flushing for 15s (fd %d, type %s, state %d).",
                conn->s, CONN_TYPE_TO_STRING(conn->type), conn->state);
@@ -422,9 +422,9 @@
 
 static void listener_close_if_present(int type) {
   connection_t *conn;
-  assert(type == CONN_TYPE_OR_LISTENER ||
-         type == CONN_TYPE_AP_LISTENER ||
-         type == CONN_TYPE_DIR_LISTENER);
+  tor_assert(type == CONN_TYPE_OR_LISTENER ||
+             type == CONN_TYPE_AP_LISTENER ||
+             type == CONN_TYPE_DIR_LISTENER);
   conn = connection_get_by_type(type);
   if (conn) {
     connection_close_immediate(conn);
@@ -495,9 +495,9 @@
 
 /* we just read num_read onto conn. Decrement buckets appropriately. */
 void connection_bucket_decrement(connection_t *conn, int num_read) {
-  global_read_bucket -= num_read; assert(global_read_bucket >= 0);
+  global_read_bucket -= num_read; tor_assert(global_read_bucket >= 0);
   if(connection_speaks_cells(conn) && conn->state == OR_CONN_STATE_OPEN) {
-    conn->receiver_bucket -= num_read; assert(conn->receiver_bucket >= 0);
+    conn->receiver_bucket -= num_read; tor_assert(conn->receiver_bucket >= 0);
   }
   if(global_read_bucket == 0) {
     log_fn(LOG_DEBUG,"global bucket exhausted. Pausing.");
@@ -568,14 +568,14 @@
 }
 
 static int connection_receiver_bucket_should_increase(connection_t *conn) {
-  assert(conn);
+  tor_assert(conn);
 
   if(!connection_speaks_cells(conn))
     return 0; /* edge connections don't use receiver_buckets */
   if(conn->state != OR_CONN_STATE_OPEN)
     return 0; /* only open connections play the rate limiting game */
 
-  assert(conn->bandwidth > 0);
+  tor_assert(conn->bandwidth > 0);
   if(conn->receiver_bucket > 9*conn->bandwidth)
     return 0;
 
@@ -677,7 +677,7 @@
 /* return -1 if you want to break the conn, else return 0 */
 int connection_handle_write(connection_t *conn) {
 
-  assert(!connection_is_listener(conn));
+  tor_assert(!connection_is_listener(conn));
 
   conn->timestamp_lastwritten = time(NULL);
 
@@ -815,7 +815,7 @@
   get_connection_array(&carray,&n);
   for(i=0;i<n;i++) {
     conn = carray[i];
-    assert(conn);
+    tor_assert(conn);
     if(connection_state_is_open(conn) &&
        !crypto_pk_cmp_keys(conn->identity_pkey, router->identity_pkey)) {
       log(LOG_DEBUG,"connection_twin_get_by_addr_port(): Found twin (%s).",conn->address);
@@ -893,7 +893,7 @@
 }
 
 int connection_state_is_open(connection_t *conn) {
-  assert(conn);
+  tor_assert(conn);
 
   if(conn->marked_for_close)
     return 0;
@@ -909,8 +909,8 @@
 int connection_send_destroy(uint16_t circ_id, connection_t *conn) {
   cell_t cell;
 
-  assert(conn);
-  assert(connection_speaks_cells(conn));
+  tor_assert(conn);
+  tor_assert(connection_speaks_cells(conn));
 
   memset(&cell, 0, sizeof(cell_t));
   cell.circ_id = circ_id;
@@ -922,7 +922,7 @@
 
 int connection_process_inbuf(connection_t *conn) {
 
-  assert(conn);
+  tor_assert(conn);
 
   switch(conn->type) {
     case CONN_TYPE_OR:
@@ -944,7 +944,7 @@
 
 int connection_finished_flushing(connection_t *conn) {
 
-  assert(conn);
+  tor_assert(conn);
 
 //  log_fn(LOG_DEBUG,"entered. Socket %u.", conn->s);
 
@@ -968,17 +968,17 @@
 
 void assert_connection_ok(connection_t *conn, time_t now)
 {
-  assert(conn);
-  assert(conn->magic == CONNECTION_MAGIC);
-  assert(conn->type >= _CONN_TYPE_MIN);
-  assert(conn->type <= _CONN_TYPE_MAX);
+  tor_assert(conn);
+  tor_assert(conn->magic == CONNECTION_MAGIC);
+  tor_assert(conn->type >= _CONN_TYPE_MIN);
+  tor_assert(conn->type <= _CONN_TYPE_MAX);
 
   if(conn->outbuf_flushlen > 0) {
-    assert(connection_is_writing(conn) || conn->wants_to_write);
+    tor_assert(connection_is_writing(conn) || conn->wants_to_write);
   }
 
   if(conn->hold_open_until_flushed)
-    assert(conn->marked_for_close);
+    tor_assert(conn->marked_for_close);
 
   /* XXX check: wants_to_read, wants_to_write, s, poll_index,
    * marked_for_close. */
@@ -990,62 +990,62 @@
   }
 
 #if 0 /* computers often go back in time; no way to know */
-  assert(!now || conn->timestamp_lastread <= now);
-  assert(!now || conn->timestamp_lastwritten <= now);
-  assert(conn->timestamp_created <= conn->timestamp_lastread);
-  assert(conn->timestamp_created <= conn->timestamp_lastwritten);
+  tor_assert(!now || conn->timestamp_lastread <= now);
+  tor_assert(!now || conn->timestamp_lastwritten <= now);
+  tor_assert(conn->timestamp_created <= conn->timestamp_lastread);
+  tor_assert(conn->timestamp_created <= conn->timestamp_lastwritten);
 #endif
 
   /* XXX Fix this; no longer so.*/
 #if 0
   if(conn->type != CONN_TYPE_OR && conn->type != CONN_TYPE_DIR)
-    assert(!conn->pkey);
+    tor_assert(!conn->pkey);
   /* pkey is set if we're a dir client, or if we're an OR in state OPEN
    * connected to another OR.
    */
 #endif
 
   if (conn->type != CONN_TYPE_OR) {
-    assert(!conn->tls);
+    tor_assert(!conn->tls);
   } else {
     if(conn->state == OR_CONN_STATE_OPEN) {
-      /* assert(conn->bandwidth > 0); */
+      /* tor_assert(conn->bandwidth > 0); */
       /* the above isn't necessarily true: if we just did a TLS
        * handshake but we didn't recognize the other peer, or it
        * gave a bad cert/etc, then we won't have assigned bandwidth,
        * yet it will be open. -RD
        */
-      assert(conn->receiver_bucket >= 0);
+      tor_assert(conn->receiver_bucket >= 0);
     }
-    assert(conn->addr && conn->port);
-    assert(conn->address);
+    tor_assert(conn->addr && conn->port);
+    tor_assert(conn->address);
     if (conn->state != OR_CONN_STATE_CONNECTING)
-      assert(conn->tls);
+      tor_assert(conn->tls);
   }
 
   if (conn->type != CONN_TYPE_EXIT && conn->type != CONN_TYPE_AP) {
-    assert(!conn->stream_id);
-    assert(!conn->next_stream);
-    assert(!conn->cpath_layer);
-    assert(!conn->package_window);
-    assert(!conn->deliver_window);
-    assert(!conn->done_sending);
-    assert(!conn->done_receiving);
+    tor_assert(!conn->stream_id);
+    tor_assert(!conn->next_stream);
+    tor_assert(!conn->cpath_layer);
+    tor_assert(!conn->package_window);
+    tor_assert(!conn->deliver_window);
+    tor_assert(!conn->done_sending);
+    tor_assert(!conn->done_receiving);
   } else {
     /* XXX unchecked: package window, deliver window. */
   }
   if (conn->type == CONN_TYPE_AP) {
-    assert(conn->socks_request);
+    tor_assert(conn->socks_request);
     if (conn->state == AP_CONN_STATE_OPEN) {
-      assert(conn->socks_request->has_finished);
-      assert(conn->cpath_layer);
+      tor_assert(conn->socks_request->has_finished);
+      tor_assert(conn->cpath_layer);
       assert_cpath_layer_ok(conn->cpath_layer);
     }
   } else {
-    assert(!conn->socks_request);
+    tor_assert(!conn->socks_request);
   }
   if(conn->type != CONN_TYPE_DIR) {
-    assert(!conn->purpose); /* only used for dir types currently */
+    tor_assert(!conn->purpose); /* only used for dir types currently */
   }
 
   switch(conn->type)
@@ -1053,37 +1053,37 @@
     case CONN_TYPE_OR_LISTENER:
     case CONN_TYPE_AP_LISTENER:
     case CONN_TYPE_DIR_LISTENER:
-      assert(conn->state == LISTENER_STATE_READY);
+      tor_assert(conn->state == LISTENER_STATE_READY);
       break;
     case CONN_TYPE_OR:
-      assert(conn->state >= _OR_CONN_STATE_MIN &&
-             conn->state <= _OR_CONN_STATE_MAX);
+      tor_assert(conn->state >= _OR_CONN_STATE_MIN &&
+                 conn->state <= _OR_CONN_STATE_MAX);
       break;
     case CONN_TYPE_EXIT:
-      assert(conn->state >= _EXIT_CONN_STATE_MIN &&
-             conn->state <= _EXIT_CONN_STATE_MAX);
+      tor_assert(conn->state >= _EXIT_CONN_STATE_MIN &&
+                 conn->state <= _EXIT_CONN_STATE_MAX);
       break;
     case CONN_TYPE_AP:
-      assert(conn->state >= _AP_CONN_STATE_MIN &&
-             conn->state <= _AP_CONN_STATE_MAX);
-      assert(conn->socks_request);
+      tor_assert(conn->state >= _AP_CONN_STATE_MIN &&
+                 conn->state <= _AP_CONN_STATE_MAX);
+      tor_assert(conn->socks_request);
       break;
     case CONN_TYPE_DIR:
-      assert(conn->state >= _DIR_CONN_STATE_MIN &&
-             conn->state <= _DIR_CONN_STATE_MAX);
-      assert(conn->purpose >= _DIR_PURPOSE_MIN &&
-             conn->purpose <= _DIR_PURPOSE_MAX);
+      tor_assert(conn->state >= _DIR_CONN_STATE_MIN &&
+                 conn->state <= _DIR_CONN_STATE_MAX);
+      tor_assert(conn->purpose >= _DIR_PURPOSE_MIN &&
+                 conn->purpose <= _DIR_PURPOSE_MAX);
       break;
     case CONN_TYPE_DNSWORKER:
-      assert(conn->state == DNSWORKER_STATE_IDLE ||
-             conn->state == DNSWORKER_STATE_BUSY);
+      tor_assert(conn->state == DNSWORKER_STATE_IDLE ||
+                 conn->state == DNSWORKER_STATE_BUSY);
       break;
     case CONN_TYPE_CPUWORKER:
-      assert(conn->state >= _CPUWORKER_STATE_MIN &&
-             conn->state <= _CPUWORKER_STATE_MAX);
+      tor_assert(conn->state >= _CPUWORKER_STATE_MIN &&
+                 conn->state <= _CPUWORKER_STATE_MAX);
       break;
     default:
-      assert(0);
+      tor_assert(0);
   }
 }
 

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_edge.c,v
retrieving revision 1.176
retrieving revision 1.177
diff -u -d -r1.176 -r1.177
--- connection_edge.c	19 Apr 2004 21:25:48 -0000	1.176
+++ connection_edge.c	25 Apr 2004 20:37:37 -0000	1.177
@@ -40,8 +40,8 @@
  */
 int connection_edge_process_inbuf(connection_t *conn) {
 
-  assert(conn);
-  assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT);
+  tor_assert(conn);
+  tor_assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT);
 
   if(conn->inbuf_reached_eof) {
 #ifdef HALF_OPEN
@@ -99,7 +99,7 @@
 }
 
 int connection_edge_destroy(uint16_t circ_id, connection_t *conn) {
-  assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT);
+  tor_assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT);
 
   if(conn->marked_for_close)
     return 0; /* already marked; probably got an 'end' */
@@ -129,7 +129,7 @@
     case END_STREAM_REASON_DONE:           return "closed normally";
     case END_STREAM_REASON_TIMEOUT:        return "gave up (timeout)";
   }
-  assert(0);
+  tor_assert(0);
   return "";
 }
 
@@ -182,7 +182,7 @@
 
   if(!circ) {
     log_fn(LOG_WARN,"no circ. Closing conn.");
-    assert(fromconn);
+    tor_assert(fromconn);
     connection_mark_for_close(fromconn, 0);
     return -1;
   }
@@ -296,7 +296,7 @@
   static int num_seen=0;
   relay_header_t rh;
 
-  assert(cell && circ);
+  tor_assert(cell && circ);
 
   relay_header_unpack(&rh, cell->payload);
 //  log_fn(LOG_DEBUG,"command %d stream %d", rh.command, rh.stream_id);
@@ -473,8 +473,8 @@
   unsigned char connected_payload[4];
   int e, len=sizeof(e);
 
-  assert(conn);
-  assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT);
+  tor_assert(conn);
+  tor_assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT);
 
   switch(conn->state) {
     case EXIT_CONN_STATE_CONNECTING:
@@ -509,7 +509,7 @@
            RELAY_COMMAND_CONNECTED, connected_payload, 4, conn->cpath_layer) < 0)
           return 0; /* circuit is closed, don't continue */
       }
-      assert(conn->package_window > 0);
+      tor_assert(conn->package_window > 0);
       return connection_edge_process_inbuf(conn); /* in case the server has written anything */
     case AP_CONN_STATE_OPEN:
     case EXIT_CONN_STATE_OPEN:
@@ -539,8 +539,8 @@
   char payload[CELL_PAYLOAD_SIZE];
   circuit_t *circ;
 
-  assert(conn);
-  assert(!connection_speaks_cells(conn));
+  tor_assert(conn);
+  tor_assert(!connection_speaks_cells(conn));
 
 repeat_connection_edge_package_raw_inbuf:
 
@@ -582,10 +582,10 @@
     return 0; /* circuit is closed, don't continue */
 
   if(!conn->cpath_layer) { /* non-rendezvous exit */
-    assert(circ->package_window > 0);
+    tor_assert(circ->package_window > 0);
     circ->package_window--;
   } else { /* we're an AP, or an exit on a rendezvous circ */
-    assert(conn->cpath_layer->package_window > 0);
+    tor_assert(conn->cpath_layer->package_window > 0);
     conn->cpath_layer->package_window--;
   }
 
@@ -628,7 +628,7 @@
       }
       continue;
     }
-    assert(circ->purpose == CIRCUIT_PURPOSE_C_GENERAL);
+    tor_assert(circ->purpose == CIRCUIT_PURPOSE_C_GENERAL);
     if(conn->num_retries >= MAX_STREAM_RETRIES) {
       log_fn(LOG_WARN,"Stream is %d seconds late. Giving up.",
              15*conn->num_retries);
@@ -648,7 +648,7 @@
       /* kludge to make us not try this circuit again, yet to allow
        * current streams on it to survive if they can: make it
        * unattractive to use for new streams */
-      assert(circ->timestamp_dirty);
+      tor_assert(circ->timestamp_dirty);
       circ->timestamp_dirty -= options.NewCircuitPeriod;
       /* give our stream another 15 seconds to try */
       conn->timestamp_lastread += 15;
@@ -714,10 +714,10 @@
   socks_request_t *socks;
   int sockshere;
 
-  assert(conn);
-  assert(conn->type == CONN_TYPE_AP);
-  assert(conn->state == AP_CONN_STATE_SOCKS_WAIT);
-  assert(conn->socks_request);
+  tor_assert(conn);
+  tor_assert(conn->type == CONN_TYPE_AP);
+  tor_assert(conn->state == AP_CONN_STATE_SOCKS_WAIT);
+  tor_assert(conn->socks_request);
   socks = conn->socks_request;
 
   log_fn(LOG_DEBUG,"entered.");
@@ -791,9 +791,9 @@
   circuit_t *circ;
   uint32_t addr;
 
-  assert(conn);
-  assert(circp);
-  assert(conn->state == AP_CONN_STATE_CIRCUIT_WAIT);
+  tor_assert(conn);
+  tor_assert(circp);
+  tor_assert(conn->state == AP_CONN_STATE_CIRCUIT_WAIT);
 
   circ = circuit_get_best(conn, 1, desired_circuit_purpose);
 
@@ -862,8 +862,8 @@
   /* assert_connection_ok(conn, time(NULL)); */
   circ->p_streams = apconn;
 
-  assert(CIRCUIT_IS_ORIGIN(circ) && circ->cpath && circ->cpath->prev);
-  assert(circ->cpath->prev->state == CPATH_STATE_OPEN);
+  tor_assert(CIRCUIT_IS_ORIGIN(circ) && circ->cpath && circ->cpath->prev);
+  tor_assert(circ->cpath->prev->state == CPATH_STATE_OPEN);
   apconn->cpath_layer = circ->cpath->prev;
 }
 
@@ -878,10 +878,10 @@
   int retval;
   int conn_age;
 
-  assert(conn);
-  assert(conn->type == CONN_TYPE_AP);
-  assert(conn->state == AP_CONN_STATE_CIRCUIT_WAIT);
-  assert(conn->socks_request);
+  tor_assert(conn);
+  tor_assert(conn->type == CONN_TYPE_AP);
+  tor_assert(conn->state == AP_CONN_STATE_CIRCUIT_WAIT);
+  tor_assert(conn->socks_request);
 
   conn_age = time(NULL) - conn->timestamp_created;
   if(conn_age > 60) {
@@ -916,13 +916,13 @@
   } else { /* we're a rendezvous conn */
     circuit_t *rendcirc=NULL, *introcirc=NULL;
 
-    assert(!conn->cpath_layer);
+    tor_assert(!conn->cpath_layer);
 
     /* start by finding a rendezvous circuit for us */
 
     retval = circuit_get_open_circ_or_launch(conn, CIRCUIT_PURPOSE_C_REND_JOINED, &rendcirc);
     if(retval < 0) return -1; /* failed */
-    assert(rendcirc);
+    tor_assert(rendcirc);
 
     if(retval > 0) {
       /* one is already established, attach */
@@ -942,7 +942,7 @@
     /* 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 */
-    assert(introcirc);
+    tor_assert(introcirc);
 
     if(retval > 0) {
       /* one has already sent the intro. keep waiting. */
@@ -958,7 +958,7 @@
              rendcirc->n_circ_id, introcirc->n_circ_id, conn_age);
       /* look around for any new intro circs that should introduce */
 
-      assert(introcirc->purpose == CIRCUIT_PURPOSE_C_INTRODUCING);
+      tor_assert(introcirc->purpose == CIRCUIT_PURPOSE_C_INTRODUCING);
       if(introcirc->state == CIRCUIT_STATE_OPEN) {
         log_fn(LOG_INFO,"found open intro circ %d (rend %d); sending introduction. (stream %d sec old)",
                introcirc->n_circ_id, rendcirc->n_circ_id, conn_age);
@@ -1010,9 +1010,9 @@
   struct in_addr in;
   const char *string_addr;
 
-  assert(ap_conn->type == CONN_TYPE_AP);
-  assert(ap_conn->state == AP_CONN_STATE_CIRCUIT_WAIT);
-  assert(ap_conn->socks_request);
+  tor_assert(ap_conn->type == CONN_TYPE_AP);
+  tor_assert(ap_conn->state == AP_CONN_STATE_CIRCUIT_WAIT);
+  tor_assert(ap_conn->socks_request);
 
   ap_conn->stream_id = get_unique_stream_id_by_circ(circ);
   if (ap_conn->stream_id==0) {
@@ -1111,7 +1111,7 @@
     connection_write_to_buf(reply, replylen, conn);
     return;
   }
-  assert(conn->socks_request);
+  tor_assert(conn->socks_request);
   if(conn->socks_request->socks_version == 4) {
     memset(buf,0,SOCKS4_NETWORK_LEN);
 #define SOCKS4_GRANTED          90
@@ -1190,7 +1190,7 @@
     n_stream->address = tor_strdup("(rendezvous)");
     n_stream->state = EXIT_CONN_STATE_CONNECTING;
     strcpy(n_stream->rend_query, circ->rend_query);
-    assert(n_stream->rend_query[0]);
+    tor_assert(n_stream->rend_query[0]);
     assert_circuit_ok(circ);
     if(rend_service_set_connection_addr_port(n_stream, circ) < 0) {
       log_fn(LOG_INFO,"Didn't find rendezvous service (port %d)",n_stream->port);
@@ -1271,7 +1271,7 @@
 }
 
 int connection_edge_is_rendezvous_stream(connection_t *conn) {
-  assert(conn);
+  tor_assert(conn);
   if(*conn->rend_query) /* XXX */
     return 1;
   return 0;
@@ -1281,9 +1281,9 @@
 {
   uint32_t addr;
 
-  assert(conn);
-  assert(conn->type == CONN_TYPE_AP);
-  assert(conn->socks_request);
+  tor_assert(conn);
+  tor_assert(conn->type == CONN_TYPE_AP);
+  tor_assert(conn->socks_request);
 
   log_fn(LOG_DEBUG,"considering nickname %s, for address %s / port %d:",
          exit->nickname, conn->socks_request->address,
@@ -1334,7 +1334,7 @@
   struct in_addr in;
   time_t now;
 
-  assert(address);
+  tor_assert(address);
 
   if (tor_inet_aton(address, &in)) {
     log_fn(LOG_DEBUG, "Using static address %s (%08lX)", address,
@@ -1374,8 +1374,8 @@
   struct in_addr in;
   time_t now;
 
-  assert(address);
-  assert(val);
+  tor_assert(address);
+  tor_assert(val);
 
   if (tor_inet_aton(address, &in))
     return;

Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_or.c,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- connection_or.c	25 Apr 2004 19:04:11 -0000	1.98
+++ connection_or.c	25 Apr 2004 20:37:37 -0000	1.99
@@ -27,7 +27,7 @@
 
 int connection_or_process_inbuf(connection_t *conn) {
 
-  assert(conn && conn->type == CONN_TYPE_OR);
+  tor_assert(conn && conn->type == CONN_TYPE_OR);
 
   if(conn->inbuf_reached_eof) {
     log_fn(LOG_INFO,"OR connection reached EOF. Closing.");
@@ -43,7 +43,7 @@
 int connection_or_finished_flushing(connection_t *conn) {
   int e, len=sizeof(e);
 
-  assert(conn && conn->type == CONN_TYPE_OR);
+  tor_assert(conn && conn->type == CONN_TYPE_OR);
   assert_connection_ok(conn,0);
 
   switch(conn->state) {
@@ -92,7 +92,7 @@
 connection_t *connection_or_connect(routerinfo_t *router) {
   connection_t *conn;
 
-  assert(router);
+  tor_assert(router);
 
   if(router_is_me(router)) {
     log_fn(LOG_WARN,"You asked me to connect to myself! Failing.");
@@ -245,8 +245,8 @@
   char networkcell[CELL_NETWORK_SIZE];
   char *n = networkcell;
 
-  assert(cell && conn);
-  assert(connection_speaks_cells(conn));
+  tor_assert(cell && conn);
+  tor_assert(connection_speaks_cells(conn));
 
   cell_pack(n, cell);
 

Index: cpuworker.c
===================================================================
RCS file: /home/or/cvsroot/src/or/cpuworker.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- cpuworker.c	25 Apr 2004 04:49:11 -0000	1.30
+++ cpuworker.c	25 Apr 2004 20:37:37 -0000	1.31
@@ -27,7 +27,7 @@
 }
 
 int connection_cpu_finished_flushing(connection_t *conn) {
-  assert(conn && conn->type == CONN_TYPE_CPUWORKER);
+  tor_assert(conn && conn->type == CONN_TYPE_CPUWORKER);
   connection_stop_writing(conn);
   return 0;
 }
@@ -70,7 +70,7 @@
   connection_t *p_conn;
   circuit_t *circ;
 
-  assert(conn && conn->type == CONN_TYPE_CPUWORKER);
+  tor_assert(conn && conn->type == CONN_TYPE_CPUWORKER);
 
   if(conn->inbuf_reached_eof) {
     log_fn(LOG_WARN,"Read eof. Worker died unexpectedly.");
@@ -90,7 +90,7 @@
   if(conn->state == CPUWORKER_STATE_BUSY_ONION) {
     if(buf_datalen(conn->inbuf) < LEN_ONION_RESPONSE) /* entire answer available? */
       return 0; /* not yet */
-    assert(buf_datalen(conn->inbuf) == LEN_ONION_RESPONSE);
+    tor_assert(buf_datalen(conn->inbuf) == LEN_ONION_RESPONSE);
 
     connection_fetch_from_buf(&success,1,conn);
     connection_fetch_from_buf(buf,LEN_ONION_RESPONSE-1,conn);
@@ -112,7 +112,7 @@
       log_fn(LOG_INFO,"processed onion for a circ that's gone. Dropping.");
       goto done_processing;
     }
-    assert(circ->p_conn);
+    tor_assert(circ->p_conn);
     if(onionskin_answer(circ, buf+TAG_LEN, buf+TAG_LEN+ONIONSKIN_REPLY_LEN) < 0) {
       log_fn(LOG_WARN,"onionskin_answer failed. Closing.");
       circuit_mark_for_close(circ);
@@ -120,7 +120,7 @@
     }
     log_fn(LOG_DEBUG,"onionskin_answer succeeded. Yay.");
   } else {
-    assert(0); /* don't ask me to do handshakes yet */
+    tor_assert(0); /* don't ask me to do handshakes yet */
   }
 
 done_processing:
@@ -167,7 +167,7 @@
       log_fn(LOG_INFO,"cpuworker exiting because tor process died.");
       goto end;
     }
-    assert(question_type == CPUWORKER_TASK_ONION);
+    tor_assert(question_type == CPUWORKER_TASK_ONION);
 
     if(read_all(fd, tag, TAG_LEN, 1) != TAG_LEN) {
       log_fn(LOG_ERR,"read tag failed. Exiting.");
@@ -262,7 +262,7 @@
 static void process_pending_task(connection_t *cpuworker) {
   circuit_t *circ;
 
-  assert(cpuworker);
+  tor_assert(cpuworker);
 
   /* for now only process onion tasks */
 
@@ -284,7 +284,7 @@
   circuit_t *circ;
   char tag[TAG_LEN];
 
-  assert(question_type == CPUWORKER_TASK_ONION);
+  tor_assert(question_type == CPUWORKER_TASK_ONION);
 
   if(question_type == CPUWORKER_TASK_ONION) {
     circ = task;
@@ -299,7 +299,7 @@
     if (!cpuworker)
       cpuworker = connection_get_by_type_state(CONN_TYPE_CPUWORKER, CPUWORKER_STATE_IDLE);
 
-    assert(cpuworker);
+    tor_assert(cpuworker);
 
     if(!circ->p_conn) {
       log_fn(LOG_INFO,"circ->p_conn gone. Failing circ.");

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/src/or/directory.c,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -d -r1.91 -r1.92
--- directory.c	17 Apr 2004 20:19:43 -0000	1.91
+++ directory.c	25 Apr 2004 20:37:37 -0000	1.92
@@ -45,7 +45,7 @@
   conn->port = router->dir_port;
   conn->address = tor_strdup(router->address);
   conn->nickname = tor_strdup(router->nickname);
-  assert(router->identity_pkey);
+  tor_assert(router->identity_pkey);
   conn->identity_pkey = crypto_pk_dup_key(router->identity_pkey);
 
   conn->purpose = purpose;
@@ -101,25 +101,25 @@
   char fetchstring[] = "GET / HTTP/1.0\r\n\r\n";
   char tmp[8192];
 
-  assert(conn && conn->type == CONN_TYPE_DIR);
+  tor_assert(conn && conn->type == CONN_TYPE_DIR);
 
   switch(purpose) {
     case DIR_PURPOSE_FETCH_DIR:
-      assert(payload == NULL);
+      tor_assert(payload == NULL);
       connection_write_to_buf(fetchstring, strlen(fetchstring), conn);
       break;
     case DIR_PURPOSE_UPLOAD_DIR:
-      assert(payload);
+      tor_assert(payload);
       snprintf(tmp, sizeof(tmp), "POST / HTTP/1.0\r\nContent-Length: %d\r\n\r\n",
                payload_len);
       connection_write_to_buf(tmp, strlen(tmp), conn);
       connection_write_to_buf(payload, payload_len, conn);
       break;
     case DIR_PURPOSE_FETCH_RENDDESC:
-      assert(payload);
+      tor_assert(payload);
 
       /* this must be true or we wouldn't be doing the lookup */
-      assert(payload_len <= REND_SERVICE_ID_LEN);
+      tor_assert(payload_len <= REND_SERVICE_ID_LEN);
       memcpy(conn->rend_query, payload, payload_len);
       conn->rend_query[payload_len] = 0;
 
@@ -127,7 +127,7 @@
       connection_write_to_buf(tmp, strlen(tmp), conn);
       break;
     case DIR_PURPOSE_UPLOAD_RENDDESC:
-      assert(payload);
+      tor_assert(payload);
       snprintf(tmp, sizeof(tmp),
         "POST %s HTTP/1.0\r\nContent-Length: %d\r\n\r\n", rend_publish_string, payload_len);
       connection_write_to_buf(tmp, strlen(tmp), conn);
@@ -167,7 +167,7 @@
  */
 int parse_http_response(char *headers, int *code, char **message) {
   int n1, n2;
-  assert(headers && code);
+  tor_assert(headers && code);
 
   while(isspace((int)*headers)) headers++; /* tolerate leading whitespace */
 
@@ -190,7 +190,7 @@
   int body_len=0;
   int status_code;
 
-  assert(conn && conn->type == CONN_TYPE_DIR);
+  tor_assert(conn && conn->type == CONN_TYPE_DIR);
 
   if(conn->inbuf_reached_eof) {
     if(conn->state != DIR_CONN_STATE_CLIENT_READING) {
@@ -443,7 +443,7 @@
   int body_len=0;
   int r;
 
-  assert(conn && conn->type == CONN_TYPE_DIR);
+  tor_assert(conn && conn->type == CONN_TYPE_DIR);
 
   switch(fetch_from_buf_http(conn->inbuf,
                              &headers, MAX_HEADERS_SIZE,
@@ -475,7 +475,7 @@
 int connection_dir_finished_flushing(connection_t *conn) {
   int e, len=sizeof(e);
 
-  assert(conn && conn->type == CONN_TYPE_DIR);
+  tor_assert(conn && conn->type == CONN_TYPE_DIR);
 
   switch(conn->state) {
     case DIR_CONN_STATE_CONNECTING:

Index: dns.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dns.c,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- dns.c	11 Apr 2004 17:07:45 -0000	1.77
+++ dns.c	25 Apr 2004 20:37:37 -0000	1.78
@@ -150,7 +150,7 @@
       case CACHE_STATE_FAILED:
         return -1;
     }
-    assert(0);
+    tor_assert(0);
   }
   /* not there, need to add it */
   resolve = tor_malloc_zero(sizeof(struct cached_resolve));
@@ -182,7 +182,7 @@
   connection_t *dnsconn;
   unsigned char len;
 
-  assert(exitconn->state == EXIT_CONN_STATE_RESOLVING);
+  tor_assert(exitconn->state == EXIT_CONN_STATE_RESOLVING);
 
   spawn_enough_dnsworkers(); /* respawn here, to be sure there are enough */
 
@@ -225,7 +225,7 @@
     return;
   }
 
-  assert(resolve->pending_connections);
+  tor_assert(resolve->pending_connections);
   assert_connection_ok(conn,0);
 
   pend = resolve->pending_connections;
@@ -247,7 +247,7 @@
         return; /* more are pending */
       }
     }
-    assert(0); /* not reachable unless onlyconn not in pending list */
+    tor_assert(0); /* not reachable unless onlyconn not in pending list */
   }
 }
 
@@ -259,7 +259,7 @@
     for(pend = resolve->pending_connections;
         pend;
         pend = pend->next) {
-      assert(pend->conn != conn);
+      tor_assert(pend->conn != conn);
     }
   }
 }
@@ -295,7 +295,7 @@
     return;
   }
 
-  assert(resolve->pending_connections);
+  tor_assert(resolve->pending_connections);
 
   /* mark all pending connections to fail */
   log_fn(LOG_DEBUG, "Failing all connections waiting on DNS resolve of '%s'",
@@ -325,7 +325,7 @@
   } else {
     /* FFFF make it a doubly linked list if this becomes too slow */
     for(tmp=oldest_cached_resolve; tmp && tmp->next != resolve; tmp=tmp->next) ;
-    assert(tmp); /* it's got to be in the list, or we screwed up somewhere else */
+    tor_assert(tmp); /* it's got to be in the list, or we screwed up somewhere else */
     tmp->next = resolve->next; /* unlink it */
 
     if(newest_cached_resolve == resolve)
@@ -358,14 +358,14 @@
   if (resolve->state != CACHE_STATE_PENDING) {
     log_fn(LOG_WARN, "Resolved '%s' which was already resolved; ignoring",
            address);
-    assert(resolve->pending_connections == NULL);
+    tor_assert(resolve->pending_connections == NULL);
     return;
   }
   /* Removed this assertion: in fact, we'll sometimes get a double answer
    * to the same question.  This can happen when we ask one worker to resolve
    * X.Y.Z., then we cancel the request, and then we ask another worker to
    * resolve X.Y.Z. */
-  /* assert(resolve->state == CACHE_STATE_PENDING); */
+  /* tor_assert(resolve->state == CACHE_STATE_PENDING); */
 
   resolve->addr = ntohl(addr);
   if(outcome == DNS_RESOLVE_SUCCEEDED)
@@ -402,7 +402,7 @@
 /******************************************************************/
 
 int connection_dns_finished_flushing(connection_t *conn) {
-  assert(conn && conn->type == CONN_TYPE_DNSWORKER);
+  tor_assert(conn && conn->type == CONN_TYPE_DNSWORKER);
   connection_stop_writing(conn);
   return 0;
 }
@@ -411,7 +411,7 @@
   char success;
   uint32_t addr;
 
-  assert(conn && conn->type == CONN_TYPE_DNSWORKER);
+  tor_assert(conn && conn->type == CONN_TYPE_DNSWORKER);
 
   if(conn->inbuf_reached_eof) {
     log_fn(LOG_WARN,"Read eof. Worker died unexpectedly.");
@@ -424,10 +424,10 @@
     return 0;
   }
 
-  assert(conn->state == DNSWORKER_STATE_BUSY);
+  tor_assert(conn->state == DNSWORKER_STATE_BUSY);
   if(buf_datalen(conn->inbuf) < 5) /* entire answer available? */
     return 0; /* not yet */
-  assert(buf_datalen(conn->inbuf) == 5);
+  tor_assert(buf_datalen(conn->inbuf) == 5);
 
   connection_fetch_from_buf(&success,1,conn);
   connection_fetch_from_buf((char *)&addr,sizeof(uint32_t),conn);
@@ -435,8 +435,8 @@
   log_fn(LOG_DEBUG, "DNSWorker (fd %d) returned answer for '%s'",
          conn->s, conn->address);
 
-  assert(success >= DNS_RESOLVE_FAILED_TRANSIENT);
-  assert(success <= DNS_RESOLVE_SUCCEEDED);
+  tor_assert(success >= DNS_RESOLVE_FAILED_TRANSIENT);
+  tor_assert(success <= DNS_RESOLVE_SUCCEEDED);
   dns_found_answer(conn->address, addr, success);
 
   tor_free(conn->address);
@@ -467,7 +467,7 @@
       log_fn(LOG_INFO,"dnsworker exiting because tor process died.");
       spawn_exit();
     }
-    assert(address_len > 0);
+    tor_assert(address_len > 0);
 
     if(read_all(fd, address, address_len, 1) != address_len) {
       log_fn(LOG_ERR,"read hostname failed. Child exiting.");
@@ -486,7 +486,7 @@
       }
       memset(answer+1,0,4);
     } else {
-      assert(rent->h_length == 4); /* break to remind us if we move away from ipv4 */
+      tor_assert(rent->h_length == 4); /* break to remind us if we move away from ipv4 */
       answer[0] = DNS_RESOLVE_SUCCEEDED;
       memcpy(answer+1, rent->h_addr, 4);
       log_fn(LOG_INFO,"Resolved address '%s'.",address);
@@ -551,7 +551,7 @@
      */
     dnsconn = connection_get_by_type_state_lastwritten(CONN_TYPE_DNSWORKER,
                                                        DNSWORKER_STATE_BUSY);
-    assert(dnsconn);
+    tor_assert(dnsconn);
 
     log_fn(LOG_WARN, "%d DNS workers are spawned; all are busy. Killing one.",
            MAX_DNSWORKERS);
@@ -579,7 +579,7 @@
     log_fn(LOG_WARN,"%d of %d dnsworkers are idle. Killing one.",
            num_dnsworkers-num_dnsworkers_needed, num_dnsworkers);
     dnsconn = connection_get_by_type_state(CONN_TYPE_DNSWORKER, DNSWORKER_STATE_IDLE);
-    assert(dnsconn);
+    tor_assert(dnsconn);
     connection_mark_for_close(dnsconn,0);
     num_dnsworkers--;
   }

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.249
retrieving revision 1.250
diff -u -d -r1.249 -r1.250
--- main.c	25 Apr 2004 19:01:49 -0000	1.249
+++ main.c	25 Apr 2004 20:37:37 -0000	1.250
@@ -53,7 +53,7 @@
 ****************************************************************************/
 
 int connection_add(connection_t *conn) {
-  assert(conn);
+  tor_assert(conn);
 
   if(nfds >= options.MaxConn-1) {
     log_fn(LOG_WARN,"failing because nfds is too high.");
@@ -87,8 +87,8 @@
 int connection_remove(connection_t *conn) {
   int current_index;
 
-  assert(conn);
-  assert(nfds>0);
+  tor_assert(conn);
+  tor_assert(nfds>0);
 
   log_fn(LOG_INFO,"removing socket %d (type %s), nfds now %d",
          conn->s, CONN_TYPE_TO_STRING(conn->type), nfds-1);
@@ -122,7 +122,7 @@
 
 void connection_watch_events(connection_t *conn, short events) {
 
-  assert(conn && conn->poll_index < nfds);
+  tor_assert(conn && conn->poll_index < nfds);
 
   poll_array[conn->poll_index].events = events;
 }
@@ -133,7 +133,7 @@
 
 void connection_stop_reading(connection_t *conn) {
 
-  assert(conn && conn->poll_index < nfds);
+  tor_assert(conn && conn->poll_index < nfds);
 
   log(LOG_DEBUG,"connection_stop_reading() called.");
   if(poll_array[conn->poll_index].events & POLLIN)
@@ -142,7 +142,7 @@
 
 void connection_start_reading(connection_t *conn) {
 
-  assert(conn && conn->poll_index < nfds);
+  tor_assert(conn && conn->poll_index < nfds);
 
   poll_array[conn->poll_index].events |= POLLIN;
 }
@@ -153,7 +153,7 @@
 
 void connection_stop_writing(connection_t *conn) {
 
-  assert(conn && conn->poll_index < nfds);
+  tor_assert(conn && conn->poll_index < nfds);
 
   if(poll_array[conn->poll_index].events & POLLOUT)
     poll_array[conn->poll_index].events -= POLLOUT;
@@ -161,7 +161,7 @@
 
 void connection_start_writing(connection_t *conn) {
 
-  assert(conn && conn->poll_index < nfds);
+  tor_assert(conn && conn->poll_index < nfds);
 
   poll_array[conn->poll_index].events |= POLLOUT;
 }

Index: onion.c
===================================================================
RCS file: /home/or/cvsroot/src/or/onion.c,v
retrieving revision 1.157
retrieving revision 1.158
diff -u -d -r1.157 -r1.158
--- onion.c	25 Apr 2004 19:04:11 -0000	1.157
+++ onion.c	25 Apr 2004 20:37:37 -0000	1.158
@@ -17,11 +17,11 @@
 int decide_circ_id_type(char *local_nick, char *remote_nick) {
   int result;
 
-  assert(remote_nick);
+  tor_assert(remote_nick);
   if(!local_nick)
     return CIRC_ID_TYPE_LOWER;
   result = strcmp(local_nick, remote_nick);
-  assert(result);
+  tor_assert(result);
   if(result < 0)
     return CIRC_ID_TYPE_LOWER;
   return CIRC_ID_TYPE_HIGHER;
@@ -45,16 +45,16 @@
   tmp->next = NULL;
 
   if(!ol_tail) {
-    assert(!ol_list);
-    assert(!ol_length);
+    tor_assert(!ol_list);
+    tor_assert(!ol_length);
     ol_list = tmp;
     ol_tail = tmp;
     ol_length++;
     return 0;
   }
 
-  assert(ol_list);
-  assert(!ol_tail->next);
+  tor_assert(ol_list);
+  tor_assert(!ol_tail->next);
 
   if(ol_length >= options.MaxOnionsPending) {
     log_fn(LOG_WARN,"Already have %d onions queued. Closing.", ol_length);
@@ -75,9 +75,9 @@
   if(!ol_list)
     return NULL; /* no onions pending, we're done */
 
-  assert(ol_list->circ);
-  assert(ol_list->circ->p_conn); /* make sure it's still valid */
-  assert(ol_length > 0);
+  tor_assert(ol_list->circ);
+  tor_assert(ol_list->circ->p_conn); /* make sure it's still valid */
+  tor_assert(ol_length > 0);
   circ = ol_list->circ;
   onion_pending_remove(ol_list->circ);
   return circ;
@@ -164,7 +164,7 @@
   int num_acceptable_routers;
   int routelen;
 
-  assert((cw >= 0) && (cw < 1) && routers); /* valid parameters */
+  tor_assert((cw >= 0) && (cw < 1) && routers); /* valid parameters */
 
 #ifdef TOR_PERF
   routelen = 2;
@@ -361,7 +361,7 @@
       return r;
     default:
       log_fn(LOG_WARN,"unhandled purpose %d", purpose);
-      assert(0);
+      tor_assert(0);
   }
   return NULL; /* never reached */
 }
@@ -470,8 +470,8 @@
   int i;
   smartlist_t *sl, *excludednodes;
 
-  assert(head_ptr);
-  assert(router_out);
+  tor_assert(head_ptr);
+  tor_assert(router_out);
 
   if (!*head_ptr) {
     cur_len = 0;
@@ -534,7 +534,7 @@
     remove_twins_from_smartlist(sl,router_get_my_routerinfo());
     for (i = 0, cpath = *head_ptr; i < cur_len; ++i, cpath=cpath->next) {
       r = router_get_by_addr_port(cpath->addr, cpath->port);
-      assert(r);
+      tor_assert(r);
       remove_twins_from_smartlist(sl,r);
     }
     smartlist_subtract(sl,excludednodes);
@@ -600,8 +600,8 @@
 
   dhbytes = crypto_dh_get_bytes(dh);
   pkbytes = crypto_pk_keysize(dest_router_key);
-  assert(dhbytes == 128);
-  assert(pkbytes == 128);
+  tor_assert(dhbytes == 128);
+  tor_assert(pkbytes == 128);
   challenge = tor_malloc_zero(DH_KEY_LEN);
 
   if (crypto_dh_get_public(dh, challenge, dhbytes))
@@ -738,7 +738,7 @@
 {
   int len;
   char *key_material=NULL;
-  assert(crypto_dh_get_bytes(handshake_state) == DH_KEY_LEN);
+  tor_assert(crypto_dh_get_bytes(handshake_state) == DH_KEY_LEN);
 
 #ifdef DEBUG_ONION_SKINS
   printf("Client: server g^y:");

Index: rendclient.c
===================================================================
RCS file: /home/or/cvsroot/src/or/rendclient.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- rendclient.c	18 Apr 2004 08:38:40 -0000	1.44
+++ rendclient.c	25 Apr 2004 20:37:37 -0000	1.45
@@ -8,8 +8,8 @@
 void
 rend_client_introcirc_is_open(circuit_t *circ)
 {
-  assert(circ->purpose == CIRCUIT_PURPOSE_C_INTRODUCING);
-  assert(CIRCUIT_IS_ORIGIN(circ) && circ->cpath);
+  tor_assert(circ->purpose == CIRCUIT_PURPOSE_C_INTRODUCING);
+  tor_assert(CIRCUIT_IS_ORIGIN(circ) && circ->cpath);
 
   log_fn(LOG_INFO,"introcirc is open");
   connection_ap_attach_pending();
@@ -21,7 +21,7 @@
 int
 rend_client_send_establish_rendezvous(circuit_t *circ)
 {
-  assert(circ->purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND);
+  tor_assert(circ->purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND);
   log_fn(LOG_INFO, "Sending an ESTABLISH_RENDEZVOUS cell");
 
   if (crypto_rand(REND_COOKIE_LEN, circ->rend_cookie)<0) {
@@ -52,9 +52,9 @@
   rend_cache_entry_t *entry;
   crypt_path_t *cpath;
 
-  assert(introcirc->purpose == CIRCUIT_PURPOSE_C_INTRODUCING);
-  assert(rendcirc->purpose == CIRCUIT_PURPOSE_C_REND_READY);
-  assert(!rend_cmp_service_ids(introcirc->rend_query, rendcirc->rend_query));
+  tor_assert(introcirc->purpose == CIRCUIT_PURPOSE_C_INTRODUCING);
+  tor_assert(rendcirc->purpose == CIRCUIT_PURPOSE_C_REND_READY);
+  tor_assert(!rend_cmp_service_ids(introcirc->rend_query, rendcirc->rend_query));
 
   if(rend_cache_lookup_entry(introcirc->rend_query, &entry) < 1) {
     log_fn(LOG_WARN,"query '%s' didn't have valid rend desc in cache. Failing.",
@@ -102,7 +102,7 @@
     goto err;
   }
 
-  assert(DIGEST_LEN + r <= RELAY_PAYLOAD_SIZE); /* we overran something */
+  tor_assert(DIGEST_LEN + r <= RELAY_PAYLOAD_SIZE); /* we overran something */
   payload_len = DIGEST_LEN + r;
 
   if (connection_edge_send_command(NULL, introcirc,
@@ -128,8 +128,8 @@
 void
 rend_client_rendcirc_is_open(circuit_t *circ)
 {
-  assert(circ->purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND);
-  assert(CIRCUIT_IS_ORIGIN(circ));
+  tor_assert(circ->purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND);
+  tor_assert(CIRCUIT_IS_ORIGIN(circ));
 
   log_fn(LOG_INFO,"rendcirc is open");
 
@@ -157,7 +157,7 @@
     return -1;
   }
 
-  assert(circ->build_state->chosen_exit);
+  tor_assert(circ->build_state->chosen_exit);
 
   if (request_len == 0) {
     /* It's an ACK; the introduction point relayed our introduction request. */
@@ -185,7 +185,7 @@
       /* There are introduction points left. re-extend the circuit to
        * another intro point and try again. */
       nickname = rend_client_get_random_intro(circ->rend_query);
-      assert(nickname);
+      tor_assert(nickname);
       log_fn(LOG_INFO,"Got nack for %s from %s, extending to %s.", circ->rend_query, circ->build_state->chosen_exit, nickname);
       if (!router_get_by_nickname(nickname)) {
         log_fn(LOG_WARN, "Advertised intro point '%s' for %s is not known. Closing.",
@@ -301,9 +301,9 @@
   }
 
   /* first DH_KEY_LEN bytes are g^y from bob. Finish the dh handshake...*/
-  assert(circ->build_state && circ->build_state->pending_final_cpath);
+  tor_assert(circ->build_state && circ->build_state->pending_final_cpath);
   hop = circ->build_state->pending_final_cpath;
-  assert(hop->handshake_state);
+  tor_assert(hop->handshake_state);
   if (crypto_dh_compute_secret(hop->handshake_state, request, DH_KEY_LEN,
                                keys, DIGEST_LEN+CPATH_KEY_MATERIAL_LEN)<0) {
     log_fn(LOG_WARN, "Couldn't complete DH handshake");

Index: rendcommon.c
===================================================================
RCS file: /home/or/cvsroot/src/or/rendcommon.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- rendcommon.c	12 Apr 2004 23:33:47 -0000	1.27
+++ rendcommon.c	25 Apr 2004 20:37:37 -0000	1.28
@@ -62,7 +62,7 @@
     return -1;
   }
   cp += i;
-  assert(*len_out == (cp-*str_out));
+  tor_assert(*len_out == (cp-*str_out));
   return 0;
 }
 
@@ -127,7 +127,7 @@
 int rend_get_service_id(crypto_pk_env_t *pk, char *out)
 {
   char buf[DIGEST_LEN];
-  assert(pk);
+  tor_assert(pk);
   if (crypto_pk_get_digest(pk, buf) < 0)
     return -1;
   if (base32_encode(out, REND_SERVICE_ID_LEN+1, buf, 10) < 0)
@@ -185,7 +185,7 @@
 
 int rend_cache_lookup_entry(char *query, rend_cache_entry_t **e)
 {
-  assert(rend_cache);
+  tor_assert(rend_cache);
   if (!rend_valid_service_id(query))
     return -1;
   *e = strmap_get_lc(rend_cache, query);
@@ -222,7 +222,7 @@
   rend_service_descriptor_t *parsed;
   char query[REND_SERVICE_ID_LEN+1];
   time_t now;
-  assert(rend_cache);
+  tor_assert(rend_cache);
   parsed = rend_parse_service_descriptor(desc,desc_len);
   if (!parsed) {
     log_fn(LOG_WARN,"Couldn't parse service descriptor");
@@ -307,7 +307,7 @@
       r = rend_client_rendezvous_acked(circ,payload,length);
       break;
     default:
-      assert(0);
+      tor_assert(0);
   }
 }
 

Index: rendservice.c
===================================================================
RCS file: /home/or/cvsroot/src/or/rendservice.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- rendservice.c	16 Apr 2004 14:26:23 -0000	1.57
+++ rendservice.c	25 Apr 2004 20:37:37 -0000	1.58
@@ -214,7 +214,7 @@
       }
       service->intro_prefer_nodes = tor_strdup(line->value);
     } else {
-      assert(!strcasecmp(line->key, "HiddenServiceExcludeNodes"));
+      tor_assert(!strcasecmp(line->key, "HiddenServiceExcludeNodes"));
       if (service->intro_exclude_nodes) {
         log_fn(LOG_WARN, "Got multiple HiddenServiceExcludedNodes lines for a single service");
         return -1;
@@ -435,7 +435,7 @@
            rp_nickname, serviceid);
     return -1;
   }
-  assert(launched->build_state);
+  tor_assert(launched->build_state);
   /* Fill in the circuit's state. */
   memcpy(launched->rend_pk_digest, circuit->rend_pk_digest,
          DIGEST_LEN);
@@ -485,7 +485,7 @@
   }
   oldstate = oldcirc->build_state;
   newstate = newcirc->build_state;
-  assert(newstate && oldstate);
+  tor_assert(newstate && oldstate);
   newstate->failure_count = oldstate->failure_count+1;
   newstate->pending_final_cpath = oldstate->pending_final_cpath;
   oldstate->pending_final_cpath = NULL;
@@ -529,12 +529,12 @@
   char auth[DIGEST_LEN + 9];
   char serviceid[REND_SERVICE_ID_LEN+1];
 
-  assert(circuit->purpose == CIRCUIT_PURPOSE_S_ESTABLISH_INTRO);
-  assert(CIRCUIT_IS_ORIGIN(circuit) && circuit->cpath);
+  tor_assert(circuit->purpose == CIRCUIT_PURPOSE_S_ESTABLISH_INTRO);
+  tor_assert(CIRCUIT_IS_ORIGIN(circuit) && circuit->cpath);
 
   if (base32_encode(serviceid, REND_SERVICE_ID_LEN+1,
                     circuit->rend_pk_digest,10)) {
-    assert(0);
+    tor_assert(0);
   }
 
   service = rend_service_get_by_pk_digest(circuit->rend_pk_digest);
@@ -615,16 +615,16 @@
   char serviceid[REND_SERVICE_ID_LEN+1];
   char hexcookie[9];
 
-  assert(circuit->purpose == CIRCUIT_PURPOSE_S_CONNECT_REND);
-  assert(circuit->cpath);
-  assert(circuit->build_state);
+  tor_assert(circuit->purpose == CIRCUIT_PURPOSE_S_CONNECT_REND);
+  tor_assert(circuit->cpath);
+  tor_assert(circuit->build_state);
   hop = circuit->build_state->pending_final_cpath;
-  assert(hop);
+  tor_assert(hop);
 
   hex_encode(circuit->rend_cookie, 4, hexcookie);
   if (base32_encode(serviceid, REND_SERVICE_ID_LEN+1,
                     circuit->rend_pk_digest,10)) {
-    assert(0);
+    tor_assert(0);
   }
 
   log_fn(LOG_INFO,
@@ -692,7 +692,7 @@
 
   while ((circ = circuit_get_next_by_pk_and_purpose(circ,pk_digest,
                                                   CIRCUIT_PURPOSE_S_INTRO))) {
-    assert(circ->cpath);
+    tor_assert(circ->cpath);
     if (circ->build_state->chosen_exit &&
         !strcasecmp(circ->build_state->chosen_exit, router->nickname)) {
       return circ;
@@ -702,7 +702,7 @@
   circ = NULL;
   while ((circ = circuit_get_next_by_pk_and_purpose(circ,pk_digest,
                                         CIRCUIT_PURPOSE_S_ESTABLISH_INTRO))) {
-    assert(circ->cpath);
+    tor_assert(circ->cpath);
     if (circ->build_state->chosen_exit &&
         !strcasecmp(circ->build_state->chosen_exit, router->nickname)) {
       return circ;
@@ -764,7 +764,7 @@
     smartlist_clear(intro_routers);
     service = smartlist_get(rend_service_list, i);
 
-    assert(service);
+    tor_assert(service);
     changed = 0;
 
     /* Find out which introduction points we have in progress for this service. */
@@ -888,7 +888,7 @@
   rend_service_port_config_t *p;
   char serviceid[REND_SERVICE_ID_LEN+1];
 
-  assert(circ->purpose == CIRCUIT_PURPOSE_S_REND_JOINED);
+  tor_assert(circ->purpose == CIRCUIT_PURPOSE_S_REND_JOINED);
   log_fn(LOG_DEBUG,"beginning to hunt for addr/port");
   if (base32_encode(serviceid, REND_SERVICE_ID_LEN+1,
                     circ->rend_pk_digest,10)) {

Index: rephist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/rephist.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- rephist.c	3 Apr 2004 02:14:20 -0000	1.5
+++ rephist.c	25 Apr 2004 20:37:37 -0000	1.6
@@ -61,9 +61,9 @@
  */
 static void update_or_history(or_history_t *hist, time_t when)
 {
-  assert(hist);
+  tor_assert(hist);
   if (hist->up_since) {
-    assert(!hist->down_since);
+    tor_assert(!hist->down_since);
     hist->uptime += (when - hist->up_since);
     hist->up_since = when;
   } else if (hist->down_since) {

Index: router.c
===================================================================
RCS file: /home/or/cvsroot/src/or/router.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- router.c	25 Apr 2004 19:04:11 -0000	1.31
+++ router.c	25 Apr 2004 20:37:37 -0000	1.32
@@ -22,7 +22,7 @@
 }
 
 crypto_pk_env_t *get_onion_key(void) {
-  assert(onionkey);
+  tor_assert(onionkey);
   return onionkey;
 }
 
@@ -39,7 +39,7 @@
 }
 
 crypto_pk_env_t *get_identity_key(void) {
-  assert(identitykey);
+  tor_assert(identitykey);
   return identitykey;
 }
 
@@ -124,7 +124,7 @@
     }
     return prkey;
   default:
-    assert(0);
+    tor_assert(0);
   }
 
  error:
@@ -146,14 +146,14 @@
 
   /* OP's don't need keys.  Just initialize the TLS context.*/
   if (!options.ORPort) {
-    assert(!options.DirPort);
+    tor_assert(!options.DirPort);
     if (tor_tls_context_new(NULL, 0, NULL, 0)<0) {
       log_fn(LOG_ERR, "Error creating TLS context for OP.");
       return -1;
     }
     return 0;
   }
-  assert(options.DataDirectory);
+  tor_assert(options.DataDirectory);
   if (strlen(options.DataDirectory) > (512-128)) {
     log_fn(LOG_ERR, "DataDirectory is too long.");
     return -1;
@@ -212,7 +212,7 @@
   /* 5. Dump fingerprint to 'fingerprint' */
   sprintf(keydir,"%s/fingerprint", options.DataDirectory);
   log_fn(LOG_INFO,"Dumping fingerprint to %s...",keydir);
-  assert(strlen(options.Nickname) <= MAX_NICKNAME_LEN);
+  tor_assert(strlen(options.Nickname) <= MAX_NICKNAME_LEN);
   strcpy(fingerprint, options.Nickname);
   strcat(fingerprint, " ");
   if (crypto_pk_get_fingerprint(get_identity_key(),
@@ -349,9 +349,9 @@
  */
 int router_compare_to_my_exit_policy(connection_t *conn)
 {
-  assert(desc_routerinfo);
-  assert(conn->addr); /* make sure it's resolved to something. this
-                         way we can't get a 'maybe' below. */
+  tor_assert(desc_routerinfo);
+  tor_assert(conn->addr); /* make sure it's resolved to something. this
+                             way we can't get a 'maybe' below. */
 
   return router_compare_addr_to_exit_policy(conn->addr, conn->port,
                    desc_routerinfo->exit_policy);
@@ -360,7 +360,7 @@
 
 int router_is_me(routerinfo_t *router)
 {
-  assert(router);
+  tor_assert(router);
   return options.Nickname && !strcasecmp(router->nickname, options.Nickname);
 }
 

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- routerlist.c	25 Apr 2004 19:04:11 -0000	1.63
+++ routerlist.c	25 Apr 2004 20:37:37 -0000	1.64
@@ -196,8 +196,8 @@
   char nick[MAX_NICKNAME_LEN+1];
   routerinfo_t *router;
 
-  assert(sl);
-  assert(list);
+  tor_assert(sl);
+  tor_assert(list);
 
   while(isspace((int)*list) || *list==',') list++;
 
@@ -295,7 +295,7 @@
   int i;
   routerinfo_t *router;
 
-  assert(routerlist);
+  tor_assert(routerlist);
 
   for(i=0;i<smartlist_len(routerlist->routers);i++) {
     router = smartlist_get(routerlist->routers, i);
@@ -310,7 +310,7 @@
   int i;
   routerinfo_t *router;
 
-  assert(routerlist);
+  tor_assert(routerlist);
 
   for(i=0;i<smartlist_len(routerlist->routers);i++) {
     router = smartlist_get(routerlist->routers, i);
@@ -395,6 +395,7 @@
 
 /* ------------------------------------------------------------ */
 
+#if 0
 static void dump_onion_keys(int severity)
 {
   int i;
@@ -408,6 +409,7 @@
     log_fn(severity, "%10s: %s", r->nickname, buf);
   }
 }
+#endif
 
 /* Replace the current router list with the one stored in 'routerfile'. */
 int router_set_routerlist_from_file(char *routerfile)
@@ -529,7 +531,7 @@
            router->address, router->nickname);
     return -1;
   }
-  assert(rent->h_length == 4);
+  tor_assert(rent->h_length == 4);
   memcpy(&router->addr, rent->h_addr,rent->h_length);
   router->addr = ntohl(router->addr); /* get it back into host order */
 
@@ -743,7 +745,7 @@
     log_fn(LOG_WARN, "Missing published time on directory.");
     goto err;
   }
-  assert(tok->n_args == 1);
+  tor_assert(tok->n_args == 1);
 
   if (parse_time(tok->args[0], &published_on) < 0) {
      goto err;
@@ -853,7 +855,7 @@
   int i;
   const char *end;
 
-  assert(s && *s);
+  tor_assert(s && *s);
 
   routers = smartlist_create();
 
@@ -1015,7 +1017,7 @@
   if (!(tok = find_first_by_keyword(tokens, K_PUBLISHED))) {
     log_fn(LOG_WARN, "Missing published time"); goto err;
   }
-  assert(tok->n_args == 1);
+  tor_assert(tok->n_args == 1);
   if (parse_time(tok->args[0], &router->published_on) < 0)
           goto err;
 
@@ -1152,7 +1154,7 @@
   char *arg, *address, *mask, *port, *endptr;
   int bits;
 
-  assert(tok->tp == K_REJECT || tok->tp == K_ACCEPT);
+  tor_assert(tok->tp == K_REJECT || tok->tp == K_ACCEPT);
 
   if (tok->n_args != 1)
     return -1;
@@ -1253,7 +1255,7 @@
   return 0;
 
 policy_read_failed:
-  assert(newe->string);
+  tor_assert(newe->string);
   log_fn(LOG_WARN,"Couldn't parse line '%s'. Dropping", newe->string);
   tor_free(newe->string);
   free(newe);
@@ -1271,7 +1273,7 @@
 token_free(directory_token_t *tok)
 {
   int i;
-  assert(tok);
+  tor_assert(tok);
   if (tok->args) {
     for (i = 0; i < tok->n_args; ++i) {
       tor_free(tok->args[i]);
@@ -1360,7 +1362,7 @@
         *s = eat_whitespace_no_nl(next+1);
       } else {
         /* The keyword takes no arguments. */
-        assert(a_syn == NO_ARGS);
+        tor_assert(a_syn == NO_ARGS);
         *s = eat_whitespace_no_nl(next);
         if (**s != '\n') {
           RET_ERR("Unexpected arguments");

Index: test.c
===================================================================
RCS file: /home/or/cvsroot/src/or/test.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -d -r1.82 -r1.83
--- test.c	24 Apr 2004 22:17:50 -0000	1.82
+++ test.c	25 Apr 2004 20:37:37 -0000	1.83
@@ -34,7 +34,7 @@
   for(i=0;i<len;++i) {
     for (j=1;j>=0;--j) {
       nyb = (((int) d[i]) >> (j*4)) & 0x0f;
-      assert(0<=nyb && nyb <=15);
+      tor_assert(0<=nyb && nyb <=15);
       putchar(TABLE[nyb]);
     }
   }