[tor-commits] [tor/master] pubsub: install libevent events separately from the_dispatcher.
asn at torproject.org
asn at torproject.org
Wed Mar 27 12:31:31 UTC 2019
commit b4f28b9df8188af82a0140b1831ee4b50c6e4f6d
Author: Nick Mathewson <nickm at torproject.org>
Date: Mon Mar 11 16:57:33 2019 -0400
pubsub: install libevent events separately from the_dispatcher.
Also, add documentation, and fix a free-on-error bug.
---
src/app/main/main.c | 7 +++++++
src/core/mainloop/mainloop_pubsub.c | 28 +++++++++++++++++++++++-----
src/core/mainloop/mainloop_pubsub.h | 1 +
3 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/src/app/main/main.c b/src/app/main/main.c
index 7bf9d3fe2..e0f635287 100644
--- a/src/app/main/main.c
+++ b/src/app/main/main.c
@@ -1428,6 +1428,13 @@ tor_run_main(const tor_main_configuration_t *tor_cfg)
}
}
+ if (get_options()->command == CMD_RUN_TOR) {
+ tor_mainloop_connect_pubsub_events();
+ /* XXXX For each pubsub channel, its delivery strategy should be set at
+ * this XXXX point, using tor_mainloop_set_delivery_strategy().
+ */
+ }
+
if (get_options()->Sandbox && get_options()->command == CMD_RUN_TOR) {
sandbox_cfg_t* cfg = sandbox_init_filter();
diff --git a/src/core/mainloop/mainloop_pubsub.c b/src/core/mainloop/mainloop_pubsub.c
index ab3614ae0..aac607126 100644
--- a/src/core/mainloop/mainloop_pubsub.c
+++ b/src/core/mainloop/mainloop_pubsub.c
@@ -44,6 +44,9 @@ flush_channel_event(mainloop_event_t *ev, void *arg)
dispatch_flush(the_dispatcher, chan, INT_MAX);
}
+/**
+ * Construct our global pubsub object from <b>builder</b>. Return 0 on
+ * success, -1 on failure. */
int
tor_mainloop_connect_pubsub(struct pubsub_builder_t *builder)
{
@@ -54,6 +57,26 @@ tor_mainloop_connect_pubsub(struct pubsub_builder_t *builder)
if (! the_dispatcher)
goto err;
+ rv = 0;
+ goto done;
+ err:
+ tor_mainloop_disconnect_pubsub();
+ done:
+ return rv;
+}
+
+/**
+ * Install libevent events for all of the pubsub channels.
+ *
+ * Invoke this after tor_mainloop_connect_pubsub, and after libevent has been
+ * initialized.
+ */
+void
+tor_mainloop_connect_pubsub_events(void)
+{
+ tor_assert(the_dispatcher);
+ tor_assert(! alert_events);
+
const size_t num_channels = get_num_channel_ids();
alert_events = smartlist_new();
for (size_t i = 0; i < num_channels; ++i) {
@@ -61,11 +84,6 @@ tor_mainloop_connect_pubsub(struct pubsub_builder_t *builder)
mainloop_event_postloop_new(flush_channel_event,
(void*)(uintptr_t)(i)));
}
-
- rv = 0;
- err:
- tor_mainloop_disconnect_pubsub();
- return rv;
}
/**
diff --git a/src/core/mainloop/mainloop_pubsub.h b/src/core/mainloop/mainloop_pubsub.h
index 6eff77842..a31b2b4ba 100644
--- a/src/core/mainloop/mainloop_pubsub.h
+++ b/src/core/mainloop/mainloop_pubsub.h
@@ -16,6 +16,7 @@ typedef enum {
} deliv_strategy_t;
int tor_mainloop_connect_pubsub(struct pubsub_builder_t *builder);
+void tor_mainloop_connect_pubsub_events(void);
int tor_mainloop_set_delivery_strategy(const char *msg_channel_name,
deliv_strategy_t strategy);
void tor_mainloop_disconnect_pubsub(void);
More information about the tor-commits
mailing list