mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
lightningd: wire plugin command JSON id through to plugin commands.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -1701,7 +1701,7 @@ static void plugin_set_timeout(struct plugin *p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *plugin_send_getmanifest(struct plugin *p)
|
const char *plugin_send_getmanifest(struct plugin *p, const char *cmd_id)
|
||||||
{
|
{
|
||||||
char **cmd;
|
char **cmd;
|
||||||
int stdinfd, stdoutfd;
|
int stdinfd, stdoutfd;
|
||||||
@@ -1730,8 +1730,7 @@ const char *plugin_send_getmanifest(struct plugin *p)
|
|||||||
* write-only on p->stdin */
|
* write-only on p->stdin */
|
||||||
p->stdout_conn = io_new_conn(p, stdoutfd, plugin_stdout_conn_init, p);
|
p->stdout_conn = io_new_conn(p, stdoutfd, plugin_stdout_conn_init, p);
|
||||||
p->stdin_conn = io_new_conn(p, stdinfd, plugin_stdin_conn_init, p);
|
p->stdin_conn = io_new_conn(p, stdinfd, plugin_stdin_conn_init, p);
|
||||||
/* FIXME: id_prefix from caller! */
|
req = jsonrpc_request_start(p, "getmanifest", cmd_id, p->log,
|
||||||
req = jsonrpc_request_start(p, "getmanifest", NULL, p->log,
|
|
||||||
NULL, plugin_manifest_cb, p);
|
NULL, plugin_manifest_cb, p);
|
||||||
json_add_bool(req->stream, "allow-deprecated-apis", deprecated_apis);
|
json_add_bool(req->stream, "allow-deprecated-apis", deprecated_apis);
|
||||||
jsonrpc_request_end(req);
|
jsonrpc_request_end(req);
|
||||||
@@ -1742,7 +1741,7 @@ const char *plugin_send_getmanifest(struct plugin *p)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool plugins_send_getmanifest(struct plugins *plugins)
|
bool plugins_send_getmanifest(struct plugins *plugins, const char *cmd_id)
|
||||||
{
|
{
|
||||||
struct plugin *p, *next;
|
struct plugin *p, *next;
|
||||||
bool sent = false;
|
bool sent = false;
|
||||||
@@ -1753,7 +1752,7 @@ bool plugins_send_getmanifest(struct plugins *plugins)
|
|||||||
|
|
||||||
if (p->plugin_state != UNCONFIGURED)
|
if (p->plugin_state != UNCONFIGURED)
|
||||||
continue;
|
continue;
|
||||||
err = plugin_send_getmanifest(p);
|
err = plugin_send_getmanifest(p, cmd_id);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
sent = true;
|
sent = true;
|
||||||
continue;
|
continue;
|
||||||
@@ -1795,7 +1794,7 @@ void plugins_init(struct plugins *plugins)
|
|||||||
setenv("LIGHTNINGD_PLUGIN", "1", 1);
|
setenv("LIGHTNINGD_PLUGIN", "1", 1);
|
||||||
setenv("LIGHTNINGD_VERSION", version(), 1);
|
setenv("LIGHTNINGD_VERSION", version(), 1);
|
||||||
|
|
||||||
if (plugins_send_getmanifest(plugins)) {
|
if (plugins_send_getmanifest(plugins, NULL)) {
|
||||||
void *ret;
|
void *ret;
|
||||||
ret = io_loop_with_timers(plugins->ld);
|
ret = io_loop_with_timers(plugins->ld);
|
||||||
log_debug(plugins->ld->log, "io_loop_with_timers: %s", __func__);
|
log_debug(plugins->ld->log, "io_loop_with_timers: %s", __func__);
|
||||||
|
|||||||
@@ -214,17 +214,19 @@ bool plugin_blacklisted(struct plugins *plugins, const char *name);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Kick off initialization of a plugin.
|
* Kick off initialization of a plugin.
|
||||||
|
* @p: plugin
|
||||||
|
* @cmd_id: optional JSON cmd_id which caused this.
|
||||||
*
|
*
|
||||||
* Returns error string, or NULL.
|
* Returns error string, or NULL.
|
||||||
*/
|
*/
|
||||||
const char *plugin_send_getmanifest(struct plugin *p);
|
const char *plugin_send_getmanifest(struct plugin *p, const char *cmd_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kick of initialization of all plugins which need it/
|
* Kick of initialization of all plugins which need it/
|
||||||
*
|
*
|
||||||
* Return true if any were started.
|
* Return true if any were started.
|
||||||
*/
|
*/
|
||||||
bool plugins_send_getmanifest(struct plugins *plugins);
|
bool plugins_send_getmanifest(struct plugins *plugins, const char *cmd_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kill a plugin process and free @plugin, with an error message.
|
* Kill a plugin process and free @plugin, with an error message.
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ plugin_dynamic_start(struct plugin_command *pcmd, const char *plugin_path,
|
|||||||
errno ? strerror(errno) : "already registered");
|
errno ? strerror(errno) : "already registered");
|
||||||
|
|
||||||
/* This will come back via plugin_cmd_killed or plugin_cmd_succeeded */
|
/* This will come back via plugin_cmd_killed or plugin_cmd_succeeded */
|
||||||
err = plugin_send_getmanifest(p);
|
err = plugin_send_getmanifest(p, pcmd->cmd->id);
|
||||||
if (err)
|
if (err)
|
||||||
return command_fail(pcmd->cmd, PLUGIN_ERROR,
|
return command_fail(pcmd->cmd, PLUGIN_ERROR,
|
||||||
"%s: %s",
|
"%s: %s",
|
||||||
@@ -103,7 +103,7 @@ plugin_dynamic_startdir(struct plugin_command *pcmd, const char *dir_path)
|
|||||||
if (res)
|
if (res)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
plugins_send_getmanifest(pcmd->cmd->ld->plugins);
|
plugins_send_getmanifest(pcmd->cmd->ld->plugins, pcmd->cmd->id);
|
||||||
return command_still_pending(pcmd->cmd);
|
return command_still_pending(pcmd->cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ plugin_dynamic_rescan_plugins(struct plugin_command *pcmd)
|
|||||||
if (res)
|
if (res)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
plugins_send_getmanifest(pcmd->cmd->ld->plugins);
|
plugins_send_getmanifest(pcmd->cmd->ld->plugins, pcmd->cmd->id);
|
||||||
return command_still_pending(pcmd->cmd);
|
return command_still_pending(pcmd->cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1486,6 +1486,9 @@ def test_libplugin(node_factory):
|
|||||||
l1.rpc.plugin_start(plugin)
|
l1.rpc.plugin_start(plugin)
|
||||||
l1.rpc.check("helloworld")
|
l1.rpc.check("helloworld")
|
||||||
|
|
||||||
|
# Side note: getmanifest will trace back to plugin_start
|
||||||
|
l1.daemon.wait_for_log(": OUT:id=[0-9]*/cln:getmanifest#[0-9]*")
|
||||||
|
|
||||||
# Test commands
|
# Test commands
|
||||||
assert l1.rpc.call("helloworld") == {"hello": "world"}
|
assert l1.rpc.call("helloworld") == {"hello": "world"}
|
||||||
assert l1.rpc.call("helloworld", {"name": "test"}) == {"hello": "test"}
|
assert l1.rpc.call("helloworld", {"name": "test"}) == {"hello": "test"}
|
||||||
|
|||||||
Reference in New Issue
Block a user