Commit 25d54257 authored by Roger Dingledine's avatar Roger Dingledine
Browse files

use tor_assert

remove obsolete BUF_OK macro


svn:r1697
parent 37192bd2
...@@ -22,13 +22,12 @@ struct buf_t { ...@@ -22,13 +22,12 @@ struct buf_t {
* out smaller than this, but they will never autoshrink to less * out smaller than this, but they will never autoshrink to less
* than this size. */ * than this size. */
#define MIN_BUF_SHRINK_SIZE (16*1024) #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 */ /* Change a buffer's capacity. Must only be called when */
static INLINE void buf_resize(buf_t *buf, size_t new_capacity) static INLINE void buf_resize(buf_t *buf, size_t new_capacity)
{ {
assert(buf->datalen <= new_capacity); tor_assert(buf->datalen <= new_capacity);
assert(new_capacity); tor_assert(new_capacity);
buf->mem = tor_realloc(buf->mem, new_capacity); buf->mem = tor_realloc(buf->mem, new_capacity);
buf->len = new_capacity; buf->len = new_capacity;
} }
...@@ -83,7 +82,7 @@ static INLINE void buf_shrink_if_underfull(buf_t *buf) { ...@@ -83,7 +82,7 @@ static INLINE void buf_shrink_if_underfull(buf_t *buf) {
/* Remove the first 'n' bytes from buf. /* Remove the first 'n' bytes from buf.
*/ */
static INLINE void buf_remove_from_front(buf_t *buf, size_t n) { 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; buf->datalen -= n;
memmove(buf->mem, buf->mem+n, buf->datalen); memmove(buf->mem, buf->mem+n, buf->datalen);
buf_shrink_if_underfull(buf); buf_shrink_if_underfull(buf);
...@@ -99,7 +98,7 @@ static int find_str_in_str(const char *str, int str_len, ...@@ -99,7 +98,7 @@ static int find_str_in_str(const char *str, int str_len,
const char *location; const char *location;
const char *last_possible = buf + buf_len - str_len; 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) if(buf_len < str_len)
return -1; return -1;
...@@ -126,7 +125,7 @@ buf_t *buf_new_with_capacity(size_t size) { ...@@ -126,7 +125,7 @@ buf_t *buf_new_with_capacity(size_t size) {
buf->datalen = 0; buf->datalen = 0;
// memset(buf->mem,0,size); // memset(buf->mem,0,size);
assert(BUF_OK(buf)); assert_buf_ok(buf);
return buf; return buf;
} }
...@@ -176,7 +175,8 @@ int read_to_buf(int s, int at_most, buf_t *buf, int *reached_eof) { ...@@ -176,7 +175,8 @@ int read_to_buf(int s, int at_most, buf_t *buf, int *reached_eof) {
int e; int e;
#endif #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)) if (buf_ensure_capacity(buf,buf->datalen+at_most))
return -1; return -1;
...@@ -214,7 +214,8 @@ int read_to_buf(int s, int at_most, buf_t *buf, int *reached_eof) { ...@@ -214,7 +214,8 @@ int read_to_buf(int s, int at_most, buf_t *buf, int *reached_eof) {
int read_to_buf_tls(tor_tls *tls, int at_most, buf_t *buf) { int read_to_buf_tls(tor_tls *tls, int at_most, buf_t *buf) {
int r; int r;
assert(tls && BUF_OK(buf)); tor_assert(tls);
assert_buf_ok(buf);
if (buf_ensure_capacity(buf, at_most+buf->datalen)) if (buf_ensure_capacity(buf, at_most+buf->datalen))
return -1; return -1;
...@@ -245,7 +246,8 @@ int flush_buf(int s, buf_t *buf, int *buf_flushlen) ...@@ -245,7 +246,8 @@ int flush_buf(int s, buf_t *buf, int *buf_flushlen)
int e; int e;
#endif #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 */ if(*buf_flushlen == 0) /* nothing to flush */
return 0; return 0;
...@@ -253,7 +255,7 @@ int flush_buf(int s, buf_t *buf, int *buf_flushlen) ...@@ -253,7 +255,7 @@ int flush_buf(int s, buf_t *buf, int *buf_flushlen)
write_result = send(s, buf->mem, *buf_flushlen, 0); write_result = send(s, buf->mem, *buf_flushlen, 0);
if (write_result < 0) { if (write_result < 0) {
if(!ERRNO_EAGAIN(errno)) { /* it's a real error */ 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; return -1;
} }
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
...@@ -277,7 +279,8 @@ int flush_buf(int s, buf_t *buf, int *buf_flushlen) ...@@ -277,7 +279,8 @@ int flush_buf(int s, buf_t *buf, int *buf_flushlen)
int flush_buf_tls(tor_tls *tls, buf_t *buf, int *buf_flushlen) int flush_buf_tls(tor_tls *tls, buf_t *buf, int *buf_flushlen)
{ {
int r; 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 /* we want to let tls write even if flushlen is zero, because it might
* have a partial record pending */ * have a partial record pending */
...@@ -298,7 +301,8 @@ int write_to_buf(const char *string, int string_len, buf_t *buf) { ...@@ -298,7 +301,8 @@ int write_to_buf(const char *string, int string_len, buf_t *buf) {
* return total number of bytes on the buf * 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)) { 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); log_fn(LOG_WARN, "buflen too small, can't hold %d bytes.", (int)buf->datalen+string_len);
...@@ -318,8 +322,9 @@ int fetch_from_buf(char *string, int string_len, buf_t *buf) { ...@@ -318,8 +322,9 @@ int fetch_from_buf(char *string, int string_len, buf_t *buf) {
* *
* Return the number of bytes still on the buffer. */ * Return the number of bytes still on the buffer. */
assert(string && BUF_OK(buf)); tor_assert(string);
assert(string_len <= buf->datalen); /* make sure we don't ask for too much */ 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); memcpy(string,buf->mem,string_len);
buf_remove_from_front(buf, string_len); buf_remove_from_front(buf, string_len);
...@@ -347,7 +352,7 @@ int fetch_from_buf_http(buf_t *buf, ...@@ -347,7 +352,7 @@ int fetch_from_buf_http(buf_t *buf,
int i; int i;
int headerlen, bodylen, contentlen; int headerlen, bodylen, contentlen;
assert(BUF_OK(buf)); assert_buf_ok(buf);
headers = buf->mem; headers = buf->mem;
i = find_on_inbuf("\r\n\r\n", 4, buf); i = find_on_inbuf("\r\n\r\n", 4, buf);
...@@ -390,7 +395,7 @@ int fetch_from_buf_http(buf_t *buf, ...@@ -390,7 +395,7 @@ int fetch_from_buf_http(buf_t *buf,
(*headers_out)[headerlen] = 0; /* null terminate it */ (*headers_out)[headerlen] = 0; /* null terminate it */
} }
if(body_out) { if(body_out) {
assert(body_used); tor_assert(body_used);
*body_used = bodylen; *body_used = bodylen;
*body_out = tor_malloc(bodylen+1); *body_out = tor_malloc(bodylen+1);
memcpy(*body_out,buf->mem+headerlen,bodylen); memcpy(*body_out,buf->mem+headerlen,bodylen);
...@@ -431,7 +436,7 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) { ...@@ -431,7 +436,7 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) {
if(req->socks_version != 5) { /* we need to negotiate a method */ if(req->socks_version != 5) { /* we need to negotiate a method */
unsigned char nummethods = (unsigned char)*(buf->mem+1); unsigned char nummethods = (unsigned char)*(buf->mem+1);
assert(!req->socks_version); tor_assert(!req->socks_version);
if(buf->datalen < 2+nummethods) if(buf->datalen < 2+nummethods)
return 0; return 0;
if(!nummethods || !memchr(buf->mem+2, 0, nummethods)) { if(!nummethods || !memchr(buf->mem+2, 0, nummethods)) {
...@@ -494,7 +499,7 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) { ...@@ -494,7 +499,7 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) {
log_fn(LOG_WARN,"socks5: unsupported address type %d. Rejecting.",*(buf->mem+3)); log_fn(LOG_WARN,"socks5: unsupported address type %d. Rejecting.",*(buf->mem+3));
return -1; return -1;
} }
assert(0); tor_assert(0);
case 4: /* socks4 */ case 4: /* socks4 */
/* http://archive.socks.permeo.com/protocol/socks4.protocol */ /* http://archive.socks.permeo.com/protocol/socks4.protocol */
/* http://archive.socks.permeo.com/protocol/socks4a.protocol */ /* http://archive.socks.permeo.com/protocol/socks4a.protocol */
...@@ -587,14 +592,16 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) { ...@@ -587,14 +592,16 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) {
} }
} }
void assert_buf_ok(buf_t *buf) void assert_buf_ok(buf_t *buf)
{ {
assert(buf); tor_assert(buf);
assert(buf->magic == BUFFER_MAGIC); tor_assert(buf->magic == BUFFER_MAGIC);
assert(buf->mem); tor_assert(buf->mem);
assert(buf->datalen <= buf->len); tor_assert(buf->datalen <= buf->len);
} }
/* /*
Local Variables: Local Variables:
mode:c mode:c
......
...@@ -51,7 +51,7 @@ void circuit_add(circuit_t *circ) { ...@@ -51,7 +51,7 @@ void circuit_add(circuit_t *circ) {
void circuit_remove(circuit_t *circ) { void circuit_remove(circuit_t *circ) {
circuit_t *tmpcirc; circuit_t *tmpcirc;
assert(circ && global_circuitlist); tor_assert(circ && global_circuitlist);
if(global_circuitlist == circ) { if(global_circuitlist == circ) {
global_circuitlist = global_circuitlist->next; global_circuitlist = global_circuitlist->next;
...@@ -120,8 +120,8 @@ circuit_t *circuit_new(uint16_t p_circ_id, connection_t *p_conn) { ...@@ -120,8 +120,8 @@ circuit_t *circuit_new(uint16_t p_circ_id, connection_t *p_conn) {
} }
void circuit_free(circuit_t *circ) { void circuit_free(circuit_t *circ) {
assert(circ); tor_assert(circ);
assert(circ->magic == CIRCUIT_MAGIC); tor_assert(circ->magic == CIRCUIT_MAGIC);
if (circ->n_crypto) if (circ->n_crypto)
crypto_free_cipher_env(circ->n_crypto); crypto_free_cipher_env(circ->n_crypto);
if (circ->p_crypto) if (circ->p_crypto)
...@@ -182,7 +182,7 @@ static uint16_t get_unique_circ_id_by_conn(connection_t *conn, int circ_id_type) ...@@ -182,7 +182,7 @@ static uint16_t get_unique_circ_id_by_conn(connection_t *conn, int circ_id_type)
int attempts=0; int attempts=0;
uint16_t high_bit; 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; high_bit = (circ_id_type == CIRC_ID_TYPE_HIGHER) ? 1<<15 : 0;
do { do {
/* Sequentially iterate over test_circ_id=1...1<<15-1 until we find a /* Sequentially iterate over test_circ_id=1...1<<15-1 until we find a
...@@ -377,11 +377,11 @@ circuit_t *circuit_get_best(connection_t *conn, ...@@ -377,11 +377,11 @@ circuit_t *circuit_get_best(connection_t *conn,
circuit_t *circ, *best=NULL; circuit_t *circ, *best=NULL;
time_t now = time(NULL); time_t now = time(NULL);
assert(conn); tor_assert(conn);
assert(purpose == CIRCUIT_PURPOSE_C_GENERAL || tor_assert(purpose == CIRCUIT_PURPOSE_C_GENERAL ||
purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT || purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT ||
purpose == CIRCUIT_PURPOSE_C_REND_JOINED); purpose == CIRCUIT_PURPOSE_C_REND_JOINED);
for (circ=global_circuitlist;circ;circ = circ->next) { for (circ=global_circuitlist;circ;circ = circ->next) {
if (!circuit_is_acceptable(circ,conn,must_be_open,purpose,now)) if (!circuit_is_acceptable(circ,conn,must_be_open,purpose,now))
...@@ -705,8 +705,8 @@ int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ, ...@@ -705,8 +705,8 @@ int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ,
crypt_path_t *layer_hint=NULL; crypt_path_t *layer_hint=NULL;
char recognized=0; char recognized=0;
assert(cell && circ); tor_assert(cell && circ);
assert(cell_direction == CELL_DIRECTION_OUT || cell_direction == CELL_DIRECTION_IN); tor_assert(cell_direction == CELL_DIRECTION_OUT || cell_direction == CELL_DIRECTION_IN);
if (circ->marked_for_close) if (circ->marked_for_close)
return 0; return 0;
...@@ -747,8 +747,8 @@ int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ, ...@@ -747,8 +747,8 @@ int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ,
if(!conn) { if(!conn) {
if (circ->rend_splice && cell_direction == CELL_DIRECTION_OUT) { if (circ->rend_splice && cell_direction == CELL_DIRECTION_OUT) {
assert(circ->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED); tor_assert(circ->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED);
assert(circ->rend_splice->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED); tor_assert(circ->rend_splice->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED);
cell->circ_id = circ->rend_splice->p_circ_id; cell->circ_id = circ->rend_splice->p_circ_id;
if (circuit_receive_relay_cell(cell, circ->rend_splice, CELL_DIRECTION_IN)<0) { if (circuit_receive_relay_cell(cell, circ->rend_splice, CELL_DIRECTION_IN)<0) {
log_fn(LOG_WARN, "Error relaying cell across rendezvous; closing circuits"); log_fn(LOG_WARN, "Error relaying cell across rendezvous; closing circuits");
...@@ -773,20 +773,20 @@ static int relay_crypt(circuit_t *circ, cell_t *cell, int cell_direction, ...@@ -773,20 +773,20 @@ static int relay_crypt(circuit_t *circ, cell_t *cell, int cell_direction,
crypt_path_t *thishop; crypt_path_t *thishop;
relay_header_t rh; relay_header_t rh;
assert(circ && cell && recognized); tor_assert(circ && cell && recognized);
assert(cell_direction == CELL_DIRECTION_IN || cell_direction == CELL_DIRECTION_OUT); tor_assert(cell_direction == CELL_DIRECTION_IN || cell_direction == CELL_DIRECTION_OUT);
if(cell_direction == CELL_DIRECTION_IN) { if(cell_direction == CELL_DIRECTION_IN) {
if(CIRCUIT_IS_ORIGIN(circ)) { /* we're at the beginning of the circuit. if(CIRCUIT_IS_ORIGIN(circ)) { /* we're at the beginning of the circuit.
We'll want to do layered crypts. */ We'll want to do layered crypts. */
assert(circ->cpath); tor_assert(circ->cpath);
thishop = circ->cpath; thishop = circ->cpath;
if(thishop->state != CPATH_STATE_OPEN) { if(thishop->state != CPATH_STATE_OPEN) {
log_fn(LOG_WARN,"Relay cell before first created cell? Closing."); log_fn(LOG_WARN,"Relay cell before first created cell? Closing.");
return -1; return -1;
} }
do { /* Remember: cpath is in forward order, that is, first hop first. */ 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) if(relay_crypt_one_payload(thishop->b_crypto, cell->payload, 0) < 0)
return -1; return -1;
...@@ -852,7 +852,7 @@ circuit_package_relay_cell(cell_t *cell, circuit_t *circ, ...@@ -852,7 +852,7 @@ circuit_package_relay_cell(cell_t *cell, circuit_t *circ,
thishop = layer_hint; thishop = layer_hint;
/* moving from farthest to nearest hop */ /* moving from farthest to nearest hop */
do { do {
assert(thishop); tor_assert(thishop);
log_fn(LOG_DEBUG,"crypting a layer of the relay cell."); log_fn(LOG_DEBUG,"crypting a layer of the relay cell.");
if(relay_crypt_one_payload(thishop->f_crypto, cell->payload, 1) < 0) { if(relay_crypt_one_payload(thishop->f_crypto, cell->payload, 1) < 0) {
...@@ -1002,7 +1002,7 @@ int _circuit_mark_for_close(circuit_t *circ) { ...@@ -1002,7 +1002,7 @@ int _circuit_mark_for_close(circuit_t *circ) {
circuit_rep_hist_note_result(circ); circuit_rep_hist_note_result(circ);
} }
if (circ->purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT) { 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 */ /* treat this like getting a nack from it */
log_fn(LOG_INFO,"Failed intro circ %s to %s (awaiting ack). Removing from descriptor.", log_fn(LOG_INFO,"Failed intro circ %s to %s (awaiting ack). Removing from descriptor.",
circ->rend_query, circ->build_state->chosen_exit); circ->rend_query, circ->build_state->chosen_exit);
...@@ -1033,8 +1033,7 @@ int _circuit_mark_for_close(circuit_t *circ) { ...@@ -1033,8 +1033,7 @@ int _circuit_mark_for_close(circuit_t *circ) {
void circuit_detach_stream(circuit_t *circ, connection_t *conn) { void circuit_detach_stream(circuit_t *circ, connection_t *conn) {
connection_t *prevconn; connection_t *prevconn;
assert(circ); tor_assert(circ && conn);
assert(conn);
if(conn == circ->p_streams) { if(conn == circ->p_streams) {
circ->p_streams = conn->next_stream; circ->p_streams = conn->next_stream;
...@@ -1055,7 +1054,7 @@ void circuit_detach_stream(circuit_t *circ, connection_t *conn) { ...@@ -1055,7 +1054,7 @@ void circuit_detach_stream(circuit_t *circ, connection_t *conn) {
return; return;
} }
log_fn(LOG_ERR,"edge conn not in circuit's list?"); 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) { void circuit_about_to_close_connection(connection_t *conn) {
...@@ -1104,7 +1103,7 @@ void circuit_log_path(int severity, circuit_t *circ) { ...@@ -1104,7 +1103,7 @@ void circuit_log_path(int severity, circuit_t *circ) {
struct crypt_path_t *hop; struct crypt_path_t *hop;
char *states[] = {"closed", "waiting for keys", "open"}; char *states[] = {"closed", "waiting for keys", "open"};
routerinfo_t *router; 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): ", snprintf(s, sizeof(buf)-1, "circ (length %d, exit %s): ",
circ->build_state->desired_path_len, circ->build_state->chosen_exit); circ->build_state->desired_path_len, circ->build_state->chosen_exit);
...@@ -1277,7 +1276,7 @@ static void circuit_is_open(circuit_t *circ) { ...@@ -1277,7 +1276,7 @@ static void circuit_is_open(circuit_t *circ) {
break; break;
default: default:
log_fn(LOG_ERR,"unhandled purpose %d",circ->purpose); log_fn(LOG_ERR,"unhandled purpose %d",circ->purpose);
assert(0); tor_assert(0);
} }
} }
...@@ -1344,7 +1343,7 @@ static void circuit_build_failed(circuit_t *circ) { ...@@ -1344,7 +1343,7 @@ static void circuit_build_failed(circuit_t *circ) {
default: default:
/* Other cases are impossible, since this function is only called with /* Other cases are impossible, since this function is only called with
* unbuilt circuits. */ * unbuilt circuits. */
assert(0); tor_assert(0);
} }
} }
...@@ -1448,7 +1447,7 @@ void circuit_n_conn_open(connection_t *or_conn) { ...@@ -1448,7 +1447,7 @@ void circuit_n_conn_open(connection_t *or_conn) {
if (circ->marked_for_close) if (circ->marked_for_close)
continue; continue;
if(CIRCUIT_IS_ORIGIN(circ) && circ->n_addr == or_conn->addr && circ->n_port == or_conn->port) { 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); log_fn(LOG_DEBUG,"Found circ %d, sending onion skin.", circ->n_circ_id);
circ->n_conn = or_conn; circ->n_conn = or_conn;
if(circuit_send_next_onion_skin(circ) < 0) { if(circuit_send_next_onion_skin(circ) < 0) {
...@@ -1471,10 +1470,10 @@ int circuit_send_next_onion_skin(circuit_t *circ) { ...@@ -1471,10 +1470,10 @@ int circuit_send_next_onion_skin(circuit_t *circ) {
int circ_id_type; int circ_id_type;
char payload[2+4+ONIONSKIN_CHALLENGE_LEN]; 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) { 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."); log_fn(LOG_DEBUG,"First skin; sending create cell.");
circ_id_type = decide_circ_id_type(options.Nickname, circ_id_type = decide_circ_id_type(options.Nickname,
...@@ -1505,8 +1504,8 @@ int circuit_send_next_onion_skin(circuit_t *circ) { ...@@ -1505,8 +1504,8 @@ int circuit_send_next_onion_skin(circuit_t *circ) {
circ->state = CIRCUIT_STATE_BUILDING; circ->state = CIRCUIT_STATE_BUILDING;
log_fn(LOG_DEBUG,"first skin; finished sending create cell."); log_fn(LOG_DEBUG,"first skin; finished sending create cell.");
} else { } else {
assert(circ->cpath->state == CPATH_STATE_OPEN); tor_assert(circ->cpath->state == CPATH_STATE_OPEN);
assert(circ->state == CIRCUIT_STATE_BUILDING); tor_assert(circ->state == CIRCUIT_STATE_BUILDING);
log_fn(LOG_DEBUG,"starting to send subsequent skin."); log_fn(LOG_DEBUG,"starting to send subsequent skin.");
r = onion_extend_cpath(&circ->cpath, circ->build_state, &router); r = onion_extend_cpath(&circ->cpath, circ->build_state, &router);
if (r==1) { if (r==1) {
...@@ -1622,9 +1621,9 @@ int circuit_init_cpath_crypto(crypt_path_t *cpath, char *key_data, int reverse) ...@@ -1622,9 +1621,9 @@ int circuit_init_cpath_crypto(crypt_path_t *cpath, char *key_data, int reverse)
crypto_digest_env_t *tmp_digest; crypto_digest_env_t *tmp_digest;
crypto_cipher_env_t *tmp_crypto; crypto_cipher_env_t *tmp_crypto;
assert(cpath && key_data); tor_assert(cpath && key_data);
assert(!(cpath->f_crypto || cpath->b_crypto || tor_assert(!(cpath->f_crypto || cpath->b_crypto ||
cpath->f_digest || cpath->b_digest)); cpath->f_digest || cpath->b_digest));
memset(iv, 0, CIPHER_IV_LEN); memset(iv, 0, CIPHER_IV_LEN);
...@@ -1664,7 +1663,7 @@ int circuit_finish_handshake(circuit_t *circ, char *reply) { ...@@ -1664,7 +1663,7 @@ int circuit_finish_handshake(circuit_t *circ, char *reply) {
unsigned char keys[CPATH_KEY_MATERIAL_LEN]; unsigned char keys[CPATH_KEY_MATERIAL_LEN];
crypt_path_t *hop; crypt_path_t *hop;
assert(CIRCUIT_IS_ORIGIN(circ)); tor_assert(CIRCUIT_IS_ORIGIN(circ));
if(circ->cpath->state == CPATH_STATE_AWAITING_KEYS) if(circ->cpath->state == CPATH_STATE_AWAITING_KEYS)
hop = circ->cpath; hop = circ->cpath;
else { else {
...@@ -1676,7 +1675,7 @@ int circuit_finish_handshake(circuit_t *circ, char *reply) { ...@@ -1676,7 +1675,7 @@ int circuit_finish_handshake(circuit_t *circ, char *reply) {
return -1; 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, if(onion_skin_client_handshake(hop->handshake_state, reply, keys,
DIGEST_LEN*2+CIPHER_KEY_LEN*2) < 0) { DIGEST_LEN*2+CIPHER_KEY_LEN*2) < 0) {
...@@ -1703,8 +1702,8 @@ int circuit_truncated(circuit_t *circ, crypt_path_t *layer) { ...@@ -1703,8 +1702,8 @@ int circuit_truncated(circuit_t *circ, crypt_path_t *layer) {
crypt_path_t *victim; crypt_path_t *victim;
connection_t *stream; connection_t *stream;
assert(circ && CIRCUIT_IS_ORIGIN(circ)); tor_assert(circ && CIRCUIT_IS_ORIGIN(circ));
assert(layer); tor_assert(layer);
/* XXX Since we don't ask for truncates currently, getting a truncated /* XXX Since we don't ask for truncates currently, getting a truncated
* means that a connection broke or an extend failed. For now, * means that a connection broke or an extend failed. For now,
...@@ -1738,24 +1737,24 @@ int circuit_truncated(circuit_t *circ, crypt_path_t *layer) { ...@@ -1738,24 +1737,24 @@ int circuit_truncated(circuit_t *circ, crypt_path_t *layer) {
void assert_cpath_layer_ok(const crypt_path_t *cp) void assert_cpath_layer_ok(const crypt_path_t *cp)
{ {
assert(cp->f_crypto); tor_assert(cp->f_crypto);
assert(cp->b_crypto); tor_assert(cp->b_crypto);
// assert(cp->addr); /* these are zero for rendezvous extra-hops */ // tor_assert(cp->addr); /* these are zero for rendezvous extra-hops */
// assert(cp->port); // tor_assert(cp->port);
switch(cp->state) switch(cp->state)
{ {
case CPATH_STATE_CLOSED: case CPATH_STATE_CLOSED:
case CPATH_STATE_OPEN: case CPATH_STATE_OPEN:
assert(!cp->handshake_state); tor_assert(!cp->handshake_state);
break; break;
case CPATH_STATE_AWAITING_KEYS: case CPATH_STATE_AWAITING_KEYS:
assert(cp->handshake_state); tor_assert(cp->handshake_state);
break; break;
default: default:
assert(0); tor_assert(0);
} }
assert(cp->package_window >= 0); tor_assert(cp->package_window >= 0);
assert(cp->deliver_window >= 0); tor_assert(cp->deliver_window >= 0);
} }
void assert_cpath_ok(const crypt_path_t *cp) void assert_cpath_ok(const crypt_path_t *cp)
...@@ -1768,10 +1767,10 @@ void assert_cpath_ok(const crypt_path_t *cp) ...@@ -1768,10 +1767,10 @@ void assert_cpath_ok(const crypt_path_t *cp)
/* layers must be in sequence of: "open* awaiting? closed*" */ /* layers must be in sequence of: "open* awaiting? closed*" */
if (cp->prev) { if (cp->prev) {
if (cp->prev->state == CPATH_STATE_OPEN) { if (cp->prev->state == CPATH_STATE_OPEN) {
assert(cp->state == CPATH_STATE_CLOSED ||