Loading src/or/circuitbuild.c +10 −5 Changes for src/or/circuitbuild.c: 10 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -2648,14 +2648,19 @@ node_handles_some_port(const node_t *node, smartlist_t *needed_ports) static int ap_stream_wants_exit_attention(connection_t *conn) { entry_connection_t *entry; if (conn->type != CONN_TYPE_AP) return 0; entry = TO_ENTRY_CONN(conn); if (conn->type == CONN_TYPE_AP && conn->state == AP_CONN_STATE_CIRCUIT_WAIT && !conn->marked_for_close && !(TO_EDGE_CONN(conn)->want_onehop) && /* ignore one-hop streams */ !(TO_EDGE_CONN(conn)->use_begindir) && /* ignore targeted dir fetches */ !(TO_EDGE_CONN(conn)->chosen_exit_name) && /* ignore defined streams */ !(entry->want_onehop) && /* ignore one-hop streams */ !(entry->use_begindir) && /* ignore targeted dir fetches */ !(entry->chosen_exit_name) && /* ignore defined streams */ !connection_edge_is_rendezvous_stream(TO_EDGE_CONN(conn)) && !circuit_stream_is_being_handled(TO_EDGE_CONN(conn), 0, !circuit_stream_is_being_handled(TO_ENTRY_CONN(conn), 0, MIN_CIRCUITS_HANDLING_STREAM)) return 1; return 0; Loading Loading @@ -2760,7 +2765,7 @@ choose_good_exit_server_general(int need_uptime, int need_capacity) SMARTLIST_FOREACH_BEGIN(connections, connection_t *, conn) { if (!ap_stream_wants_exit_attention(conn)) continue; /* Skip everything but APs in CIRCUIT_WAIT */ if (connection_ap_can_use_exit(TO_EDGE_CONN(conn), node)) { if (connection_ap_can_use_exit(TO_ENTRY_CONN(conn), node)) { ++n_supported[i]; // log_fn(LOG_DEBUG,"%s is supported. n_supported[%d] now %d.", // router->nickname, i, n_supported[i]); Loading src/or/circuituse.c +53 −44 Changes for src/or/circuituse.c: 53 added lines, 44 removed lines. Original line number Diff line number Diff line Loading @@ -41,7 +41,7 @@ static void circuit_increment_failure_count(void); */ static int circuit_is_acceptable(const origin_circuit_t *origin_circ, const edge_connection_t *conn, const entry_connection_t *conn, int must_be_open, uint8_t purpose, int need_uptime, int need_internal, time_t now) Loading Loading @@ -135,10 +135,11 @@ circuit_is_acceptable(const origin_circuit_t *origin_circ, return 0; } } else { /* not general */ if ((conn->rend_data && !origin_circ->rend_data) || (!conn->rend_data && origin_circ->rend_data) || (conn->rend_data && origin_circ->rend_data && rend_cmp_service_ids(conn->rend_data->onion_address, const edge_connection_t *edge_conn = ENTRY_TO_EDGE_CONN(conn); if ((edge_conn->rend_data && !origin_circ->rend_data) || (!edge_conn->rend_data && origin_circ->rend_data) || (edge_conn->rend_data && origin_circ->rend_data && rend_cmp_service_ids(edge_conn->rend_data->onion_address, origin_circ->rend_data->onion_address))) { /* this circ is not for this conn */ return 0; Loading @@ -159,11 +160,11 @@ circuit_is_acceptable(const origin_circuit_t *origin_circ, */ static int circuit_is_better(const origin_circuit_t *oa, const origin_circuit_t *ob, const edge_connection_t *conn) const entry_connection_t *conn) { const circuit_t *a = TO_CIRCUIT(oa); const circuit_t *b = TO_CIRCUIT(ob); const uint8_t purpose = conn->_base.purpose; const uint8_t purpose = ENTRY_TO_CONN(conn)->purpose; int a_bits, b_bits; switch (purpose) { Loading Loading @@ -241,7 +242,7 @@ circuit_is_better(const origin_circuit_t *oa, const origin_circuit_t *ob, * closest introduce-purposed circuit that you can find. */ static origin_circuit_t * circuit_get_best(const edge_connection_t *conn, circuit_get_best(const entry_connection_t *conn, int must_be_open, uint8_t purpose, int need_uptime, int need_internal) { Loading Loading @@ -544,7 +545,7 @@ circuit_remove_handled_ports(smartlist_t *needed_ports) * Else return 0. */ int circuit_stream_is_being_handled(edge_connection_t *conn, circuit_stream_is_being_handled(entry_connection_t *conn, uint16_t port, int min) { circuit_t *circ; Loading Loading @@ -738,8 +739,11 @@ circuit_detach_stream(circuit_t *circ, edge_connection_t *conn) tor_assert(circ); tor_assert(conn); conn->cpath_layer = NULL; /* make sure we don't keep a stale pointer */ conn->may_use_optimistic_data = 0; if (conn->_base.type == CONN_TYPE_AP) { entry_connection_t *entry_conn = EDGE_TO_ENTRY_CONN(conn); entry_conn->may_use_optimistic_data = 0; } conn->cpath_layer = NULL; /* don't keep a stale pointer */ conn->on_circuit = NULL; if (CIRCUIT_IS_ORIGIN(circ)) { Loading Loading @@ -1286,7 +1290,7 @@ circuit_reset_failure_count(int timeout) * Write the found or in-progress or launched circ into *circp. */ static int circuit_get_open_circ_or_launch(edge_connection_t *conn, circuit_get_open_circ_or_launch(entry_connection_t *conn, uint8_t desired_circuit_purpose, origin_circuit_t **circp) { Loading @@ -1298,11 +1302,11 @@ circuit_get_open_circ_or_launch(edge_connection_t *conn, tor_assert(conn); tor_assert(circp); tor_assert(conn->_base.state == AP_CONN_STATE_CIRCUIT_WAIT); tor_assert(ENTRY_TO_CONN(conn)->state == AP_CONN_STATE_CIRCUIT_WAIT); check_exit_policy = conn->socks_request->command == SOCKS_COMMAND_CONNECT && !conn->use_begindir && !connection_edge_is_rendezvous_stream(conn); !connection_edge_is_rendezvous_stream(ENTRY_TO_EDGE_CONN(conn)); want_onehop = conn->want_onehop; need_uptime = !conn->want_onehop && !conn->use_begindir && Loading Loading @@ -1410,19 +1414,20 @@ circuit_get_open_circ_or_launch(edge_connection_t *conn, if (desired_circuit_purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT) { /* need to pick an intro point */ tor_assert(conn->rend_data); extend_info = rend_client_get_random_intro(conn->rend_data); rend_data_t *rend_data = ENTRY_TO_EDGE_CONN(conn)->rend_data; tor_assert(rend_data); extend_info = rend_client_get_random_intro(rend_data); if (!extend_info) { log_info(LD_REND, "No intro points for '%s': re-fetching service descriptor.", safe_str_client(conn->rend_data->onion_address)); rend_client_refetch_v2_renddesc(conn->rend_data); conn->_base.state = AP_CONN_STATE_RENDDESC_WAIT; safe_str_client(rend_data->onion_address)); rend_client_refetch_v2_renddesc(rend_data); ENTRY_TO_CONN(conn)->state = AP_CONN_STATE_RENDDESC_WAIT; return 0; } log_info(LD_REND,"Chose %s as intro point for '%s'.", extend_info_describe(extend_info), safe_str_client(conn->rend_data->onion_address)); safe_str_client(rend_data->onion_address)); } /* If we have specified a particular exit node for our Loading Loading @@ -1511,7 +1516,7 @@ circuit_get_open_circ_or_launch(edge_connection_t *conn, rep_hist_note_used_internal(time(NULL), need_uptime, 1); if (circ) { /* write the service_id into circ */ circ->rend_data = rend_data_dup(conn->rend_data); circ->rend_data = rend_data_dup(ENTRY_TO_EDGE_CONN(conn)->rend_data); if (circ->_base.purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND && circ->_base.state == CIRCUIT_STATE_OPEN) rend_client_rendcirc_has_opened(circ); Loading Loading @@ -1569,7 +1574,7 @@ optimistic_data_enabled(void) * hop in circ's cpath if <b>cpath</b> is NULL. */ static void link_apconn_to_circ(edge_connection_t *apconn, origin_circuit_t *circ, link_apconn_to_circ(entry_connection_t *apconn, origin_circuit_t *circ, crypt_path_t *cpath) { const node_t *exitnode; Loading @@ -1578,29 +1583,29 @@ link_apconn_to_circ(edge_connection_t *apconn, origin_circuit_t *circ, log_debug(LD_APP|LD_CIRC, "attaching new conn to circ. n_circ_id %d.", circ->_base.n_circ_id); /* reset it, so we can measure circ timeouts */ apconn->_base.timestamp_lastread = time(NULL); apconn->next_stream = circ->p_streams; apconn->on_circuit = TO_CIRCUIT(circ); ENTRY_TO_CONN(apconn)->timestamp_lastread = time(NULL); ENTRY_TO_EDGE_CONN(apconn)->next_stream = circ->p_streams; ENTRY_TO_EDGE_CONN(apconn)->on_circuit = TO_CIRCUIT(circ); /* assert_connection_ok(conn, time(NULL)); */ circ->p_streams = apconn; circ->p_streams = ENTRY_TO_EDGE_CONN(apconn); if (cpath) { /* we were given one; use it */ tor_assert(cpath_is_on_circuit(circ, cpath)); apconn->cpath_layer = cpath; } else { /* use the last hop in the circuit */ } else { /* use the last hop in the circuit */ tor_assert(circ->cpath); tor_assert(circ->cpath->prev); tor_assert(circ->cpath->prev->state == CPATH_STATE_OPEN); apconn->cpath_layer = circ->cpath->prev; cpath = circ->cpath->prev; } ENTRY_TO_EDGE_CONN(apconn)->cpath_layer = cpath; circ->isolation_any_streams_attached = 1; connection_edge_update_circuit_isolation(apconn, circ, 0); /* See if we can use optimistic data on this circuit */ if (apconn->cpath_layer->extend_info && (exitnode = node_get_by_id( apconn->cpath_layer->extend_info->identity_digest)) && if (cpath->extend_info && (exitnode = node_get_by_id(cpath->extend_info->identity_digest)) && exitnode->rs) { /* Okay; we know what exit node this is. */ if (optimistic_data_enabled() && Loading Loading @@ -1642,7 +1647,7 @@ hostname_in_track_host_exits(const or_options_t *options, const char *address) * <b>conn</b>'s destination. */ static void consider_recording_trackhost(const edge_connection_t *conn, consider_recording_trackhost(const entry_connection_t *conn, const origin_circuit_t *circ) { const or_options_t *options = get_options(); Loading Loading @@ -1680,18 +1685,19 @@ consider_recording_trackhost(const edge_connection_t *conn, * indicated by <b>cpath</b>, or from the last hop in circ's cpath if * <b>cpath</b> is NULL. */ int connection_ap_handshake_attach_chosen_circuit(edge_connection_t *conn, connection_ap_handshake_attach_chosen_circuit(entry_connection_t *conn, origin_circuit_t *circ, crypt_path_t *cpath) { connection_t *base_conn = ENTRY_TO_CONN(conn); tor_assert(conn); tor_assert(conn->_base.state == AP_CONN_STATE_CIRCUIT_WAIT || conn->_base.state == AP_CONN_STATE_CONTROLLER_WAIT); tor_assert(base_conn->state == AP_CONN_STATE_CIRCUIT_WAIT || base_conn->state == AP_CONN_STATE_CONTROLLER_WAIT); tor_assert(conn->socks_request); tor_assert(circ); tor_assert(circ->_base.state == CIRCUIT_STATE_OPEN); conn->_base.state = AP_CONN_STATE_CIRCUIT_WAIT; base_conn->state = AP_CONN_STATE_CIRCUIT_WAIT; if (!circ->_base.timestamp_dirty) circ->_base.timestamp_dirty = time(NULL); Loading Loading @@ -1721,21 +1727,22 @@ connection_ap_handshake_attach_chosen_circuit(edge_connection_t *conn, /* XXXX this function should mark for close whenever it returns -1; * its callers shouldn't have to worry about that. */ int connection_ap_handshake_attach_circuit(edge_connection_t *conn) connection_ap_handshake_attach_circuit(entry_connection_t *conn) { connection_t *base_conn = ENTRY_TO_CONN(conn); int retval; int conn_age; int want_onehop; tor_assert(conn); tor_assert(conn->_base.state == AP_CONN_STATE_CIRCUIT_WAIT); tor_assert(base_conn->state == AP_CONN_STATE_CIRCUIT_WAIT); tor_assert(conn->socks_request); want_onehop = conn->want_onehop; conn_age = (int)(time(NULL) - conn->_base.timestamp_created); conn_age = (int)(time(NULL) - base_conn->timestamp_created); if (conn_age >= get_options()->SocksTimeout) { int severity = (tor_addr_is_null(&conn->_base.addr) && !conn->_base.port) ? int severity = (tor_addr_is_null(&base_conn->addr) && !base_conn->port) ? LOG_INFO : LOG_NOTICE; log_fn(severity, LD_APP, "Tried for %d seconds to get a connection to %s:%d. Giving up.", Loading @@ -1744,7 +1751,8 @@ connection_ap_handshake_attach_circuit(edge_connection_t *conn) return -1; } if (!connection_edge_is_rendezvous_stream(conn)) { /* we're a general conn */ if (!connection_edge_is_rendezvous_stream(ENTRY_TO_EDGE_CONN(conn))) { /* we're a general conn */ origin_circuit_t *circ=NULL; if (conn->chosen_exit_name) { Loading Loading @@ -1799,7 +1807,7 @@ connection_ap_handshake_attach_circuit(edge_connection_t *conn) } else { /* we're a rendezvous conn */ origin_circuit_t *rendcirc=NULL, *introcirc=NULL; tor_assert(!conn->cpath_layer); tor_assert(!ENTRY_TO_EDGE_CONN(conn)->cpath_layer); /* start by finding a rendezvous circuit for us */ Loading Loading @@ -1855,7 +1863,8 @@ connection_ap_handshake_attach_circuit(edge_connection_t *conn) !c->marked_for_close && CIRCUIT_IS_ORIGIN(c)) { origin_circuit_t *oc = TO_ORIGIN_CIRCUIT(c); if (oc->rend_data && !rend_cmp_service_ids(conn->rend_data->onion_address, !rend_cmp_service_ids( ENTRY_TO_EDGE_CONN(conn)->rend_data->onion_address, oc->rend_data->onion_address)) { log_info(LD_REND|LD_CIRC, "Closing introduction circuit that we " "built in parallel."); Loading src/or/circuituse.h +3 −3 Changes for src/or/circuituse.h: 3 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ void circuit_expire_building(void); void circuit_remove_handled_ports(smartlist_t *needed_ports); int circuit_stream_is_being_handled(edge_connection_t *conn, uint16_t port, int circuit_stream_is_being_handled(entry_connection_t *conn, uint16_t port, int min); #if 0 int circuit_conforms_to_options(const origin_circuit_t *circ, Loading Loading @@ -45,10 +45,10 @@ origin_circuit_t *circuit_launch_by_extend_info(uint8_t purpose, int flags); origin_circuit_t *circuit_launch(uint8_t purpose, int flags); void circuit_reset_failure_count(int timeout); int connection_ap_handshake_attach_chosen_circuit(edge_connection_t *conn, int connection_ap_handshake_attach_chosen_circuit(entry_connection_t *conn, origin_circuit_t *circ, crypt_path_t *cpath); int connection_ap_handshake_attach_circuit(edge_connection_t *conn); int connection_ap_handshake_attach_circuit(entry_connection_t *conn); int hostname_in_track_host_exits(const or_options_t *options, const char *address); Loading src/or/connection.c +41 −39 Changes for src/or/connection.c: 41 added lines, 39 removed lines. Original line number Diff line number Diff line Loading @@ -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; } Loading Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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)); Loading Loading @@ -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; } Loading Loading @@ -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); Loading Loading @@ -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) Loading Loading @@ -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)) { Loading @@ -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; } Loading Loading @@ -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); } } } Loading Loading @@ -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); Loading src/or/connection_edge.c +219 −205 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
src/or/circuitbuild.c +10 −5 Changes for src/or/circuitbuild.c: 10 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -2648,14 +2648,19 @@ node_handles_some_port(const node_t *node, smartlist_t *needed_ports) static int ap_stream_wants_exit_attention(connection_t *conn) { entry_connection_t *entry; if (conn->type != CONN_TYPE_AP) return 0; entry = TO_ENTRY_CONN(conn); if (conn->type == CONN_TYPE_AP && conn->state == AP_CONN_STATE_CIRCUIT_WAIT && !conn->marked_for_close && !(TO_EDGE_CONN(conn)->want_onehop) && /* ignore one-hop streams */ !(TO_EDGE_CONN(conn)->use_begindir) && /* ignore targeted dir fetches */ !(TO_EDGE_CONN(conn)->chosen_exit_name) && /* ignore defined streams */ !(entry->want_onehop) && /* ignore one-hop streams */ !(entry->use_begindir) && /* ignore targeted dir fetches */ !(entry->chosen_exit_name) && /* ignore defined streams */ !connection_edge_is_rendezvous_stream(TO_EDGE_CONN(conn)) && !circuit_stream_is_being_handled(TO_EDGE_CONN(conn), 0, !circuit_stream_is_being_handled(TO_ENTRY_CONN(conn), 0, MIN_CIRCUITS_HANDLING_STREAM)) return 1; return 0; Loading Loading @@ -2760,7 +2765,7 @@ choose_good_exit_server_general(int need_uptime, int need_capacity) SMARTLIST_FOREACH_BEGIN(connections, connection_t *, conn) { if (!ap_stream_wants_exit_attention(conn)) continue; /* Skip everything but APs in CIRCUIT_WAIT */ if (connection_ap_can_use_exit(TO_EDGE_CONN(conn), node)) { if (connection_ap_can_use_exit(TO_ENTRY_CONN(conn), node)) { ++n_supported[i]; // log_fn(LOG_DEBUG,"%s is supported. n_supported[%d] now %d.", // router->nickname, i, n_supported[i]); Loading
src/or/circuituse.c +53 −44 Changes for src/or/circuituse.c: 53 added lines, 44 removed lines. Original line number Diff line number Diff line Loading @@ -41,7 +41,7 @@ static void circuit_increment_failure_count(void); */ static int circuit_is_acceptable(const origin_circuit_t *origin_circ, const edge_connection_t *conn, const entry_connection_t *conn, int must_be_open, uint8_t purpose, int need_uptime, int need_internal, time_t now) Loading Loading @@ -135,10 +135,11 @@ circuit_is_acceptable(const origin_circuit_t *origin_circ, return 0; } } else { /* not general */ if ((conn->rend_data && !origin_circ->rend_data) || (!conn->rend_data && origin_circ->rend_data) || (conn->rend_data && origin_circ->rend_data && rend_cmp_service_ids(conn->rend_data->onion_address, const edge_connection_t *edge_conn = ENTRY_TO_EDGE_CONN(conn); if ((edge_conn->rend_data && !origin_circ->rend_data) || (!edge_conn->rend_data && origin_circ->rend_data) || (edge_conn->rend_data && origin_circ->rend_data && rend_cmp_service_ids(edge_conn->rend_data->onion_address, origin_circ->rend_data->onion_address))) { /* this circ is not for this conn */ return 0; Loading @@ -159,11 +160,11 @@ circuit_is_acceptable(const origin_circuit_t *origin_circ, */ static int circuit_is_better(const origin_circuit_t *oa, const origin_circuit_t *ob, const edge_connection_t *conn) const entry_connection_t *conn) { const circuit_t *a = TO_CIRCUIT(oa); const circuit_t *b = TO_CIRCUIT(ob); const uint8_t purpose = conn->_base.purpose; const uint8_t purpose = ENTRY_TO_CONN(conn)->purpose; int a_bits, b_bits; switch (purpose) { Loading Loading @@ -241,7 +242,7 @@ circuit_is_better(const origin_circuit_t *oa, const origin_circuit_t *ob, * closest introduce-purposed circuit that you can find. */ static origin_circuit_t * circuit_get_best(const edge_connection_t *conn, circuit_get_best(const entry_connection_t *conn, int must_be_open, uint8_t purpose, int need_uptime, int need_internal) { Loading Loading @@ -544,7 +545,7 @@ circuit_remove_handled_ports(smartlist_t *needed_ports) * Else return 0. */ int circuit_stream_is_being_handled(edge_connection_t *conn, circuit_stream_is_being_handled(entry_connection_t *conn, uint16_t port, int min) { circuit_t *circ; Loading Loading @@ -738,8 +739,11 @@ circuit_detach_stream(circuit_t *circ, edge_connection_t *conn) tor_assert(circ); tor_assert(conn); conn->cpath_layer = NULL; /* make sure we don't keep a stale pointer */ conn->may_use_optimistic_data = 0; if (conn->_base.type == CONN_TYPE_AP) { entry_connection_t *entry_conn = EDGE_TO_ENTRY_CONN(conn); entry_conn->may_use_optimistic_data = 0; } conn->cpath_layer = NULL; /* don't keep a stale pointer */ conn->on_circuit = NULL; if (CIRCUIT_IS_ORIGIN(circ)) { Loading Loading @@ -1286,7 +1290,7 @@ circuit_reset_failure_count(int timeout) * Write the found or in-progress or launched circ into *circp. */ static int circuit_get_open_circ_or_launch(edge_connection_t *conn, circuit_get_open_circ_or_launch(entry_connection_t *conn, uint8_t desired_circuit_purpose, origin_circuit_t **circp) { Loading @@ -1298,11 +1302,11 @@ circuit_get_open_circ_or_launch(edge_connection_t *conn, tor_assert(conn); tor_assert(circp); tor_assert(conn->_base.state == AP_CONN_STATE_CIRCUIT_WAIT); tor_assert(ENTRY_TO_CONN(conn)->state == AP_CONN_STATE_CIRCUIT_WAIT); check_exit_policy = conn->socks_request->command == SOCKS_COMMAND_CONNECT && !conn->use_begindir && !connection_edge_is_rendezvous_stream(conn); !connection_edge_is_rendezvous_stream(ENTRY_TO_EDGE_CONN(conn)); want_onehop = conn->want_onehop; need_uptime = !conn->want_onehop && !conn->use_begindir && Loading Loading @@ -1410,19 +1414,20 @@ circuit_get_open_circ_or_launch(edge_connection_t *conn, if (desired_circuit_purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT) { /* need to pick an intro point */ tor_assert(conn->rend_data); extend_info = rend_client_get_random_intro(conn->rend_data); rend_data_t *rend_data = ENTRY_TO_EDGE_CONN(conn)->rend_data; tor_assert(rend_data); extend_info = rend_client_get_random_intro(rend_data); if (!extend_info) { log_info(LD_REND, "No intro points for '%s': re-fetching service descriptor.", safe_str_client(conn->rend_data->onion_address)); rend_client_refetch_v2_renddesc(conn->rend_data); conn->_base.state = AP_CONN_STATE_RENDDESC_WAIT; safe_str_client(rend_data->onion_address)); rend_client_refetch_v2_renddesc(rend_data); ENTRY_TO_CONN(conn)->state = AP_CONN_STATE_RENDDESC_WAIT; return 0; } log_info(LD_REND,"Chose %s as intro point for '%s'.", extend_info_describe(extend_info), safe_str_client(conn->rend_data->onion_address)); safe_str_client(rend_data->onion_address)); } /* If we have specified a particular exit node for our Loading Loading @@ -1511,7 +1516,7 @@ circuit_get_open_circ_or_launch(edge_connection_t *conn, rep_hist_note_used_internal(time(NULL), need_uptime, 1); if (circ) { /* write the service_id into circ */ circ->rend_data = rend_data_dup(conn->rend_data); circ->rend_data = rend_data_dup(ENTRY_TO_EDGE_CONN(conn)->rend_data); if (circ->_base.purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND && circ->_base.state == CIRCUIT_STATE_OPEN) rend_client_rendcirc_has_opened(circ); Loading Loading @@ -1569,7 +1574,7 @@ optimistic_data_enabled(void) * hop in circ's cpath if <b>cpath</b> is NULL. */ static void link_apconn_to_circ(edge_connection_t *apconn, origin_circuit_t *circ, link_apconn_to_circ(entry_connection_t *apconn, origin_circuit_t *circ, crypt_path_t *cpath) { const node_t *exitnode; Loading @@ -1578,29 +1583,29 @@ link_apconn_to_circ(edge_connection_t *apconn, origin_circuit_t *circ, log_debug(LD_APP|LD_CIRC, "attaching new conn to circ. n_circ_id %d.", circ->_base.n_circ_id); /* reset it, so we can measure circ timeouts */ apconn->_base.timestamp_lastread = time(NULL); apconn->next_stream = circ->p_streams; apconn->on_circuit = TO_CIRCUIT(circ); ENTRY_TO_CONN(apconn)->timestamp_lastread = time(NULL); ENTRY_TO_EDGE_CONN(apconn)->next_stream = circ->p_streams; ENTRY_TO_EDGE_CONN(apconn)->on_circuit = TO_CIRCUIT(circ); /* assert_connection_ok(conn, time(NULL)); */ circ->p_streams = apconn; circ->p_streams = ENTRY_TO_EDGE_CONN(apconn); if (cpath) { /* we were given one; use it */ tor_assert(cpath_is_on_circuit(circ, cpath)); apconn->cpath_layer = cpath; } else { /* use the last hop in the circuit */ } else { /* use the last hop in the circuit */ tor_assert(circ->cpath); tor_assert(circ->cpath->prev); tor_assert(circ->cpath->prev->state == CPATH_STATE_OPEN); apconn->cpath_layer = circ->cpath->prev; cpath = circ->cpath->prev; } ENTRY_TO_EDGE_CONN(apconn)->cpath_layer = cpath; circ->isolation_any_streams_attached = 1; connection_edge_update_circuit_isolation(apconn, circ, 0); /* See if we can use optimistic data on this circuit */ if (apconn->cpath_layer->extend_info && (exitnode = node_get_by_id( apconn->cpath_layer->extend_info->identity_digest)) && if (cpath->extend_info && (exitnode = node_get_by_id(cpath->extend_info->identity_digest)) && exitnode->rs) { /* Okay; we know what exit node this is. */ if (optimistic_data_enabled() && Loading Loading @@ -1642,7 +1647,7 @@ hostname_in_track_host_exits(const or_options_t *options, const char *address) * <b>conn</b>'s destination. */ static void consider_recording_trackhost(const edge_connection_t *conn, consider_recording_trackhost(const entry_connection_t *conn, const origin_circuit_t *circ) { const or_options_t *options = get_options(); Loading Loading @@ -1680,18 +1685,19 @@ consider_recording_trackhost(const edge_connection_t *conn, * indicated by <b>cpath</b>, or from the last hop in circ's cpath if * <b>cpath</b> is NULL. */ int connection_ap_handshake_attach_chosen_circuit(edge_connection_t *conn, connection_ap_handshake_attach_chosen_circuit(entry_connection_t *conn, origin_circuit_t *circ, crypt_path_t *cpath) { connection_t *base_conn = ENTRY_TO_CONN(conn); tor_assert(conn); tor_assert(conn->_base.state == AP_CONN_STATE_CIRCUIT_WAIT || conn->_base.state == AP_CONN_STATE_CONTROLLER_WAIT); tor_assert(base_conn->state == AP_CONN_STATE_CIRCUIT_WAIT || base_conn->state == AP_CONN_STATE_CONTROLLER_WAIT); tor_assert(conn->socks_request); tor_assert(circ); tor_assert(circ->_base.state == CIRCUIT_STATE_OPEN); conn->_base.state = AP_CONN_STATE_CIRCUIT_WAIT; base_conn->state = AP_CONN_STATE_CIRCUIT_WAIT; if (!circ->_base.timestamp_dirty) circ->_base.timestamp_dirty = time(NULL); Loading Loading @@ -1721,21 +1727,22 @@ connection_ap_handshake_attach_chosen_circuit(edge_connection_t *conn, /* XXXX this function should mark for close whenever it returns -1; * its callers shouldn't have to worry about that. */ int connection_ap_handshake_attach_circuit(edge_connection_t *conn) connection_ap_handshake_attach_circuit(entry_connection_t *conn) { connection_t *base_conn = ENTRY_TO_CONN(conn); int retval; int conn_age; int want_onehop; tor_assert(conn); tor_assert(conn->_base.state == AP_CONN_STATE_CIRCUIT_WAIT); tor_assert(base_conn->state == AP_CONN_STATE_CIRCUIT_WAIT); tor_assert(conn->socks_request); want_onehop = conn->want_onehop; conn_age = (int)(time(NULL) - conn->_base.timestamp_created); conn_age = (int)(time(NULL) - base_conn->timestamp_created); if (conn_age >= get_options()->SocksTimeout) { int severity = (tor_addr_is_null(&conn->_base.addr) && !conn->_base.port) ? int severity = (tor_addr_is_null(&base_conn->addr) && !base_conn->port) ? LOG_INFO : LOG_NOTICE; log_fn(severity, LD_APP, "Tried for %d seconds to get a connection to %s:%d. Giving up.", Loading @@ -1744,7 +1751,8 @@ connection_ap_handshake_attach_circuit(edge_connection_t *conn) return -1; } if (!connection_edge_is_rendezvous_stream(conn)) { /* we're a general conn */ if (!connection_edge_is_rendezvous_stream(ENTRY_TO_EDGE_CONN(conn))) { /* we're a general conn */ origin_circuit_t *circ=NULL; if (conn->chosen_exit_name) { Loading Loading @@ -1799,7 +1807,7 @@ connection_ap_handshake_attach_circuit(edge_connection_t *conn) } else { /* we're a rendezvous conn */ origin_circuit_t *rendcirc=NULL, *introcirc=NULL; tor_assert(!conn->cpath_layer); tor_assert(!ENTRY_TO_EDGE_CONN(conn)->cpath_layer); /* start by finding a rendezvous circuit for us */ Loading Loading @@ -1855,7 +1863,8 @@ connection_ap_handshake_attach_circuit(edge_connection_t *conn) !c->marked_for_close && CIRCUIT_IS_ORIGIN(c)) { origin_circuit_t *oc = TO_ORIGIN_CIRCUIT(c); if (oc->rend_data && !rend_cmp_service_ids(conn->rend_data->onion_address, !rend_cmp_service_ids( ENTRY_TO_EDGE_CONN(conn)->rend_data->onion_address, oc->rend_data->onion_address)) { log_info(LD_REND|LD_CIRC, "Closing introduction circuit that we " "built in parallel."); Loading
src/or/circuituse.h +3 −3 Changes for src/or/circuituse.h: 3 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ void circuit_expire_building(void); void circuit_remove_handled_ports(smartlist_t *needed_ports); int circuit_stream_is_being_handled(edge_connection_t *conn, uint16_t port, int circuit_stream_is_being_handled(entry_connection_t *conn, uint16_t port, int min); #if 0 int circuit_conforms_to_options(const origin_circuit_t *circ, Loading Loading @@ -45,10 +45,10 @@ origin_circuit_t *circuit_launch_by_extend_info(uint8_t purpose, int flags); origin_circuit_t *circuit_launch(uint8_t purpose, int flags); void circuit_reset_failure_count(int timeout); int connection_ap_handshake_attach_chosen_circuit(edge_connection_t *conn, int connection_ap_handshake_attach_chosen_circuit(entry_connection_t *conn, origin_circuit_t *circ, crypt_path_t *cpath); int connection_ap_handshake_attach_circuit(edge_connection_t *conn); int connection_ap_handshake_attach_circuit(entry_connection_t *conn); int hostname_in_track_host_exits(const or_options_t *options, const char *address); Loading
src/or/connection.c +41 −39 Changes for src/or/connection.c: 41 added lines, 39 removed lines. Original line number Diff line number Diff line Loading @@ -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; } Loading Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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)); Loading Loading @@ -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; } Loading Loading @@ -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); Loading Loading @@ -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) Loading Loading @@ -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)) { Loading @@ -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; } Loading Loading @@ -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); } } } Loading Loading @@ -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); Loading
src/or/connection_edge.c +219 −205 File changed.Preview size limit exceeded, changes collapsed. Show changes