diff options
author | Nick Mathewson <nickm@torproject.org> | 2011-07-20 12:55:42 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-07-21 11:15:25 -0400 |
commit | 569fe936b8349082d6f9dcd4e55f7d5758d236be (patch) | |
tree | ec9ea9960da15b0f20dd2805f6fea5fa040ed536 /src/or/connection.c | |
parent | 33e6a3d75054d9dbb945434d9fe5c3f6be162adb (diff) | |
download | tor-569fe936b8349082d6f9dcd4e55f7d5758d236be.tar.gz tor-569fe936b8349082d6f9dcd4e55f7d5758d236be.zip |
Move entry-only fields from edge_connection_t to entry_connection_t
Also, refactor the code accordingly.
Diffstat (limited to 'src/or/connection.c')
-rw-r--r-- | src/or/connection.c | 80 |
1 files changed, 41 insertions, 39 deletions
diff --git a/src/or/connection.c b/src/or/connection.c index a799627158..012a3fbd03 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -251,7 +251,7 @@ entry_connection_new(int type, int socket_family) entry_connection_t *entry_conn = tor_malloc_zero(sizeof(entry_connection_t)); tor_assert(type == CONN_TYPE_AP); connection_init(time(NULL), ENTRY_TO_CONN(entry_conn), type, socket_family); - entry_conn->_edge.socks_request = socks_request_new(); + entry_conn->socks_request = socks_request_new(); return entry_conn; } @@ -346,10 +346,10 @@ connection_init(time_t now, connection_t *conn, int type, int socket_family) conn->magic = OR_CONNECTION_MAGIC; break; case CONN_TYPE_EXIT: - conn->magic = ENTRY_CONNECTION_MAGIC; + conn->magic = EDGE_CONNECTION_MAGIC; break; case CONN_TYPE_AP: - conn->magic = EDGE_CONNECTION_MAGIC; + conn->magic = ENTRY_CONNECTION_MAGIC; break; case CONN_TYPE_DIR: conn->magic = DIR_CONNECTION_MAGIC; @@ -483,19 +483,21 @@ _connection_free(connection_t *conn) smartlist_free(or_conn->active_circuit_pqueue); tor_free(or_conn->nickname); } - if (CONN_IS_EDGE(conn)) { - edge_connection_t *edge_conn = TO_EDGE_CONN(conn); - tor_free(edge_conn->chosen_exit_name); - tor_free(edge_conn->original_dest_address); - if (edge_conn->socks_request) - socks_request_free(edge_conn->socks_request); - if (edge_conn->pending_optimistic_data) { - generic_buffer_free(edge_conn->pending_optimistic_data); + if (conn->type == CONN_TYPE_AP) { + entry_connection_t *entry_conn = TO_ENTRY_CONN(conn); + tor_free(entry_conn->chosen_exit_name); + tor_free(entry_conn->original_dest_address); + if (entry_conn->socks_request) + socks_request_free(entry_conn->socks_request); + if (entry_conn->pending_optimistic_data) { + generic_buffer_free(entry_conn->pending_optimistic_data); } - if (edge_conn->sending_optimistic_data) { - generic_buffer_free(edge_conn->sending_optimistic_data); + if (entry_conn->sending_optimistic_data) { + generic_buffer_free(entry_conn->sending_optimistic_data); } - rend_data_free(edge_conn->rend_data); + } + if (CONN_IS_EDGE(conn)) { + rend_data_free(TO_EDGE_CONN(conn)->rend_data); } if (conn->type == CONN_TYPE_CONTROL) { control_connection_t *control_conn = TO_CONTROL_CONN(conn); @@ -639,7 +641,7 @@ connection_about_to_close_connection(connection_t *conn) connection_or_about_to_close(TO_OR_CONN(conn)); break; case CONN_TYPE_AP: - connection_ap_about_to_close(TO_EDGE_CONN(conn)); + connection_ap_about_to_close(TO_ENTRY_CONN(conn)); break; case CONN_TYPE_EXIT: connection_exit_about_to_close(TO_EDGE_CONN(conn)); @@ -1266,19 +1268,19 @@ connection_init_accepted_conn(connection_t *conn, control_event_or_conn_status(TO_OR_CONN(conn), OR_CONN_EVENT_NEW, 0); return connection_tls_start_handshake(TO_OR_CONN(conn), 1); case CONN_TYPE_AP: - TO_EDGE_CONN(conn)->isolation_flags = listener->isolation_flags; - TO_EDGE_CONN(conn)->session_group = listener->session_group; - TO_EDGE_CONN(conn)->nym_epoch = get_signewnym_epoch(); + TO_ENTRY_CONN(conn)->isolation_flags = listener->isolation_flags; + TO_ENTRY_CONN(conn)->session_group = listener->session_group; + TO_ENTRY_CONN(conn)->nym_epoch = get_signewnym_epoch(); switch (TO_CONN(listener)->type) { case CONN_TYPE_AP_LISTENER: conn->state = AP_CONN_STATE_SOCKS_WAIT; break; case CONN_TYPE_AP_TRANS_LISTENER: - TO_EDGE_CONN(conn)->is_transparent_ap = 1; + TO_ENTRY_CONN(conn)->is_transparent_ap = 1; conn->state = AP_CONN_STATE_CIRCUIT_WAIT; - return connection_ap_process_transparent(TO_EDGE_CONN(conn)); + return connection_ap_process_transparent(TO_ENTRY_CONN(conn)); case CONN_TYPE_AP_NATD_LISTENER: - TO_EDGE_CONN(conn)->is_transparent_ap = 1; + TO_ENTRY_CONN(conn)->is_transparent_ap = 1; conn->state = AP_CONN_STATE_NATD_WAIT; break; } @@ -2635,8 +2637,10 @@ connection_handle_read_impl(connection_t *conn) if (CONN_IS_EDGE(conn)) { edge_connection_t *edge_conn = TO_EDGE_CONN(conn); connection_edge_end_errno(edge_conn); - if (edge_conn->socks_request) /* broken, don't send a socks reply back */ - edge_conn->socks_request->has_finished = 1; + if (conn->type == CONN_TYPE_AP && TO_ENTRY_CONN(conn)->socks_request) { + /* broken, don't send a socks reply back */ + TO_ENTRY_CONN(conn)->socks_request->has_finished = 1; + } } connection_close_immediate(conn); /* Don't flush; connection is dead. */ connection_mark_for_close(conn); @@ -2978,8 +2982,10 @@ connection_handle_event_cb(struct bufferevent *bufev, short event, void *arg) edge_connection_t *edge_conn = TO_EDGE_CONN(conn); if (!edge_conn->edge_has_sent_end) connection_edge_end_errno(edge_conn); - if (edge_conn->socks_request) /* broken, don't send a socks reply back */ - edge_conn->socks_request->has_finished = 1; + if (conn->type == CONN_TYPE_AP && TO_ENTRY_CONN(conn)->socks_request) { + /* broken, don't send a socks reply back */ + TO_ENTRY_CONN(conn)->socks_request->has_finished = 1; + } } connection_close_immediate(conn); /* Connection is dead. */ if (!conn->marked_for_close) @@ -3509,8 +3515,7 @@ connection_get_by_type_state_rendquery(int type, int state, type == CONN_TYPE_AP || type == CONN_TYPE_EXIT); tor_assert(rendquery); - SMARTLIST_FOREACH(conns, connection_t *, conn, - { + SMARTLIST_FOREACH_BEGIN(conns, connection_t *, conn) { if (conn->type == type && !conn->marked_for_close && (!state || state == conn->state)) { @@ -3525,7 +3530,7 @@ connection_get_by_type_state_rendquery(int type, int state, TO_EDGE_CONN(conn)->rend_data->onion_address)) return conn; } - }); + } SMARTLIST_FOREACH_END(conn); return NULL; } @@ -4016,21 +4021,18 @@ assert_connection_ok(connection_t *conn, time_t now) } if (CONN_IS_EDGE(conn)) { - edge_connection_t *edge_conn = TO_EDGE_CONN(conn); - if (edge_conn->chosen_exit_optional || edge_conn->chosen_exit_retries) { - tor_assert(conn->type == CONN_TYPE_AP); - tor_assert(edge_conn->chosen_exit_name); - } - /* XXX unchecked: package window, deliver window. */ if (conn->type == CONN_TYPE_AP) { + entry_connection_t *entry_conn = TO_ENTRY_CONN(conn); + if (entry_conn->chosen_exit_optional || entry_conn->chosen_exit_retries) + tor_assert(entry_conn->chosen_exit_name); - tor_assert(edge_conn->socks_request); + tor_assert(entry_conn->socks_request); if (conn->state == AP_CONN_STATE_OPEN) { - tor_assert(edge_conn->socks_request->has_finished); + tor_assert(entry_conn->socks_request->has_finished); if (!conn->marked_for_close) { - tor_assert(edge_conn->cpath_layer); - assert_cpath_layer_ok(edge_conn->cpath_layer); + tor_assert(ENTRY_TO_EDGE_CONN(entry_conn)->cpath_layer); + assert_cpath_layer_ok(ENTRY_TO_EDGE_CONN(entry_conn)->cpath_layer); } } } @@ -4063,7 +4065,7 @@ assert_connection_ok(connection_t *conn, time_t now) case CONN_TYPE_AP: tor_assert(conn->state >= _AP_CONN_STATE_MIN); tor_assert(conn->state <= _AP_CONN_STATE_MAX); - tor_assert(TO_EDGE_CONN(conn)->socks_request); + tor_assert(TO_ENTRY_CONN(conn)->socks_request); break; case CONN_TYPE_DIR: tor_assert(conn->state >= _DIR_CONN_STATE_MIN); |