From ee401e62a2f875c22c50bf5deaf9e51ccf78418d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 5 May 2020 10:42:29 +0930 Subject: [PATCH] lightningd: complete plugin state machine. Signed-off-by: Rusty Russell --- lightningd/plugin.c | 2 ++ lightningd/plugin.h | 2 ++ lightningd/plugin_control.c | 3 +++ 3 files changed, 7 insertions(+) diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 9561e2bb0..789a0632e 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -1145,6 +1145,7 @@ void plugins_init(struct plugins *plugins, const char *dev_plugin_debug) plugin_manifest_cb, p); jsonrpc_request_end(req); plugin_request_send(p, req); + p->plugin_state = AWAITING_GETMANIFEST_RESPONSE; plugins->pending_manifests++; /* Don't timeout if they're running a debugger. */ @@ -1232,6 +1233,7 @@ plugin_config(struct plugin *plugin) plugin_populate_init_request(plugin, req); jsonrpc_request_end(req); plugin_request_send(plugin, req); + plugin->plugin_state = AWAITING_INIT_RESPONSE; } void plugins_config(struct plugins *plugins) diff --git a/lightningd/plugin.h b/lightningd/plugin.h index 0d26325e9..4120f91ee 100644 --- a/lightningd/plugin.h +++ b/lightningd/plugin.h @@ -24,6 +24,8 @@ enum plugin_state { /* We have to ask getmanifest */ UNCONFIGURED, + /* We sent getmanifest, need response. */ + AWAITING_GETMANIFEST_RESPONSE, /* Got `getmanifest` reply, now we need to send `init`. */ NEEDS_INIT, /* We have to get `init` response */ diff --git a/lightningd/plugin_control.c b/lightningd/plugin_control.c index c0fdad82d..d2ab2b3ca 100644 --- a/lightningd/plugin_control.c +++ b/lightningd/plugin_control.c @@ -97,6 +97,7 @@ static void plugin_dynamic_config(struct dynamic_plugin *dp) plugin_dynamic_config_callback, dp); plugin_populate_init_request(dp->plugin, req); jsonrpc_request_end(req); + dp->plugin->plugin_state = AWAITING_INIT_RESPONSE; plugin_request_send(dp->plugin, req); } @@ -112,6 +113,7 @@ static void plugin_dynamic_manifest_callback(const char *buffer, return was_pending(plugin_dynamic_error(dp, "Not a dynamic plugin")); /* We got the manifest, now send the init message */ + dp->plugin->plugin_state = NEEDS_INIT; plugin_dynamic_config(dp); } @@ -167,6 +169,7 @@ static struct command_result *plugin_start(struct dynamic_plugin *dp) plugin_dynamic_manifest_callback, dp); jsonrpc_request_end(req); plugin_request_send(p, req); + p->plugin_state = AWAITING_GETMANIFEST_RESPONSE; return command_still_pending(dp->cmd); }