aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2015-08-12 11:02:27 -0400
committerNick Mathewson <nickm@torproject.org>2015-08-12 11:02:27 -0400
commit23fb084cb2d7d20d906106b2eb7676f455f333e1 (patch)
treecbd6fc73e200aca8a4dde8746f6656ec272d78bd
parentda04fed865b6df09b33e6b632d51d34b3eb20d14 (diff)
parentb65d53519aa216232f81144bdfd33b19d2ec23dc (diff)
downloadtor-23fb084cb2d7d20d906106b2eb7676f455f333e1.tar.gz
tor-23fb084cb2d7d20d906106b2eb7676f455f333e1.zip
Merge branch 'ticket16762_squashed'
-rw-r--r--changes/decouple_dir_all_unreachable4
-rw-r--r--src/or/main.c44
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 0000000000..1e57b3dfbd
--- /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 e564e6c132..a29387c67a 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