Commit 4ff4577b authored by Nick Mathewson's avatar Nick Mathewson 🥄
Browse files

r6908@Kushana: nickm | 2006-07-26 12:38:52 -0400

 Refactor connection_t into edge, or, dir, control, and base subtypes.  This might save some RAM on busy exit servers, but really matters most in terms of correctness.


svn:r6906
parent 18771e85
...@@ -60,14 +60,13 @@ static void entry_guards_changed(void); ...@@ -60,14 +60,13 @@ static void entry_guards_changed(void);
* Return it, or 0 if can't get a unique circ_id. * Return it, or 0 if can't get a unique circ_id.
*/ */
static uint16_t static uint16_t
get_unique_circ_id_by_conn(connection_t *conn) get_unique_circ_id_by_conn(or_connection_t *conn)
{ {
uint16_t test_circ_id; uint16_t test_circ_id;
uint16_t attempts=0; uint16_t attempts=0;
uint16_t high_bit; uint16_t high_bit;
tor_assert(conn); tor_assert(conn);
tor_assert(conn->type == CONN_TYPE_OR);
high_bit = (conn->circ_id_type == CIRC_ID_TYPE_HIGHER) ? 1<<15 : 0; high_bit = (conn->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
...@@ -277,7 +276,7 @@ int ...@@ -277,7 +276,7 @@ int
circuit_handle_first_hop(origin_circuit_t *circ) circuit_handle_first_hop(origin_circuit_t *circ)
{ {
crypt_path_t *firsthop; crypt_path_t *firsthop;
connection_t *n_conn; or_connection_t *n_conn;
char tmpbuf[INET_NTOA_BUF_LEN]; char tmpbuf[INET_NTOA_BUF_LEN];
struct in_addr in; struct in_addr in;
...@@ -298,15 +297,15 @@ circuit_handle_first_hop(origin_circuit_t *circ) ...@@ -298,15 +297,15 @@ circuit_handle_first_hop(origin_circuit_t *circ)
/* If we don't have an open conn, or the conn we have is obsolete /* If we don't have an open conn, or the conn we have is obsolete
* (i.e. old or broken) and the other side will let us make a second * (i.e. old or broken) and the other side will let us make a second
* connection without dropping it immediately... */ * connection without dropping it immediately... */
if (!n_conn || n_conn->state != OR_CONN_STATE_OPEN || if (!n_conn || n_conn->_base.state != OR_CONN_STATE_OPEN ||
(n_conn->is_obsolete && (n_conn->_base.or_is_obsolete &&
router_digest_version_as_new_as(firsthop->extend_info->identity_digest, router_digest_version_as_new_as(firsthop->extend_info->identity_digest,
"0.1.1.9-alpha-cvs"))) { "0.1.1.9-alpha-cvs"))) {
/* not currently connected */ /* not currently connected */
circ->_base.n_addr = firsthop->extend_info->addr; circ->_base.n_addr = firsthop->extend_info->addr;
circ->_base.n_port = firsthop->extend_info->port; circ->_base.n_port = firsthop->extend_info->port;
if (!n_conn || n_conn->is_obsolete) { /* launch the connection */ if (!n_conn || n_conn->_base.or_is_obsolete) { /* launch the connection */
n_conn = connection_or_connect(firsthop->extend_info->addr, n_conn = connection_or_connect(firsthop->extend_info->addr,
firsthop->extend_info->port, firsthop->extend_info->port,
firsthop->extend_info->identity_digest); firsthop->extend_info->identity_digest);
...@@ -323,8 +322,8 @@ circuit_handle_first_hop(origin_circuit_t *circ) ...@@ -323,8 +322,8 @@ circuit_handle_first_hop(origin_circuit_t *circ)
*/ */
return 0; return 0;
} else { /* it's already open. use it. */ } else { /* it's already open. use it. */
circ->_base.n_addr = n_conn->addr; circ->_base.n_addr = n_conn->_base.addr;
circ->_base.n_port = n_conn->port; circ->_base.n_port = n_conn->_base.port;
circ->_base.n_conn = n_conn; circ->_base.n_conn = n_conn;
log_debug(LD_CIRC,"Conn open. Delivering first onion skin."); log_debug(LD_CIRC,"Conn open. Delivering first onion skin.");
if (circuit_send_next_onion_skin(circ) < 0) { if (circuit_send_next_onion_skin(circ) < 0) {
...@@ -341,7 +340,7 @@ circuit_handle_first_hop(origin_circuit_t *circ) ...@@ -341,7 +340,7 @@ circuit_handle_first_hop(origin_circuit_t *circ)
* Status is 1 if connect succeeded, or 0 if connect failed. * Status is 1 if connect succeeded, or 0 if connect failed.
*/ */
void void
circuit_n_conn_done(connection_t *or_conn, int status) circuit_n_conn_done(or_connection_t *or_conn, int status)
{ {
extern smartlist_t *circuits_pending_or_conns; extern smartlist_t *circuits_pending_or_conns;
smartlist_t *changed_circs; smartlist_t *changed_circs;
...@@ -419,7 +418,6 @@ circuit_deliver_create_cell(circuit_t *circ, uint8_t cell_type, ...@@ -419,7 +418,6 @@ circuit_deliver_create_cell(circuit_t *circ, uint8_t cell_type,
tor_assert(circ); tor_assert(circ);
tor_assert(circ->n_conn); tor_assert(circ->n_conn);
tor_assert(circ->n_conn->type == CONN_TYPE_OR);
tor_assert(payload); tor_assert(payload);
tor_assert(cell_type == CELL_CREATE || cell_type == CELL_CREATE_FAST); tor_assert(cell_type == CELL_CREATE || cell_type == CELL_CREATE_FAST);
...@@ -621,7 +619,7 @@ circuit_note_clock_jumped(int seconds_elapsed) ...@@ -621,7 +619,7 @@ circuit_note_clock_jumped(int seconds_elapsed)
int int
circuit_extend(cell_t *cell, circuit_t *circ) circuit_extend(cell_t *cell, circuit_t *circ)
{ {
connection_t *n_conn; or_connection_t *n_conn;
relay_header_t rh; relay_header_t rh;
char *onionskin; char *onionskin;
char *id_digest=NULL; char *id_digest=NULL;
...@@ -651,8 +649,8 @@ circuit_extend(cell_t *cell, circuit_t *circ) ...@@ -651,8 +649,8 @@ circuit_extend(cell_t *cell, circuit_t *circ)
/* If we don't have an open conn, or the conn we have is obsolete /* If we don't have an open conn, or the conn we have is obsolete
* (i.e. old or broken) and the other side will let us make a second * (i.e. old or broken) and the other side will let us make a second
* connection without dropping it immediately... */ * connection without dropping it immediately... */
if (!n_conn || n_conn->state != OR_CONN_STATE_OPEN || if (!n_conn || n_conn->_base.state != OR_CONN_STATE_OPEN ||
(n_conn->is_obsolete && (n_conn->_base.or_is_obsolete &&
router_digest_version_as_new_as(id_digest,"0.1.1.9-alpha-cvs"))) { router_digest_version_as_new_as(id_digest,"0.1.1.9-alpha-cvs"))) {
struct in_addr in; struct in_addr in;
char tmpbuf[INET_NTOA_BUF_LEN]; char tmpbuf[INET_NTOA_BUF_LEN];
...@@ -668,9 +666,9 @@ circuit_extend(cell_t *cell, circuit_t *circ) ...@@ -668,9 +666,9 @@ circuit_extend(cell_t *cell, circuit_t *circ)
/* imprint the circuit with its future n_conn->id */ /* imprint the circuit with its future n_conn->id */
memcpy(circ->n_conn_id_digest, id_digest, DIGEST_LEN); memcpy(circ->n_conn_id_digest, id_digest, DIGEST_LEN);
if (n_conn && !n_conn->is_obsolete) { if (n_conn && !n_conn->_base.or_is_obsolete) {
circ->n_addr = n_conn->addr; circ->n_addr = n_conn->_base.addr;
circ->n_port = n_conn->port; circ->n_port = n_conn->_base.port;
} else { } else {
/* we should try to open a connection */ /* we should try to open a connection */
n_conn = connection_or_connect(circ->n_addr, circ->n_port, id_digest); n_conn = connection_or_connect(circ->n_addr, circ->n_port, id_digest);
...@@ -689,12 +687,12 @@ circuit_extend(cell_t *cell, circuit_t *circ) ...@@ -689,12 +687,12 @@ circuit_extend(cell_t *cell, circuit_t *circ)
} }
/* these may be different if the router connected to us from elsewhere */ /* these may be different if the router connected to us from elsewhere */
circ->n_addr = n_conn->addr; circ->n_addr = n_conn->_base.addr;
circ->n_port = n_conn->port; circ->n_port = n_conn->_base.port;
circ->n_conn = n_conn; circ->n_conn = n_conn;
memcpy(circ->n_conn_id_digest, n_conn->identity_digest, DIGEST_LEN); memcpy(circ->n_conn_id_digest, n_conn->identity_digest, DIGEST_LEN);
log_debug(LD_CIRC,"n_conn is %s:%u",n_conn->address,n_conn->port); log_debug(LD_CIRC,"n_conn is %s:%u",n_conn->_base.address,n_conn->_base.port);
if (circuit_deliver_create_cell(circ, CELL_CREATE, onionskin) < 0) if (circuit_deliver_create_cell(circ, CELL_CREATE, onionskin) < 0)
return -1; return -1;
...@@ -910,7 +908,7 @@ onionskin_answer(or_circuit_t *circ, uint8_t cell_type, char *payload, ...@@ -910,7 +908,7 @@ onionskin_answer(or_circuit_t *circ, uint8_t cell_type, char *payload,
connection_or_write_cell_to_buf(&cell, circ->p_conn); connection_or_write_cell_to_buf(&cell, circ->p_conn);
log_debug(LD_CIRC,"Finished sending 'created' cell."); log_debug(LD_CIRC,"Finished sending 'created' cell.");
if (!is_local_IP(circ->p_conn->addr) && if (!is_local_IP(circ->p_conn->_base.addr) &&
!connection_or_nonopen_was_started_here(circ->p_conn)) { !connection_or_nonopen_was_started_here(circ->p_conn)) {
/* record that we could process create cells from a non-local conn /* record that we could process create cells from a non-local conn
* that we didn't initiate; presumably this means that create cells * that we didn't initiate; presumably this means that create cells
...@@ -1048,8 +1046,9 @@ ap_stream_wants_exit_attention(connection_t *conn) ...@@ -1048,8 +1046,9 @@ ap_stream_wants_exit_attention(connection_t *conn)
if (conn->type == CONN_TYPE_AP && if (conn->type == CONN_TYPE_AP &&
conn->state == AP_CONN_STATE_CIRCUIT_WAIT && conn->state == AP_CONN_STATE_CIRCUIT_WAIT &&
!conn->marked_for_close && !conn->marked_for_close &&
!connection_edge_is_rendezvous_stream(conn) && !connection_edge_is_rendezvous_stream(TO_EDGE_CONN(conn)) &&
!circuit_stream_is_being_handled(conn, 0, MIN_CIRCUITS_HANDLING_STREAM)) !circuit_stream_is_being_handled(TO_EDGE_CONN(conn), 0,
MIN_CIRCUITS_HANDLING_STREAM))
return 1; return 1;
return 0; return 0;
} }
...@@ -1134,7 +1133,7 @@ choose_good_exit_server_general(routerlist_t *dir, int need_uptime, ...@@ -1134,7 +1133,7 @@ choose_good_exit_server_general(routerlist_t *dir, int need_uptime,
for (j = 0; j < n_connections; ++j) { /* iterate over connections */ for (j = 0; j < n_connections; ++j) { /* iterate over connections */
if (!ap_stream_wants_exit_attention(carray[j])) if (!ap_stream_wants_exit_attention(carray[j]))
continue; /* Skip everything but APs in CIRCUIT_WAIT */ continue; /* Skip everything but APs in CIRCUIT_WAIT */
if (connection_ap_can_use_exit(carray[j], router)) { if (connection_ap_can_use_exit(TO_EDGE_CONN(carray[j]), router)) {
++n_supported[i]; ++n_supported[i];
// log_fn(LOG_DEBUG,"%s is supported. n_supported[%d] now %d.", // log_fn(LOG_DEBUG,"%s is supported. n_supported[%d] now %d.",
// router->nickname, i, n_supported[i]); // router->nickname, i, n_supported[i]);
......
...@@ -33,7 +33,7 @@ static void circuit_free_cpath_node(crypt_path_t *victim); ...@@ -33,7 +33,7 @@ static void circuit_free_cpath_node(crypt_path_t *victim);
* very important here, since we need to do it every time a cell arrives.) */ * very important here, since we need to do it every time a cell arrives.) */
typedef struct orconn_circid_circuit_map_t { typedef struct orconn_circid_circuit_map_t {
HT_ENTRY(orconn_circid_circuit_map_t) node; HT_ENTRY(orconn_circid_circuit_map_t) node;
connection_t *or_conn; or_connection_t *or_conn;
uint16_t circ_id; uint16_t circ_id;
circuit_t *circuit; circuit_t *circuit;
} orconn_circid_circuit_map_t; } orconn_circid_circuit_map_t;
...@@ -70,8 +70,8 @@ orconn_circid_circuit_map_t *_last_circid_orconn_ent = NULL; ...@@ -70,8 +70,8 @@ orconn_circid_circuit_map_t *_last_circid_orconn_ent = NULL;
static void static void
circuit_set_circid_orconn_helper(circuit_t *circ, uint16_t id, circuit_set_circid_orconn_helper(circuit_t *circ, uint16_t id,
connection_t *conn, or_connection_t *conn,
uint16_t old_id, connection_t *old_conn) uint16_t old_id, or_connection_t *old_conn)
{ {
orconn_circid_circuit_map_t search; orconn_circid_circuit_map_t search;
orconn_circid_circuit_map_t *found; orconn_circid_circuit_map_t *found;
...@@ -85,7 +85,7 @@ circuit_set_circid_orconn_helper(circuit_t *circ, uint16_t id, ...@@ -85,7 +85,7 @@ circuit_set_circid_orconn_helper(circuit_t *circ, uint16_t id,
} }
if (old_conn) { /* we may need to remove it from the conn-circid map */ if (old_conn) { /* we may need to remove it from the conn-circid map */
tor_assert(old_conn->magic == CONNECTION_MAGIC); tor_assert(old_conn->_base.magic == OR_CONNECTION_MAGIC);
search.circ_id = old_id; search.circ_id = old_id;
search.or_conn = old_conn; search.or_conn = old_conn;
found = HT_REMOVE(orconn_circid_map, &orconn_circid_circuit_map, &search); found = HT_REMOVE(orconn_circid_map, &orconn_circid_circuit_map, &search);
...@@ -119,10 +119,10 @@ circuit_set_circid_orconn_helper(circuit_t *circ, uint16_t id, ...@@ -119,10 +119,10 @@ circuit_set_circid_orconn_helper(circuit_t *circ, uint16_t id,
* to the (orconn,id)-\>circuit map. */ * to the (orconn,id)-\>circuit map. */
void void
circuit_set_p_circid_orconn(or_circuit_t *circ, uint16_t id, circuit_set_p_circid_orconn(or_circuit_t *circ, uint16_t id,
connection_t *conn) or_connection_t *conn)
{ {
uint16_t old_id; uint16_t old_id;
connection_t *old_conn; or_connection_t *old_conn;
old_id = circ->p_circ_id; old_id = circ->p_circ_id;
old_conn = circ->p_conn; old_conn = circ->p_conn;
...@@ -140,10 +140,10 @@ circuit_set_p_circid_orconn(or_circuit_t *circ, uint16_t id, ...@@ -140,10 +140,10 @@ circuit_set_p_circid_orconn(or_circuit_t *circ, uint16_t id,
* to the (orconn,id)-\>circuit map. */ * to the (orconn,id)-\>circuit map. */
void void
circuit_set_n_circid_orconn(circuit_t *circ, uint16_t id, circuit_set_n_circid_orconn(circuit_t *circ, uint16_t id,
connection_t *conn) or_connection_t *conn)
{ {
uint16_t old_id; uint16_t old_id;
connection_t *old_conn; or_connection_t *old_conn;
old_id = circ->n_circ_id; old_id = circ->n_circ_id;
old_conn = circ->n_conn; old_conn = circ->n_conn;
...@@ -279,7 +279,7 @@ origin_circuit_new(void) ...@@ -279,7 +279,7 @@ origin_circuit_new(void)
} }
or_circuit_t * or_circuit_t *
or_circuit_new(uint16_t p_circ_id, connection_t *p_conn) or_circuit_new(uint16_t p_circ_id, or_connection_t *p_conn)
{ {
/* CircIDs */ /* CircIDs */
or_circuit_t *circ; or_circuit_t *circ;
...@@ -379,9 +379,9 @@ circuit_free_all(void) ...@@ -379,9 +379,9 @@ circuit_free_all(void)
if (! CIRCUIT_IS_ORIGIN(global_circuitlist)) { if (! CIRCUIT_IS_ORIGIN(global_circuitlist)) {
or_circuit_t *or_circ = TO_OR_CIRCUIT(global_circuitlist); or_circuit_t *or_circ = TO_OR_CIRCUIT(global_circuitlist);
while (or_circ->resolving_streams) { while (or_circ->resolving_streams) {
connection_t *next; edge_connection_t *next;
next = or_circ->resolving_streams->next_stream; next = or_circ->resolving_streams->next_stream;
connection_free(or_circ->resolving_streams); connection_free(TO_CONN(or_circ->resolving_streams));
or_circ->resolving_streams = next; or_circ->resolving_streams = next;
} }
} }
...@@ -439,7 +439,7 @@ void ...@@ -439,7 +439,7 @@ void
circuit_dump_by_conn(connection_t *conn, int severity) circuit_dump_by_conn(connection_t *conn, int severity)
{ {
circuit_t *circ; circuit_t *circ;
connection_t *tmpconn; edge_connection_t *tmpconn;
for (circ=global_circuitlist;circ;circ = circ->next) { for (circ=global_circuitlist;circ;circ = circ->next) {
circid_t n_circ_id = circ->n_circ_id, p_circ_id = 0; circid_t n_circ_id = circ->n_circ_id, p_circ_id = 0;
...@@ -449,25 +449,26 @@ circuit_dump_by_conn(connection_t *conn, int severity) ...@@ -449,25 +449,26 @@ circuit_dump_by_conn(connection_t *conn, int severity)
if (! CIRCUIT_IS_ORIGIN(circ)) if (! CIRCUIT_IS_ORIGIN(circ))
p_circ_id = TO_OR_CIRCUIT(circ)->p_circ_id; p_circ_id = TO_OR_CIRCUIT(circ)->p_circ_id;
if (! CIRCUIT_IS_ORIGIN(circ) && TO_OR_CIRCUIT(circ)->p_conn == conn) if (! CIRCUIT_IS_ORIGIN(circ) && TO_OR_CIRCUIT(circ)->p_conn &&
TO_CONN(TO_OR_CIRCUIT(circ)->p_conn) == conn)
circuit_dump_details(severity, circ, conn->poll_index, "App-ward", circuit_dump_details(severity, circ, conn->poll_index, "App-ward",
p_circ_id, n_circ_id); p_circ_id, n_circ_id);
if (CIRCUIT_IS_ORIGIN(circ)) { if (CIRCUIT_IS_ORIGIN(circ)) {
for (tmpconn=TO_ORIGIN_CIRCUIT(circ)->p_streams; tmpconn; for (tmpconn=TO_ORIGIN_CIRCUIT(circ)->p_streams; tmpconn;
tmpconn=tmpconn->next_stream) { tmpconn=tmpconn->next_stream) {
if (tmpconn == conn) { if (TO_CONN(tmpconn) == conn) {
circuit_dump_details(severity, circ, conn->poll_index, "App-ward", circuit_dump_details(severity, circ, conn->poll_index, "App-ward",
p_circ_id, n_circ_id); p_circ_id, n_circ_id);
} }
} }
} }
if (circ->n_conn == conn) if (circ->n_conn && TO_CONN(circ->n_conn) == conn)
circuit_dump_details(severity, circ, conn->poll_index, "Exit-ward", circuit_dump_details(severity, circ, conn->poll_index, "Exit-ward",
n_circ_id, p_circ_id); n_circ_id, p_circ_id);
if (! CIRCUIT_IS_ORIGIN(circ)) { if (! CIRCUIT_IS_ORIGIN(circ)) {
for (tmpconn=TO_OR_CIRCUIT(circ)->n_streams; tmpconn; for (tmpconn=TO_OR_CIRCUIT(circ)->n_streams; tmpconn;
tmpconn=tmpconn->next_stream) { tmpconn=tmpconn->next_stream) {
if (tmpconn == conn) { if (TO_CONN(tmpconn) == conn) {
circuit_dump_details(severity, circ, conn->poll_index, "Exit-ward", circuit_dump_details(severity, circ, conn->poll_index, "Exit-ward",
n_circ_id, p_circ_id); n_circ_id, p_circ_id);
} }
...@@ -476,7 +477,9 @@ circuit_dump_by_conn(connection_t *conn, int severity) ...@@ -476,7 +477,9 @@ circuit_dump_by_conn(connection_t *conn, int severity)
if (!circ->n_conn && circ->n_addr && circ->n_port && if (!circ->n_conn && circ->n_addr && circ->n_port &&
circ->n_addr == conn->addr && circ->n_addr == conn->addr &&
circ->n_port == conn->port && circ->n_port == conn->port &&
!memcmp(conn->identity_digest, circ->n_conn_id_digest, DIGEST_LEN)) { conn->type == CONN_TYPE_OR &&
!memcmp(TO_OR_CONN(conn)->identity_digest, circ->n_conn_id_digest,
DIGEST_LEN)) {
circuit_dump_details(severity, circ, conn->poll_index, circuit_dump_details(severity, circ, conn->poll_index,
(circ->state == CIRCUIT_STATE_OPEN && (circ->state == CIRCUIT_STATE_OPEN &&
!CIRCUIT_IS_ORIGIN(circ)) ? !CIRCUIT_IS_ORIGIN(circ)) ?
...@@ -509,13 +512,11 @@ circuit_get_by_global_id(uint32_t id) ...@@ -509,13 +512,11 @@ circuit_get_by_global_id(uint32_t id)
* Return NULL if no such circuit exists. * Return NULL if no such circuit exists.
*/ */
static INLINE circuit_t * static INLINE circuit_t *
circuit_get_by_circid_orconn_impl(uint16_t circ_id, connection_t *conn) circuit_get_by_circid_orconn_impl(uint16_t circ_id, or_connection_t *conn)
{ {
orconn_circid_circuit_map_t search; orconn_circid_circuit_map_t search;
orconn_circid_circuit_map_t *found; orconn_circid_circuit_map_t *found;
tor_assert(conn->type == CONN_TYPE_OR);
if (_last_circid_orconn_ent && if (_last_circid_orconn_ent &&
circ_id == _last_circid_orconn_ent->circ_id && circ_id == _last_circid_orconn_ent->circ_id &&
conn == _last_circid_orconn_ent->or_conn) { conn == _last_circid_orconn_ent->or_conn) {
...@@ -560,7 +561,7 @@ circuit_get_by_circid_orconn_impl(uint16_t circ_id, connection_t *conn) ...@@ -560,7 +561,7 @@ circuit_get_by_circid_orconn_impl(uint16_t circ_id, connection_t *conn)
* Return NULL if no such circuit exists. * Return NULL if no such circuit exists.
*/ */
circuit_t * circuit_t *
circuit_get_by_circid_orconn(uint16_t circ_id, connection_t *conn) circuit_get_by_circid_orconn(uint16_t circ_id, or_connection_t *conn)
{ {
circuit_t *circ = circuit_get_by_circid_orconn_impl(circ_id, conn); circuit_t *circ = circuit_get_by_circid_orconn_impl(circ_id, conn);
if (!circ || circ->marked_for_close) if (!circ || circ->marked_for_close)
...@@ -575,7 +576,7 @@ circuit_get_by_circid_orconn(uint16_t circ_id, connection_t *conn) ...@@ -575,7 +576,7 @@ circuit_get_by_circid_orconn(uint16_t circ_id, connection_t *conn)
* Return NULL if no such circuit exists. * Return NULL if no such circuit exists.
*/ */
int int
circuit_id_used_on_conn(uint16_t circ_id, connection_t *conn) circuit_id_used_on_conn(uint16_t circ_id, or_connection_t *conn)
{ {
circuit_t *circ = circuit_get_by_circid_orconn_impl(circ_id, conn); circuit_t *circ = circuit_get_by_circid_orconn_impl(circ_id, conn);
if (circ && circ->marked_for_close) if (circ && circ->marked_for_close)
...@@ -587,10 +588,9 @@ circuit_id_used_on_conn(uint16_t circ_id, connection_t *conn) ...@@ -587,10 +588,9 @@ circuit_id_used_on_conn(uint16_t circ_id, connection_t *conn)
/** Return the circuit that a given edge connection is using. */ /** Return the circuit that a given edge connection is using. */
circuit_t * circuit_t *
circuit_get_by_edge_conn(connection_t *conn) circuit_get_by_edge_conn(edge_connection_t *conn)
{ {
circuit_t *circ; circuit_t *circ;
tor_assert(CONN_IS_EDGE(conn));
circ = conn->on_circuit; circ = conn->on_circuit;
tor_assert(!circ || tor_assert(!circ ||
...@@ -605,7 +605,7 @@ circuit_get_by_edge_conn(connection_t *conn) ...@@ -605,7 +605,7 @@ circuit_get_by_edge_conn(connection_t *conn)
* been marked already. * been marked already.
*/ */
void void
circuit_unlink_all_from_or_conn(connection_t *conn, int reason) circuit_unlink_all_from_or_conn(or_connection_t *conn, int reason)
{ {
circuit_t *circ; circuit_t *circ;
for (circ = global_circuitlist; circ; circ = circ->next) { for (circ = global_circuitlist; circ; circ = circ->next) {
...@@ -820,8 +820,6 @@ void ...@@ -820,8 +820,6 @@ void
_circuit_mark_for_close(circuit_t *circ, int reason, int line, _circuit_mark_for_close(circuit_t *circ, int reason, int line,
const char *file) const char *file)
{ {
connection_t *conn;
assert_circuit_ok(circ); assert_circuit_ok(circ);
tor_assert(line); tor_assert(line);
tor_assert(file); tor_assert(file);
...@@ -889,18 +887,19 @@ _circuit_mark_for_close(circuit_t *circ, int reason, int line, ...@@ -889,18 +887,19 @@ _circuit_mark_for_close(circuit_t *circ, int reason, int line,
if (! CIRCUIT_IS_ORIGIN(circ)) { if (! CIRCUIT_IS_ORIGIN(circ)) {
or_circuit_t *or_circ = TO_OR_CIRCUIT(circ); or_circuit_t *or_circ = TO_OR_CIRCUIT(circ);
edge_connection_t *conn;
for (conn=or_circ->n_streams; conn; conn=conn->next_stream) for (conn=or_circ->n_streams; conn; conn=conn->next_stream)
connection_edge_destroy(or_circ->p_circ_id, conn); connection_edge_destroy(or_circ->p_circ_id, conn);
while (or_circ->resolving_streams) { while (or_circ->resolving_streams) {
conn = or_circ->resolving_streams; conn = or_circ->resolving_streams;
or_circ->resolving_streams = conn->next_stream; or_circ->resolving_streams = conn->next_stream;
if (!conn->marked_for_close) { if (!conn->_base.marked_for_close) {
/* The other side will see a DESTROY, and infer that the connections /* The other side will see a DESTROY, and infer that the connections
* are closing because the circuit is getting torn down. No need * are closing because the circuit is getting torn down. No need
* to send an end cell. */ * to send an end cell. */
conn->has_sent_end = 1; conn->_base.edge_has_sent_end = 1;
connection_mark_for_close(conn); connection_mark_for_close(TO_CONN(conn));
} }
conn->on_circuit = NULL; conn->on_circuit = NULL;
} }
...@@ -909,6 +908,7 @@ _circuit_mark_for_close(circuit_t *circ, int reason, int line, ...@@ -909,6 +908,7 @@ _circuit_mark_for_close(circuit_t *circ, int reason, int line,
connection_or_send_destroy(or_circ->p_circ_id, or_circ->p_conn, reason); connection_or_send_destroy(or_circ->p_circ_id, or_circ->p_conn, reason);
} else { } else {
origin_circuit_t *ocirc = TO_ORIGIN_CIRCUIT(circ); origin_circuit_t *ocirc = TO_ORIGIN_CIRCUIT(circ);
edge_connection_t *conn;
for (conn=ocirc->p_streams; conn; conn=conn->next_stream) for (conn=ocirc->p_streams; conn; conn=conn->next_stream)
connection_edge_destroy(circ->n_circ_id, conn); connection_edge_destroy(circ->n_circ_id, conn);
} }
...@@ -987,7 +987,7 @@ assert_cpath_ok(const crypt_path_t *cp) ...@@ -987,7 +987,7 @@ assert_cpath_ok(const crypt_path_t *cp)
void void
assert_circuit_ok(const circuit_t *c) assert_circuit_ok(const circuit_t *c)
{ {
connection_t *conn; edge_connection_t *conn;
const or_circuit_t *or_circ = NULL; const or_circuit_t *or_circ = NULL;
const origin_circuit_t *origin_circ = NULL; const origin_circuit_t *origin_circ = NULL;
...@@ -1002,24 +1002,22 @@ assert_circuit_ok(const circuit_t *c) ...@@ -1002,24 +1002,22 @@ assert_circuit_ok(const circuit_t *c)
or_circ = TO_OR_CIRCUIT((circuit_t*)c); or_circ = TO_OR_CIRCUIT((circuit_t*)c);
if (c->n_conn) { if (c->n_conn) {
tor_assert(c->n_conn->type == CONN_TYPE_OR);
tor_assert(!memcmp(c->n_conn->identity_digest, c->n_conn_id_digest, tor_assert(!memcmp(c->n_conn->identity_digest, c->n_conn_id_digest,
DIGEST_LEN)); DIGEST_LEN));
if (c->n_circ_id) if (c->n_circ_id)
tor_assert(c == circuit_get_by_circid_orconn(c->n_circ_id, c->n_conn)); tor_assert(c == circuit_get_by_circid_orconn(c->n_circ_id, c->n_conn));
} }
if (or_circ && or_circ->p_conn) { if (or_circ && or_circ->p_conn) {
tor_assert(or_circ->p_conn->type == CONN_TYPE_OR);
if (or_circ->p_circ_id) if (or_circ->p_circ_id)
tor_assert(c == circuit_get_by_circid_orconn(or_circ->p_circ_id, tor_assert(c == circuit_get_by_circid_orconn(or_circ->p_circ_id,
or_circ->p_conn)); or_circ->p_conn));
} }
if (origin_circ) if (origin_circ)
for (conn = origin_circ->p_streams; conn; conn = conn->next_stream) for (conn = origin_circ->p_streams; conn; conn = conn->next_stream)
tor_assert(conn->type == CONN_TYPE_AP); tor_assert(conn->_base.type == CONN_TYPE_AP);
if (or_circ) if (or_circ)
for (conn = or_circ->n_streams; conn; conn = conn->next_stream) for (conn = or_circ->n_streams; conn; conn = conn->next_stream)
tor_assert(conn->type == CONN_TYPE_EXIT); tor_assert(conn->_base.type == CONN_TYPE_EXIT);
tor_assert(c->deliver_window >= 0); tor_assert(c->deliver_window >= 0);
tor_assert(c->package_window >= 0); tor_assert(c->package_window >= 0);
......
...@@ -26,7 +26,7 @@ static void circuit_increment_failure_count(void); ...@@ -26,7 +26,7 @@ static void circuit_increment_failure_count(void);
* Else return 0. * Else return 0.
*/ */
static int static int
circuit_is_acceptable(circuit_t *circ, connection_t *conn, circuit_is_acceptable(circuit_t *circ, edge_connection_t *conn,
int must_be_open, uint8_t purpose, int must_be_open, uint8_t purpose,
int need_uptime, int need_internal, int need_uptime, int need_internal,
time_t now) time_t now)
...@@ -155,7 +155,7 @@ circuit_is_better(circuit_t *a, circuit_t *b, uint8_t purpose) ...@@ -155,7 +155,7 @@ circuit_is_better(circuit_t *a, circuit_t *b, uint8_t purpose)
* closest introduce-purposed circuit that you can find. * closest introduce-purposed circuit that you can find.