Browse Source

pubsub: install libevent events separately from the_dispatcher.

Also, add documentation, and fix a free-on-error bug.
Nick Mathewson 5 years ago
parent
commit
b4f28b9df8
3 changed files with 31 additions and 5 deletions
  1. 7 0
      src/app/main/main.c
  2. 23 5
      src/core/mainloop/mainloop_pubsub.c
  3. 1 0
      src/core/mainloop/mainloop_pubsub.h

+ 7 - 0
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();
 

+ 23 - 5
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;
 }
 
 /**

+ 1 - 0
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);