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

[tor-commits] [tor/master] Decouple the backend for directory_all_unreachable to simplify our CFG



commit b65d53519aa216232f81144bdfd33b19d2ec23dc
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Tue Aug 11 09:58:30 2015 -0400

    Decouple the backend for directory_all_unreachable to simplify our CFG
    
    See ticket 16762.
---
 changes/decouple_dir_all_unreachable |    4 ++++
 src/or/main.c                        |   44 ++++++++++++++++++++++++++--------
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/changes/decouple_dir_all_unreachable b/changes/decouple_dir_all_unreachable
new file mode 100644
index 0000000..1e57b3d
--- /dev/null
+++ b/changes/decouple_dir_all_unreachable
@@ -0,0 +1,4 @@
+  o Code simplification and refactoring:
+    - Simply the control graph further by deferring the inner body of
+      directory_all_unreachable() into a callback. Closes ticket
+      16762.
\ No newline at end of file
diff --git a/src/or/main.c b/src/or/main.c
index e564e6c..a29387c 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -982,19 +982,18 @@ conn_close_if_marked(int i)
   return 1;
 }
 
-/** We've just tried every dirserver we know about, and none of
- * them were reachable. Assume the network is down. Change state
- * so next time an application connection arrives we'll delay it
- * and try another directory fetch. Kill off all the circuit_wait
- * streams that are waiting now, since they will all timeout anyway.
+/** Implementation for directory_all_unreachable.  This is done in a callback,
+ * since otherwise it would complicate Tor's control-flow graph beyond all
+ * reason.
  */
-void
-directory_all_unreachable(time_t now)
+static void
+directory_all_unreachable_cb(evutil_socket_t fd, short event, void *arg)
 {
-  connection_t *conn;
-  (void)now;
+  (void)fd;
+  (void)event;
+  (void)arg;
 
-  stats_n_seconds_working=0; /* reset it */
+  connection_t *conn;
 
   while ((conn = connection_get_by_type_state(CONN_TYPE_AP,
                                               AP_CONN_STATE_CIRCUIT_WAIT))) {
@@ -1010,6 +1009,31 @@ directory_all_unreachable(time_t now)
   control_event_general_status(LOG_ERR, "DIR_ALL_UNREACHABLE");
 }
 
+static struct event *directory_all_unreachable_cb_event = NULL;
+
+/** We've just tried every dirserver we know about, and none of
+ * them were reachable. Assume the network is down. Change state
+ * so next time an application connection arrives we'll delay it
+ * and try another directory fetch. Kill off all the circuit_wait
+ * streams that are waiting now, since they will all timeout anyway.
+ */
+void
+directory_all_unreachable(time_t now)
+{
+  (void)now;
+
+  stats_n_seconds_working=0; /* reset it */
+
+  if (!directory_all_unreachable_cb_event) {
+    directory_all_unreachable_cb_event =
+      tor_event_new(tor_libevent_get_base(),
+                    -1, EV_READ, directory_all_unreachable_cb, NULL);
+    tor_assert(directory_all_unreachable_cb_event);
+  }
+
+  event_active(directory_all_unreachable_cb_event, EV_READ, 1);
+}
+
 /** This function is called whenever we successfully pull down some new
  * network statuses or server descriptors. */
 void



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