Merge remote-tracking branch 'tor-github/pr/1986/head'

This commit is contained in:
Nick Mathewson 2020-08-03 08:33:22 -04:00
commit 3e3b0b0443
6 changed files with 27 additions and 8 deletions

4
changes/ticket32190 Normal file
View file

@ -0,0 +1,4 @@
o Minor features (control port):
- When a stream enters the AP_CONN_STATE_CONTROLLER_WAIT status,
send a control port event CONTROLLER_WAIT. Closes ticket 32190.
Patch by Neel Chauhan.

View file

@ -1553,6 +1553,16 @@ circuit_discard_optional_exit_enclaves(extend_info_t *info)
} SMARTLIST_FOREACH_END(conn);
}
/** Set the connection state to CONTROLLER_WAIT and send an control port event.
*/
void
connection_entry_set_controller_wait(entry_connection_t *conn)
{
CONNECTION_AP_EXPECT_NONPENDING(conn);
ENTRY_TO_CONN(conn)->state = AP_CONN_STATE_CONTROLLER_WAIT;
control_event_stream_status(conn, STREAM_EVENT_CONTROLLER_WAIT, 0);
}
/** The AP connection <b>conn</b> has just failed while attaching or
* sending a BEGIN or resolving on <b>circ</b>, but another circuit
* might work. Detach the circuit, and either reattach it, launch a
@ -1584,8 +1594,7 @@ connection_ap_detach_retriable(entry_connection_t *conn,
circuit_detach_stream(TO_CIRCUIT(circ),ENTRY_TO_EDGE_CONN(conn));
connection_ap_mark_as_pending_circuit(conn);
} else {
CONNECTION_AP_EXPECT_NONPENDING(conn);
ENTRY_TO_CONN(conn)->state = AP_CONN_STATE_CONTROLLER_WAIT;
connection_entry_set_controller_wait(conn);
circuit_detach_stream(TO_CIRCUIT(circ),ENTRY_TO_EDGE_CONN(conn));
}
return 0;
@ -1738,8 +1747,7 @@ connection_ap_rewrite_and_attach_if_allowed,(entry_connection_t *conn,
const or_options_t *options = get_options();
if (options->LeaveStreamsUnattached) {
CONNECTION_AP_EXPECT_NONPENDING(conn);
ENTRY_TO_CONN(conn)->state = AP_CONN_STATE_CONTROLLER_WAIT;
connection_entry_set_controller_wait(conn);
return 0;
}
return connection_ap_handshake_rewrite_and_attach(conn, circ, cpath);

View file

@ -98,6 +98,8 @@ int connection_edge_flushed_some(edge_connection_t *conn);
int connection_edge_finished_flushing(edge_connection_t *conn);
int connection_edge_finished_connecting(edge_connection_t *conn);
void connection_entry_set_controller_wait(entry_connection_t *conn);
void connection_ap_about_to_close(entry_connection_t *edge_conn);
void connection_exit_about_to_close(edge_connection_t *edge_conn);

View file

@ -981,8 +981,7 @@ handle_control_attachstream(control_connection_t *conn,
edge_conn->end_reason = 0;
if (tmpcirc)
circuit_detach_stream(tmpcirc, edge_conn);
CONNECTION_AP_EXPECT_NONPENDING(ap_conn);
TO_CONN(edge_conn)->state = AP_CONN_STATE_CONTROLLER_WAIT;
connection_entry_set_controller_wait(ap_conn);
}
if (circ && (circ->base_.state != CIRCUIT_STATE_OPEN)) {

View file

@ -109,6 +109,7 @@ const struct control_event_t control_event_table[] = {
{ EVENT_HS_DESC, "HS_DESC" },
{ EVENT_HS_DESC_CONTENT, "HS_DESC_CONTENT" },
{ EVENT_NETWORK_LIVENESS, "NETWORK_LIVENESS" },
{ EVENT_CONTROLLER_WAIT, "CONTROLLER_WAIT" },
{ 0, NULL },
};
@ -818,6 +819,7 @@ control_event_stream_status(entry_connection_t *conn, stream_status_event_t tp,
case STREAM_EVENT_NEW_RESOLVE: status = "NEWRESOLVE"; break;
case STREAM_EVENT_FAILED_RETRIABLE: status = "DETACHED"; break;
case STREAM_EVENT_REMAP: status = "REMAP"; break;
case STREAM_EVENT_CONTROLLER_WAIT: status = "CONTROLLER_WAIT"; break;
default:
log_warn(LD_BUG, "Unrecognized status code %d", (int)tp);
return 0;

View file

@ -36,7 +36,8 @@ typedef enum stream_status_event_t {
STREAM_EVENT_NEW = 5,
STREAM_EVENT_NEW_RESOLVE = 6,
STREAM_EVENT_FAILED_RETRIABLE = 7,
STREAM_EVENT_REMAP = 8
STREAM_EVENT_REMAP = 8,
STREAM_EVENT_CONTROLLER_WAIT = 9
} stream_status_event_t;
/** Used to indicate the type of a buildtime event */
@ -226,6 +227,8 @@ void control_event_hs_descriptor_content(const char *onion_address,
void cbt_control_event_buildtimeout_set(const circuit_build_times_t *cbt,
buildtimeout_set_event_t type);
int control_event_enter_controller_wait(void);
void control_events_free_all(void);
#ifdef CONTROL_MODULE_PRIVATE
@ -284,7 +287,8 @@ typedef uint64_t event_mask_t;
#define EVENT_NETWORK_LIVENESS 0x0023
#define EVENT_PT_LOG 0x0024
#define EVENT_PT_STATUS 0x0025
#define EVENT_MAX_ 0x0025
#define EVENT_CONTROLLER_WAIT 0x0026
#define EVENT_MAX_ 0x0026
/* sizeof(control_connection_t.event_mask) in bits, currently a uint64_t */
#define EVENT_CAPACITY_ 0x0040