From 59e37c12cdccdab337f694ac70dc985195f7080b Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 20 Sep 2018 13:46:50 +0200 Subject: [PATCH] plugin: Add plugins to lightningd and register arguments --- doc/lightningd-config.5 | 5 +++++ doc/lightningd-config.5.txt | 5 +++++ lightningd/lightningd.c | 8 ++++++++ lightningd/lightningd.h | 3 +++ lightningd/options.c | 15 +++++++++++++++ lightningd/test/run-find_my_abspath.c | 3 +++ 6 files changed, 39 insertions(+) diff --git a/doc/lightningd-config.5 b/doc/lightningd-config.5 index 5ff42ab9c..921e0f226 100644 --- a/doc/lightningd-config.5 +++ b/doc/lightningd-config.5 @@ -176,6 +176,11 @@ Sets configuration file (default: \fIPATH\fR must exist and be readable (we allow missing files in the default case)\&. Using this inside a configuration file is meaningless\&. .RE +.PP +\fBplugin\fR=\fIPATH\fR +.RS 4 +Specify a plugin to run as part of c\-lightning\&. This can be specified multiple times and may enable additional configuration options and JSON\-RPC methods, depending on the plugin\&. +.RE .sp Lightning node customization options: .PP diff --git a/doc/lightningd-config.5.txt b/doc/lightningd-config.5.txt index 74fdaf856..870c20795 100644 --- a/doc/lightningd-config.5.txt +++ b/doc/lightningd-config.5.txt @@ -124,6 +124,11 @@ Lightning daemon options: (we allow missing files in the default case). Using this inside a configuration file is meaningless. +*plugin*='PATH':: + Specify a plugin to run as part of c-lightning. This can be specified + multiple times and may enable additional configuration options and JSON-RPC + methods, depending on the plugin. + Lightning node customization options: *rgb*='RRGGBB':: diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index cc9820163..950d520be 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -211,6 +211,14 @@ static struct lightningd *new_lightningd(const tal_t *ctx) ld->tor_service_password = NULL; ld->max_funding_unconfirmed = 2016; + /*~ We run a number of plugins (subprocesses that we talk JSON-RPC with) + *alongside this process. This allows us to have an easy way for users + *to add their own tools without having to modify the c-lightning source + *code. Here we initialize the context that will keep track and control + *the plugins. + */ + ld->plugins = plugins_new(ld); + return ld; } diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index 9a52dd8a6..4ae38849e 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -203,6 +204,8 @@ struct lightningd { bool use_proxy_always; char *tor_service_password; bool pure_tor_setup; + + struct plugins *plugins; }; const struct chainparams *get_chainparams(const struct lightningd *ld); diff --git a/lightningd/options.c b/lightningd/options.c index e66600a9e..22ecdd4bc 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -286,11 +287,23 @@ static char *opt_add_proxy_addr(const char *arg, struct lightningd *ld) return NULL; } +static char *opt_add_plugin(const char *arg, struct lightningd *ld) +{ + plugin_register(ld->plugins, arg); + return NULL; +} + static void config_register_opts(struct lightningd *ld) { opt_register_early_arg("--conf=", opt_set_talstr, NULL, &ld->config_filename, "Specify configuration file. Relative paths will be prefixed by lightning-dir location. (default: config)"); + + /* Register plugins as an early argc, so we can initialize them and have + * them register more command line options */ + opt_register_early_arg("--plugin", opt_add_plugin, NULL, ld, + "Add a plugin to be run."); + opt_register_noarg("--daemon", opt_set_bool, &ld->daemon, "Run in the background, suppress stdout/stderr"); opt_register_arg("--ignore-fee-limits", opt_set_bool_arg, opt_show_bool, @@ -957,6 +970,8 @@ static void add_config(struct lightningd *ld, } else if (opt->cb_arg == (void *)opt_add_proxy_addr) { if (ld->proxyaddr) answer = fmt_wireaddr(name0, ld->proxyaddr); + } else if (opt->cb_arg == (void *)opt_add_plugin) { + /* FIXME: Actually add the plugin options */ #if DEVELOPER } else if (strstarts(name, "dev-")) { /* Ignore dev settings */ diff --git a/lightningd/test/run-find_my_abspath.c b/lightningd/test/run-find_my_abspath.c index c13f9fd21..8b0ed1177 100644 --- a/lightningd/test/run-find_my_abspath.c +++ b/lightningd/test/run-find_my_abspath.c @@ -119,6 +119,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_new */ +struct plugins *plugins_new(const tal_t *ctx UNNEEDED) +{ fprintf(stderr, "plugins_new called!\n"); abort(); } /* Generated stub for register_opts */ void register_opts(struct lightningd *ld UNNEEDED) { fprintf(stderr, "register_opts called!\n"); abort(); }