diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/or/circuit.c | 72 | ||||
-rw-r--r-- | src/or/connection.c | 101 | ||||
-rw-r--r-- | src/or/or.h | 20 |
3 files changed, 193 insertions, 0 deletions
diff --git a/src/or/circuit.c b/src/or/circuit.c index 2f5649f8b..ceafed6ca 100644 --- a/src/or/circuit.c +++ b/src/or/circuit.c @@ -939,6 +939,78 @@ int circuit_truncated(circuit_t *circ, crypt_path_t *layer) { return 0; } + +void assert_cpath_layer_ok(crypt_path_t *cp) +{ + assert(cp->f_crypto); + assert(cp->b_crypto); + assert(cp->addr); + assert(cp->port); + switch(cp->state) + { + case CPATH_STATE_CLOSED: + case CPATH_STATE_OPEN: + assert(!cp->handshake_state); + case CPATH_STATE_AWAITING_KEYS: + assert(cp->handshake_state); + default: + assert(0); + } + assert(cp->package_window >= 0); + assert(cp->deliver_window >= 0); +} + +void assert_cpath_ok(crypt_path_t *cp) +{ + while(cp->prev) + cp = cp->prev; + + while(cp->next) { + assert_cpath_layer_ok(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); + } else { + assert(cp->state == CPATH_STATE_CLOSED); + } + } + cp = cp->next; + } +} + +void assert_circuit_ok(circuit_t *c) +{ + connection_t *conn; + + assert(c->n_addr); + assert(c->n_port); + assert(c->n_conn); + assert(c->n_conn->type == CONN_TYPE_OR); + if (c->p_conn) + assert(c->p_conn->type == CONN_TYPE_OR); + for (conn = c->p_streams; conn; conn = conn->next_stream) + assert(c->p_conn->type == CONN_TYPE_EXIT); + for (conn = c->n_streams; conn; conn = conn->next_stream) + assert(conn->type == CONN_TYPE_EXIT); + + assert(c->deliver_window >= 0); + assert(c->package_window >= 0); + if (c->state == CIRCUIT_STATE_OPEN) { + if (c->cpath) { + assert(!c->n_crypto); + assert(!c->p_crypto); + } else { + assert(c->n_crypto); + assert(c->p_crypto); + } + } + if (c->cpath) { + assert_cpath_ok(c->cpath); + } +} + /* Local Variables: mode:c diff --git a/src/or/connection.c b/src/or/connection.c index a6505931a..76e1f6732 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -765,6 +765,107 @@ int connection_finished_flushing(connection_t *conn) { } } +void assert_connection_ok(connection_t *conn, time_t now) +{ + assert(conn); + assert(conn->type >= _CONN_TYPE_MIN); + assert(conn->type <= _CONN_TYPE_MAX); + + /* XXX check: wants_to_read, wants_to_write, s, poll_index, + * marked_for_close. */ + + /* buffers */ + assert(conn->inbuf); + assert(conn->inbuflen <= conn->inbuf_datalen); + assert(conn->inbuflen >= 0); + assert(conn->inbuf_datalen > 0); + assert(conn->outbuf); + assert(conn->outbuflen <= conn->outbuf_datalen); + assert(conn->outbuflen >= 0); + assert(conn->outbuf_datalen > 0); + + 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); + + if (conn->type != CONN_TYPE_OR) { + assert(conn->bandwidth == -1); + assert(conn->receiver_bucket == -1); + /* Addr, port, address XXX */ + assert(!conn->pkey); + assert(!conn->tls); + } else { + assert(conn->bandwidth); + assert(conn->receiver_bucket >= 0); + assert(conn->receiver_bucket <= 10*conn->bandwidth); + assert(conn->addr && conn->port); + assert(conn->address); + assert(conn->pkey); +#ifdef USE_TLS + if (conn->state != OR_CONN_STATE_CONNECTING) + assert(conn->tls); +#endif + } + + if (conn->type != CONN_TYPE_EXIT) { + assert(!conn->stream_id[0]); + assert(!conn->next_stream); + assert(!conn->cpath_layer); + assert(!conn->package_window); + assert(!conn->deliver_window); + assert(!conn->done_sending); + assert(!conn->done_receiving); + } else { + assert(!conn->next_stream || + conn->next_stream->type == CONN_TYPE_EXIT); + assert(conn->cpath_layer); + assert_cpath_layer_ok(conn->cpath_layer); + /* XXX unchecked, package window, deliver window. */ + } + + if (conn->type != CONN_TYPE_AP) { + assert(!conn->socks_version); + assert(!conn->read_username); + assert(!conn->dest_addr); + assert(!conn->dest_port); + } + + switch(conn->type) + { + case CONN_TYPE_OR_LISTENER: + case CONN_TYPE_AP_LISTENER: + case CONN_TYPE_DIR_LISTENER: + assert(conn->state == LISTENER_STATE_READY); + break; + case CONN_TYPE_OR: + 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); + break; + case CONN_TYPE_AP: + assert(conn->state >= _AP_CONN_STATE_MIN && + conn->state <= _AP_CONN_STATE_MAX); + break; + case CONN_TYPE_DIR: + assert(conn->state >= _DIR_CONN_STATE_MIN && + conn->state <= _DIR_CONN_STATE_MAX); + break; + case CONN_TYPE_DNSWORKER: + assert(conn->state == DNSWORKER_STATE_IDLE || + conn->state == DNSWORKER_STATE_BUSY); + case CONN_TYPE_CPUWORKER: + assert(conn->state >= _CPUWORKER_STATE_MIN && + conn->state <= _CPUWORKER_STATE_MAX); + break; + default: + assert(0); + } +} + /* Local Variables: mode:c diff --git a/src/or/or.h b/src/or/or.h index ad677d5ca..d9f7cbc08 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -112,6 +112,7 @@ #define ACI_TYPE_HIGHER 1 #define ACI_TYPE_BOTH 2 +#define _CONN_TYPE_MIN 3 #define CONN_TYPE_OR_LISTENER 3 #define CONN_TYPE_OR 4 #define CONN_TYPE_EXIT 5 @@ -121,15 +122,18 @@ #define CONN_TYPE_DIR 9 #define CONN_TYPE_DNSWORKER 10 #define CONN_TYPE_CPUWORKER 11 +#define _CONN_TYPE_MAX 3 #define LISTENER_STATE_READY 0 #define DNSWORKER_STATE_IDLE 0 #define DNSWORKER_STATE_BUSY 1 +#define _CPUWORKER_STATE_MIN 0 #define CPUWORKER_STATE_IDLE 0 #define CPUWORKER_STATE_BUSY_ONION 1 #define CPUWORKER_STATE_BUSY_HANDSHAKE 2 +#define _CPUWORKER_STATE_MAX 2 #define CPUWORKER_TASK_ONION CPUWORKER_STATE_BUSY_ONION #define CPUWORKER_TASK_HANDSHAKE CPUWORKER_STATE_BUSY_HANDSHAKE @@ -140,6 +144,7 @@ * "I am acting as a bar, currently in stage baz of talking with a foo." */ //#define OR_CONN_STATE_OP_CONNECTING 0 /* an application proxy wants me to connect to this OR */ +#define _OR_CONN_STATE_MIN 1 #define OR_CONN_STATE_OP_SENDING_KEYS 1 #define OR_CONN_STATE_CLIENT_CONNECTING 2 /* connecting to this OR */ #define OR_CONN_STATE_CLIENT_SENDING_AUTH 3 /* sending address and info */ @@ -149,29 +154,38 @@ #define OR_CONN_STATE_SERVER_SENDING_AUTH 7 /* writing auth and nonce */ #define OR_CONN_STATE_SERVER_NONCE_WAIT 8 /* waiting for confirmation of nonce */ #define OR_CONN_STATE_OPEN 9 /* ready to send/receive cells. */ +#define _OR_CONN_STATE_MAX 9 #else +#define _OR_CONN_STATE_MIN 0 #define OR_CONN_STATE_CONNECTING 0 /* waiting for connect() to finish */ #define OR_CONN_STATE_HANDSHAKING 1 /* SSL is handshaking, not done yet */ #define OR_CONN_STATE_OPEN 2 /* ready to send/receive cells. */ +#define _OR_CONN_STATE_MAX 2 #endif +#define _EXIT_CONN_STATE_MIN 0 #define EXIT_CONN_STATE_RESOLVING 0 /* waiting for response from dns farm */ #define EXIT_CONN_STATE_CONNECTING 1 /* waiting for connect() to finish */ #define EXIT_CONN_STATE_OPEN 2 +#define _EXIT_CONN_STATE_MAX 2 #if 0 #define EXIT_CONN_STATE_CLOSE 3 /* flushing the buffer, then will close */ #define EXIT_CONN_STATE_CLOSE_WAIT 4 /* have sent a destroy, awaiting a confirmation */ #endif +#define _AP_CONN_STATE_MIN 3 #define AP_CONN_STATE_SOCKS_WAIT 3 #define AP_CONN_STATE_OR_WAIT 4 #define AP_CONN_STATE_OPEN 5 +#define _AP_CONN_STATE_MAX 5 +#define _DIR_CONN_STATE_MIN 0 #define DIR_CONN_STATE_CONNECTING 0 #define DIR_CONN_STATE_SENDING_COMMAND 1 #define DIR_CONN_STATE_READING 2 #define DIR_CONN_STATE_COMMAND_WAIT 3 #define DIR_CONN_STATE_WRITING 4 +#define _DIR_CONN_STATE_MAX 4 #define CIRCUIT_STATE_BUILDING 0 /* I'm the OP, still haven't done all my handshakes */ #define CIRCUIT_STATE_ONIONSKIN_PENDING 1 /* waiting to process the onion */ @@ -518,6 +532,10 @@ int circuit_extend(cell_t *cell, circuit_t *circ); int circuit_finish_handshake(circuit_t *circ, char *reply); int circuit_truncated(circuit_t *circ, crypt_path_t *layer); +void assert_cpath_ok(crypt_path_t *c); +void assert_cpath_layer_ok(crypt_path_t *c); +void assert_circuit_ok(circuit_t *c); + /********************************* command.c ***************************/ void command_process_cell(cell_t *cell, connection_t *conn); @@ -564,6 +582,8 @@ int connection_send_destroy(aci_t aci, connection_t *conn); int connection_process_inbuf(connection_t *conn); int connection_finished_flushing(connection_t *conn); +void assert_connection_ok(connection_t *conn, time_t now); + /********************************* connection_edge.c ***************************/ int connection_edge_process_inbuf(connection_t *conn); |