Commit Graph

74 Commits

Author SHA1 Message Date
Rusty Russell 8b2a84a0c7 plugins: don't hand empty strings for unset options.
This was deeply surprising to me; there's a difference between a value not being
specified, and it being specified as "".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-05-22 00:18:29 +02:00
darosior a497295f92 Add a default 'plugins' directory in the lightning dir
Automatically load all plugins from 'lightning_dir/plugins' (setting them as plugin_dir)
2019-05-21 07:05:43 +00:00
Rusty Russell 3729ad9914 plugin: plugin_exclusive_loop helper to service one plugin synchronously.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-04-08 01:56:17 +00:00
lisa neigut f48fe03815 plugins: patch in empty string when no default given
If a plugin fails to pass in a default value for an option,
c-lightning crashes. this fixes the crash.

Patches #2515
2019-03-31 20:07:27 +02:00
Michael Schmoock 6f71564bdd fix: missing closedir in plugin.c 2019-03-06 23:27:07 +00:00
Rusty Russell e3bdc32ee8 plugin: give *some* clue in the logs of getmanifest raises an exception!
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-25 21:45:21 +00:00
Rusty Russell 53423e8a55 lightningd: re-enable IO logging for JSON output.
Hex format is terrible, but sometimes it's the only way to tell WTF is
going on.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-21 00:44:57 +00:00
Richard Bondi 503360143a fix crash with lightning charge and plugin opts (#2358)
* fix crash with lightning charge and plugin opts
2019-02-17 21:44:10 +01:00
Rusty Russell 53c0a21d2c plugins: get usage from plugins (required unless deprecated_apis == True).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-07 20:33:50 +00:00
Rusty Russell 5770e0c700 jsonrpc: probe sites for usage information once, at start.
We store it in a strmap.  This means we call the jsonrpc handler earlier,
so all callers need to call param() before they do anything else; only
json_listaddrs and json_help needed fixing.

Plugins still use '[usage]' for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-07 20:33:50 +00:00
Rusty Russell c506d42679 plugins: don't keep redundant jsonrpc pointer.
We have ld already, just use that in the one place we need.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-07 20:33:50 +00:00
Rusty Russell cc76416447 jsonrpc: use tal destructor to remove json commands when required.
This fixes a bug with a plugin duplicating an existing name
where we'd crash, too.

This doesn't work for builtins, which aren't tal objects, so
create a separate path for them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-07 20:33:50 +00:00
Christian Decker c78d7e0f95 plugin: Increase manifest timeout to 60 seconds
Valgrind seems to be slowing the pay-plugin down enough for the 10
seconds timeout to get triggered on a semi-regular basis.

Reported-by: Rusty Russell <@rustyrussell>
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-01-20 03:06:03 +00:00
Christian Decker a2fa0788fc plugin: Remove plugin_request_new and expose plugin_request_send
plugin_request_new did nothing special aside from registering the
request ID with the dispatch code. This duty has now been moved to
plugin_request_send instead, which is also exposed so we can use that
code in plugin_hook.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-01-17 05:42:49 +00:00
Christian Decker b8584a744b plugin: Add hooks that a plugin might register
This is the first use of the `hooks` autodata field, and it required a
dummy element in order for the section not to be dropped, it'll be
removed once we have actual hooks.
2019-01-17 05:42:49 +00:00
Christian Decker ff897f8788 jsonrpc: Generalize plugin_request to jsonrpc_request
There is very little that is plugin specific in the jsonrpc_request so
this just extracts the common parts so we can reuse them outside of
the plugin compilation unit as well.
2019-01-17 05:42:49 +00:00
Christian Decker 1a952667ee plugin: Remove plugin_request argument from callbacks
None of the existing callbacks was making use of it and we will be
exposing the method callback interface to outside compilation unit
where the struct definition is not visible. So just remove it.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-01-17 05:42:49 +00:00
Conor Scott 3d270fcca6 Skip README.md when reading in plugins dir 2019-01-15 19:40:12 +00:00
Rusty Russell 26dda57cc0 utils: make tal_arr_expand safer.
Christian and I both unwittingly used it in form:

	*tal_arr_expand(&x) = tal(x, ...)

Since '=' isn't a sequence point, the compiler can (and does!) cache
the value of x, handing it to tal *after* tal_arr_expand() moves it
due to tal_resize().

The new version is somewhat less convenient to use, but doesn't have
this problem, since the assignment is always evaluated after the
resize.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-01-15 12:01:38 +01:00
Christian Decker 5813567856 plugin: Dispatch notifications to subscribed plugins
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-30 14:36:02 +01:00
Christian Decker 37b2f907d4 plugin: Make plugin_send a more generic function
This used to be request-specific, but we now want to send
notifications and requests. As a drive-by we also clarify the
ownership of the json_stream instance that is being sent.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-30 14:36:02 +01:00
Christian Decker 7355e62964 plugin: Add subscriptions when processing the plugin manifest
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-30 14:36:02 +01:00
Richard Bondi 9ca07728ad fix crash on check with plugin command 2018-12-22 14:20:15 +01:00
Rusty Russell 68bb36b210 json-rpc: make commands return 'struct command_result *'.
Usually, this means they return 'command_param_failed()' if param()
fails, and changing 'command_success(); return;' to 'return
command_success()'.

Occasionally, it's more complex: there's a command_its_complicated()
for the case where we can't exactly determine what the status is,
but it should be considered a last resort.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-20 03:22:32 +00:00
Rusty Russell 12731c4a60 json_tok_len, json_tok_contents: rename to json_tok_full_len and json_tok_full
These are only supposed to be used when you want the token contents including
surrounding "".  We should use this when reporting errors, but usually
we just want to access the tok members directly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-20 03:22:32 +00:00
Rusty Russell 22ca896b54 json: add and use a json_strdup() helper.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-20 03:22:32 +00:00
Christian Decker 2c53572798 plugin: Add missing context to tal_fmt call on error message
Seems the context parameter got lost somewhere.

Reported-by: Ulmo <@ulmo>
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-16 04:40:06 +00:00
Christian Decker 968aeac908 plugin: Set LIGHTNINGD_PLUGIN env var inform plugins
It might be useful to take special precautions inside a plugin when
being run as a plugin (and not as a standalone executable). This env
var is just set so plugins can differentiate correctly. I don't unset
the variable since it shouldn't have any effect on `lightningd`
itself.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-15 15:04:32 +01:00
Christian Decker a304db9be2 plugin: Handle log notifications from plugins
Logs are parsed and injected into the main daemon's logs.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-13 02:36:43 +00:00
Christian Decker dc25c43945 plugin: Split the parsing from the request handling in the plugin
This is a preparatory step for the next commit which adds notification
parsing as well.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-13 02:36:43 +00:00
Christian Decker 2834053457 plugin: Fix an issue with string IDs ending up quoted twice
The transparent passthrough that was recently introduced would end up
causing phantom quotes to appear around IDs when one of them was a
string. This happened for example when using `lightning-cli`, the code
would copy the quotes from the original request, insert our u64 ID,
and then re-add them on the way back as well.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-10 18:56:49 +00:00
Rusty Russell d7e233e47d Move json and param core functionality into common, for plugins.
json_escaped.[ch], param.[ch] and jsonrpc_errors.h move from lightningd/
to common/.  Tests moved too.

We add a new 'common/json_tok.[ch]' for the common parameter parsing
routines which a plugin might want, taking them out of
lightningd/json.c (which now only contains the lightningd-specific
ones).

The rest is mainly fixing up includes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-10 00:00:50 +00:00
Rusty Russell 86c517ac9b common/json: add context arg to json_parse_input.
All callers currently just hand the same arg twice, but plugins might
want this different.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-10 00:00:50 +00:00
Rusty Russell b3d30095cb lightningd/plugin: simply patch requests through and don't interpret them (much).
We simply look for the id token, and substitute it on the way in/out.
We also need to make sure output is '\n\n' terminated.

I started this because we weren't forwarding complex errors properly
(we treated them as a string), but it's also a huge simplification.

`struct plugin_rpc_request` is eliminated entirely: the information we need
is actually inside `struct command` already.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-10 00:00:50 +00:00
Rusty Russell 8015e7dcfb jsonrpc: add the obj token to the callback.
This (will) avoid the plugin having to walk back from the params object
as it currently does.

No code changes; I removed UNUSED and UNNEEDED labels from the other
parameters though (as *every* json_rpc callback needs to call param()
these days, they're *always* used).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-10 00:00:50 +00:00
Rusty Russell f653723a85 plugin: log response given by plugin if it's invalid JSON.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-10 00:00:50 +00:00
Rusty Russell fbeef504f5 plugin: preserve stderr for plugins.
Now we've updated ccan/pipecmd, we can use pipecmd_preserve to
preserve stderr for plugins so we see their error spew.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-10 00:00:50 +00:00
Rusty Russell 6da213be31 ccan: update to get updated pipecmd.
Note that this changes the order of arguments to pipecmd to match the
documentation, so we fix all the callers!

Also make configure re-run when configurator changes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-10 00:00:50 +00:00
Rusty Russell 6323cc1898 plugins: allow --dev-debugger=<pluginname>.
This currently just invokes GDB, but we could generalize it (though
pdb doesn't allow attaching to a running process, other python
debuggers seem to).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-10 00:00:50 +00:00
Rusty Russell b484933b40 plugin: simplify plugin dir test a little.
Check if it's a normal file first, then check permissions.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-10 00:00:50 +00:00
Christian Decker be7674ed6c plugin: Added .params.configuration to init call
This tells the plugin both the `lightning-dir` as well as the
`rpc-filename` to use to talk to `lightningd`. Prior to this they'd
had to guess.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-07 17:17:53 +01:00
Christian Decker bd6ce102e6 plugin: Better cleanup when a plugin fails
This used to be a use-after-free bug in which we'd free the plugin and
then still have two connections that expect to be able to operate on
the plugin. This now signals the connections to exit and cleans up
once they do.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-05 23:15:59 +00:00
Christian Decker b23a33ec7a jsonrpc: Use tal_arr_remove instead of leaving NULL in the commands
Suggested-by: Rusty Russell <@rustyrussell>
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-05 23:15:59 +00:00
Christian Decker 230730eca4 plugin: Migrate request creation to json_stream
We can use the internal buffering of the json_stream instead of
manually building JSON-RPC calls. This makes it a lot easier to handle
these requests.

Notice that we do not flush concurrently and still buffer all the
things, but it avoids double-buffering things.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-05 23:15:59 +00:00
Christian Decker dc4fb650dc plugin: Add a timeout to the `getmanifest` call
If the plugin fails to respond to we may end up hanging indefinitely,
so we limit the time we're willing to wait to 10 seconds.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-05 23:15:59 +00:00
Christian Decker 83ecb61890 plugin: Ignore directories in the plugin-directory
They pass the executable test, but aren't really executable.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-05 23:15:59 +00:00
Rusty Russell 111d6df442 plugins: make log prefix the basename.
It's not perfect if they have multiple with same name, but better than number.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-05 01:22:55 +01:00
Rusty Russell eb03b33655 plugins: add and install built-in plugin dir, add clear and disable options.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-05 01:22:55 +01:00
Rusty Russell a4287f99fd lightningd: add --plugin-dir option to load directory full of plugins.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-05 01:22:55 +01:00
Christian Decker d7e94a9386 plugin: Iterate over the options from a plugin using the tok->size
I had this really contorted way of iterating over options that could
cause valgrind to choke. This is the much more intuitive way to
iterate.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-02 22:55:47 +00:00