[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Send a control port event when a stream enters the AP_CONN_STATE_CONTROLLER_WAIT state



commit 60f699c859875b92602819c47c4a673343bee5fb
Author: Neel Chauhan <neel@xxxxxxxxx>
Date:   Wed Jul 8 20:12:56 2020 -0700

    Send a control port event when a stream enters the AP_CONN_STATE_CONTROLLER_WAIT state
---
 changes/ticket32190                  |  4 ++++
 src/core/or/connection_edge.c        | 16 ++++++++++++----
 src/core/or/connection_edge.h        |  2 ++
 src/feature/control/control_cmd.c    |  3 +--
 src/feature/control/control_events.c | 10 ++++++++++
 src/feature/control/control_events.h |  5 ++++-
 6 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/changes/ticket32190 b/changes/ticket32190
new file mode 100644
index 0000000000..a34fd51c60
--- /dev/null
+++ b/changes/ticket32190
@@ -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.
diff --git a/src/core/or/connection_edge.c b/src/core/or/connection_edge.c
index 2826a99249..5fc5f1176a 100644
--- a/src/core/or/connection_edge.c
+++ b/src/core/or/connection_edge.c
@@ -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);
diff --git a/src/core/or/connection_edge.h b/src/core/or/connection_edge.h
index 8c06af5664..12bc314b70 100644
--- a/src/core/or/connection_edge.h
+++ b/src/core/or/connection_edge.h
@@ -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);
 
diff --git a/src/feature/control/control_cmd.c b/src/feature/control/control_cmd.c
index a8926c0b79..6dc556a579 100644
--- a/src/feature/control/control_cmd.c
+++ b/src/feature/control/control_cmd.c
@@ -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)) {
diff --git a/src/feature/control/control_events.c b/src/feature/control/control_events.c
index 8e69c772f6..85936aa722 100644
--- a/src/feature/control/control_events.c
+++ b/src/feature/control/control_events.c
@@ -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
diff --git a/src/feature/control/control_events.h b/src/feature/control/control_events.h
index 0c8448e0f8..cd84fb0850 100644
--- a/src/feature/control/control_events.h
+++ b/src/feature/control/control_events.h
@@ -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



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits