diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-01-15 10:27:39 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-03-25 16:35:33 -0400 |
commit | bdeaf7d4b2929609c4d3f2ce9adfd973361ef578 (patch) | |
tree | 2742b9f39f5ab9331a54f3dd6cb932679af122cb /src/app | |
parent | 24df14eb096e73438d6045ff3b2840499a9af9b5 (diff) | |
download | tor-bdeaf7d4b2929609c4d3f2ce9adfd973361ef578.tar.gz tor-bdeaf7d4b2929609c4d3f2ce9adfd973361ef578.zip |
Code to manage publish/subscribe setup via subsystem interface.
This commit has the necessary logic to run the publish/subscribe
system from the mainloop, and to initialize it on startup and tear
it down later.
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/main/subsysmgr.c | 52 | ||||
-rw-r--r-- | src/app/main/subsysmgr.h | 5 |
2 files changed, 56 insertions, 1 deletions
diff --git a/src/app/main/subsysmgr.c b/src/app/main/subsysmgr.c index abd2edd10b..91a567ce0b 100644 --- a/src/app/main/subsysmgr.c +++ b/src/app/main/subsysmgr.c @@ -5,9 +5,14 @@ #include "orconfig.h" #include "app/main/subsysmgr.h" -#include "lib/err/torerr.h" +#include "lib/dispatch/dispatch_naming.h" +#include "lib/dispatch/msgtypes.h" +#include "lib/err/torerr.h" #include "lib/log/log.h" +#include "lib/malloc/malloc.h" +#include "lib/pubsub/pubsub_build.h" +#include "lib/pubsub/pubsub_connect.h" #include <stdio.h> #include <stdlib.h> @@ -106,6 +111,51 @@ subsystems_init_upto(int target_level) } /** + * Add publish/subscribe relationships to <b>builder</b> for all + * initialized subsystems of level no more than <b>target_level</b>. + **/ +int +subsystems_add_pubsub_upto(pubsub_builder_t *builder, + int target_level) +{ + for (unsigned i = 0; i < n_tor_subsystems; ++i) { + const subsys_fns_t *sys = tor_subsystems[i]; + if (!sys->supported) + continue; + if (sys->level > target_level) + break; + if (! sys_initialized[i]) + continue; + int r = 0; + if (sys->add_pubsub) { + subsys_id_t sysid = get_subsys_id(sys->name); + raw_assert(sysid != ERROR_ID); + pubsub_connector_t *connector; + connector = pubsub_connector_for_subsystem(builder, sysid); + r = sys->add_pubsub(connector); + pubsub_connector_free(connector); + } + if (r < 0) { + fprintf(stderr, "BUG: subsystem %s (at %u) could not connect to " + "publish/subscribe system.", sys->name, sys->level); + raw_assert_unreached_msg("A subsystem couldn't be connected."); + } + } + + return 0; +} + +/** + * Add publish/subscribe relationships to <b>builder</b> for all + * initialized subsystems. + **/ +int +subsystems_add_pubsub(pubsub_builder_t *builder) +{ + return subsystems_add_pubsub_upto(builder, MAX_SUBSYS_LEVEL); +} + +/** * Shut down all the subsystems. **/ void diff --git a/src/app/main/subsysmgr.h b/src/app/main/subsysmgr.h index 4b3cad62ad..4878cf8c36 100644 --- a/src/app/main/subsysmgr.h +++ b/src/app/main/subsysmgr.h @@ -14,6 +14,11 @@ extern const unsigned n_tor_subsystems; int subsystems_init(void); int subsystems_init_upto(int level); +struct pubsub_builder_t; +int subsystems_add_pubsub_upto(struct pubsub_builder_t *builder, + int target_level); +int subsystems_add_pubsub(struct pubsub_builder_t *builder); + void subsystems_shutdown(void); void subsystems_shutdown_downto(int level); |