mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
lightningd/plugin: Add a 'dynamic' field to getmanifest and a 'startup' field to init
This lets a plugin specify whether it can be restarted, and to know if it is started at lightningd startup
This commit is contained in:
@@ -99,7 +99,7 @@ class Plugin(object):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, stdout=None, stdin=None, autopatch=True):
|
def __init__(self, stdout=None, stdin=None, autopatch=True, dynamic=True):
|
||||||
self.methods = {'init': Method('init', self._init, MethodType.RPCMETHOD)}
|
self.methods = {'init': Method('init', self._init, MethodType.RPCMETHOD)}
|
||||||
self.options = {}
|
self.options = {}
|
||||||
|
|
||||||
@@ -118,6 +118,8 @@ class Plugin(object):
|
|||||||
self.rpc_filename = None
|
self.rpc_filename = None
|
||||||
self.lightning_dir = None
|
self.lightning_dir = None
|
||||||
self.rpc = None
|
self.rpc = None
|
||||||
|
self.startup = True
|
||||||
|
self.dynamic = dynamic
|
||||||
self.child_init = None
|
self.child_init = None
|
||||||
|
|
||||||
self.write_lock = RLock()
|
self.write_lock = RLock()
|
||||||
@@ -496,6 +498,7 @@ class Plugin(object):
|
|||||||
'rpcmethods': methods,
|
'rpcmethods': methods,
|
||||||
'subscriptions': list(self.subscriptions.keys()),
|
'subscriptions': list(self.subscriptions.keys()),
|
||||||
'hooks': hooks,
|
'hooks': hooks,
|
||||||
|
'dynamic': self.dynamic
|
||||||
}
|
}
|
||||||
|
|
||||||
def _init(self, options, configuration, request):
|
def _init(self, options, configuration, request):
|
||||||
@@ -503,6 +506,7 @@ class Plugin(object):
|
|||||||
self.lightning_dir = configuration['lightning-dir']
|
self.lightning_dir = configuration['lightning-dir']
|
||||||
path = os.path.join(self.lightning_dir, self.rpc_filename)
|
path = os.path.join(self.lightning_dir, self.rpc_filename)
|
||||||
self.rpc = LightningRpc(path)
|
self.rpc = LightningRpc(path)
|
||||||
|
self.startup = configuration['startup']
|
||||||
for name, value in options.items():
|
for name, value in options.items():
|
||||||
self.options[name]['value'] = value
|
self.options[name]['value'] = value
|
||||||
|
|
||||||
|
|||||||
@@ -789,7 +789,8 @@ static void plugin_manifest_cb(const char *buffer,
|
|||||||
const jsmntok_t *idtok,
|
const jsmntok_t *idtok,
|
||||||
struct plugin *plugin)
|
struct plugin *plugin)
|
||||||
{
|
{
|
||||||
const jsmntok_t *resulttok;
|
const jsmntok_t *resulttok, *dynamictok;
|
||||||
|
bool dynamic_plugin;
|
||||||
|
|
||||||
/* Check if all plugins have replied to getmanifest, and break
|
/* Check if all plugins have replied to getmanifest, and break
|
||||||
* if they have and this is the startup init */
|
* if they have and this is the startup init */
|
||||||
@@ -806,6 +807,10 @@ static void plugin_manifest_cb(const char *buffer,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dynamictok = json_get_member(buffer, resulttok, "dynamic");
|
||||||
|
if (dynamictok && json_to_bool(buffer, dynamictok, &dynamic_plugin))
|
||||||
|
plugin->dynamic = dynamic_plugin;
|
||||||
|
|
||||||
if (!plugin_opts_add(plugin, buffer, resulttok) ||
|
if (!plugin_opts_add(plugin, buffer, resulttok) ||
|
||||||
!plugin_rpcmethods_add(plugin, buffer, resulttok) ||
|
!plugin_rpcmethods_add(plugin, buffer, resulttok) ||
|
||||||
!plugin_subscriptions_add(plugin, buffer, resulttok) ||
|
!plugin_subscriptions_add(plugin, buffer, resulttok) ||
|
||||||
@@ -1014,6 +1019,7 @@ static void plugin_config(struct plugin *plugin)
|
|||||||
json_object_start(req->stream, "configuration");
|
json_object_start(req->stream, "configuration");
|
||||||
json_add_string(req->stream, "lightning-dir", ld->config_dir);
|
json_add_string(req->stream, "lightning-dir", ld->config_dir);
|
||||||
json_add_string(req->stream, "rpc-file", ld->rpc_filename);
|
json_add_string(req->stream, "rpc-file", ld->rpc_filename);
|
||||||
|
json_add_bool(req->stream, "startup", plugin->plugins->startup);
|
||||||
json_object_end(req->stream);
|
json_object_end(req->stream);
|
||||||
|
|
||||||
jsonrpc_request_end(req);
|
jsonrpc_request_end(req);
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ struct plugin {
|
|||||||
struct plugins *plugins;
|
struct plugins *plugins;
|
||||||
const char **plugin_path;
|
const char **plugin_path;
|
||||||
bool configured;
|
bool configured;
|
||||||
|
/* If this plugin can be restarted without restarting lightningd */
|
||||||
|
bool dynamic;
|
||||||
|
|
||||||
/* Stuff we read */
|
/* Stuff we read */
|
||||||
char *buffer;
|
char *buffer;
|
||||||
|
|||||||
Reference in New Issue
Block a user