Send a control port event when a stream enters the AP_CONN_STATE_CONTROLLER_WAIT state

This commit is contained in:
Neel Chauhan
2020-07-08 20:12:56 -07:00
parent e4bfa734a6
commit 60f699c859
6 changed files with 33 additions and 7 deletions
+4
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.
+12 -4
View File
@@ -1504,6 +1504,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_enter_controller_wait();
}
/** 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
@@ -1535,8 +1545,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;
@@ -1686,8 +1695,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);
+2
View File
@@ -94,6 +94,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);
+1 -2
View File
@@ -982,8 +982,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)) {
+10
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 },
};
@@ -2363,6 +2364,15 @@ control_events_free_all(void)
disable_log_messages = 0;
}
/** Our own router descriptor has changed; tell any controllers that care.
*/
int
control_event_enter_controller_wait(void)
{
send_control_event(EVENT_CONTROLLER_WAIT, "650 CONTROLLER_WAIT\r\n");
return 0;
}
#ifdef TOR_UNIT_TESTS
/* For testing: change the value of global_event_mask */
void
+4 -1
View File
@@ -226,6 +226,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 +286,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