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 {
* 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 @@ static INLINE void buf_shrink_if_underfull(buf_t *buf) {
/* 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 @@ static int find_str_in_str(const char *str, int str_len,
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_t *buf_new_with_capacity(size_t size) {
buf->datalen = 0;
// memset(buf->mem,0,size);
assert(BUF_OK(buf));
assert_buf_ok(buf);
return buf;
}
......@@ -176,7 +175,8 @@ int read_to_buf(int s, int at_most, buf_t *buf, int *reached_eof) {
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(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 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 flush_buf(int s, buf_t *buf, int *buf_flushlen)
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 @@ int flush_buf(int s, buf_t *buf, int *buf_flushlen)
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(int s, buf_t *buf, int *buf_flushlen)
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 @@ int write_to_buf(const char *string, int string_len, buf_t *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)) {
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) {
*
* 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 fetch_from_buf_http(buf_t *buf,
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 @@ int fetch_from_buf_http(buf_t *buf,
(*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 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) {
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 @@ 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));
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 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) {
}
}
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
......
......@@ -51,7 +51,7 @@ void circuit_add(circuit_t *circ) {
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 @@ circuit_t *circuit_new(uint16_t p_circ_id, connection_t *p_conn) {
}
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 @@ static uint16_t get_unique_circ_id_by_conn(connection_t *conn, int circ_id_type)
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 *circuit_get_best(connection_t *conn,
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 @@ int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ,
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 @@ int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ,
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 @@ static int relay_crypt(circuit_t *circ, cell_t *cell, int cell_direction,
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 @@ circuit_package_relay_cell(cell_t *cell, circuit_t *circ,
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 @@ int _circuit_mark_for_close(circuit_t *circ) {
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 @@ int _circuit_mark_for_close(circuit_t *circ) {
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 @@ void circuit_detach_stream(circuit_t *circ, connection_t *conn) {
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 @@ void circuit_log_path(int severity, circuit_t *circ) {
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 @@ static void circuit_is_open(circuit_t *circ) {
break;
default:
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) {
default:
/* Other cases are impossible, since this function is only called with
* unbuilt circuits. */
assert(0);
tor_assert(0);
}
}
......@@ -1448,7 +1447,7 @@ void circuit_n_conn_open(connection_t *or_conn) {
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 circuit_send_next_onion_skin(circuit_t *circ) {
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 @@ int circuit_send_next_onion_skin(circuit_t *circ) {
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 @@ int circuit_init_cpath_crypto(crypt_path_t *cpath, char *key_data, int reverse)
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 @@ int circuit_finish_handshake(circuit_t *circ, char *reply) {
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 @@ int circuit_finish_handshake(circuit_t *circ, char *reply) {
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 @@ int circuit_truncated(circuit_t *circ, crypt_path_t *layer) {
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 @@ int circuit_truncated(circuit_t *circ, crypt_path_t *layer) {
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 @@ void assert_cpath_ok(const crypt_path_t *cp)
/* 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 @@ void assert_circuit_ok(const circuit_t *c)
{
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 @@ void assert_circuit_ok(const circuit_t *c)
}
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);
}
}
......
......@@ -25,7 +25,7 @@ static int config_assign(or_options_t *options, struct config_line_t *list);
/* 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 @@ static FILE *config_open(const unsigned char *filename) {
/* close configuration file */
static int config_close(FILE *f) {
assert(f);
tor_assert(f);
return fclose(f);
}
......@@ -396,7 +396,7 @@ static int resolve_my_address(or_options_t *options) {
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))) {
......
......@@ -99,8 +99,8 @@ connection_t *connection_new(int type) {
}
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 @@ void connection_expire_held_open(void)
* 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 @@ int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_
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 @@ int connection_bucket_read_limit(connection_t *conn) {
/* 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 @@ void connection_bucket_refill(struct timeval *now) {
}
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 @@ int connection_outbuf_too_full(connection_t *conn) {
/* 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 @@ connection_t *connection_twin_get_by_addr_port(uint32_t addr, uint16_t port) {
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_is_listener(connection_t *conn) {
}
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_state_is_open(connection_t *conn) {
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_send_destroy(uint16_t circ_id, connection_t *conn) {