plugin: Send the configure request once we collected all options

This is the final step to get the plugins working. After parsing the
early options (including `--plugin`), then starting and asking the
plugins for options, and finally reading in the options we just
registered, we just need to assemble the options and send them over.

Signed-off-by: Christian Decker <@cdecker>
This commit is contained in:
Christian Decker 2018-11-05 17:01:56 +01:00
parent 2b3059be0c
commit e6ef675ea1
3 changed files with 38 additions and 0 deletions

View File

@ -607,6 +607,11 @@ int main(int argc, char *argv[])
/*~ Handle options and config; move to .lightningd (--lightning-dir) */
handle_opts(ld, argc, argv);
/*~ Now that we have collected all the early options, gave
* plugins a chance to register theirs and collected all
* remaining options it's time to tell the plugins. */
plugins_config(ld->plugins);
/*~ Make sure we can reach the subdaemons, and versions match. */
test_subdaemons(ld);

View File

@ -413,8 +413,38 @@ void plugins_init(struct plugins *plugins)
io_loop(NULL, NULL);
}
static void plugin_config_cb(const struct plugin_request *req,
struct plugin *plugin)
{
/* Nothing to be done here, this is just a report */
}
/* FIXME(cdecker) This just builds a string for the request because
* the json_stream is tightly bound to the command interface. It
* should probably be generalized and fixed up. */
static void plugin_config(struct plugin *plugin)
{
struct plugin_opt *opt;
bool first = true;
const char *name, *sep;
char *conf = tal_fmt(tmpctx, "{\n \"options\": {");
list_for_each(&plugin->plugin_opts, opt, list) {
/* Trim the `--` that we added before */
name = opt->name + 2;
/* Separator between elements in the same object */
sep = first?"":",";
first = false;
tal_append_fmt(&conf, "%s\n \"%s\": \"%s\"", sep, name, opt->value);
}
tal_append_fmt(&conf, "\n }\n}");
plugin_request_send(plugin, "configure", conf, plugin_config_cb, plugin);
}
void plugins_config(struct plugins *plugins)
{
for (size_t i=0; i<tal_count(plugins->plugins); i++) {
plugin_config(plugins->plugins[i]);
}
}
void json_add_opt_plugins(struct json_stream *response,

View File

@ -122,6 +122,9 @@ struct chain_topology *new_topology(struct lightningd *ld UNNEEDED, struct log *
/* Generated stub for onchaind_replay_channels */
void onchaind_replay_channels(struct lightningd *ld UNNEEDED)
{ fprintf(stderr, "onchaind_replay_channels called!\n"); abort(); }
/* Generated stub for plugins_config */
void plugins_config(struct plugins *plugins UNNEEDED)
{ fprintf(stderr, "plugins_config called!\n"); abort(); }
/* Generated stub for plugins_init */
void plugins_init(struct plugins *plugins UNNEEDED)
{ fprintf(stderr, "plugins_init called!\n"); abort(); }