mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
libplugin: demarshal and stash the feature set given by lightningd.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
#include <ccan/read_write_all/read_write_all.h>
|
#include <ccan/read_write_all/read_write_all.h>
|
||||||
#include <ccan/tal/str/str.h>
|
#include <ccan/tal/str/str.h>
|
||||||
#include <common/daemon.h>
|
#include <common/daemon.h>
|
||||||
|
#include <common/features.h>
|
||||||
#include <common/json_stream.h>
|
#include <common/json_stream.h>
|
||||||
#include <common/utils.h>
|
#include <common/utils.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -82,6 +83,9 @@ struct plugin {
|
|||||||
/* Timers */
|
/* Timers */
|
||||||
struct timers timers;
|
struct timers timers;
|
||||||
size_t in_timer;
|
size_t in_timer;
|
||||||
|
|
||||||
|
/* Feature set for lightningd */
|
||||||
|
struct feature_set *fset;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -148,6 +152,11 @@ jsonrpc_request_start_(struct plugin *plugin, struct command *cmd,
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const struct feature_set *plugin_feature_set(const struct plugin *p)
|
||||||
|
{
|
||||||
|
return p->fset;
|
||||||
|
}
|
||||||
|
|
||||||
static void jsonrpc_finish_and_send(struct plugin *p, struct json_stream *js)
|
static void jsonrpc_finish_and_send(struct plugin *p, struct json_stream *js)
|
||||||
{
|
{
|
||||||
json_object_compat_end(js);
|
json_object_compat_end(js);
|
||||||
@@ -710,11 +719,37 @@ static struct io_plan *rpc_conn_init(struct io_conn *conn,
|
|||||||
rpc_conn_write_request(conn, plugin));
|
rpc_conn_write_request(conn, plugin));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct feature_set *json_to_feature_set(struct plugin *plugin,
|
||||||
|
const char *buf,
|
||||||
|
const jsmntok_t *features)
|
||||||
|
{
|
||||||
|
struct feature_set *fset = talz(plugin, struct feature_set);
|
||||||
|
const jsmntok_t *t;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
json_for_each_obj(i, t, features) {
|
||||||
|
enum feature_place p;
|
||||||
|
if (json_tok_streq(buf, t, "init"))
|
||||||
|
p = INIT_FEATURE;
|
||||||
|
else if (json_tok_streq(buf, t, "node"))
|
||||||
|
p = NODE_ANNOUNCE_FEATURE;
|
||||||
|
else if (json_tok_streq(buf, t, "channel"))
|
||||||
|
p = CHANNEL_FEATURE;
|
||||||
|
else if (json_tok_streq(buf, t, "invoice"))
|
||||||
|
p = BOLT11_FEATURE;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
fset->bits[p] = json_tok_bin_from_hex(fset, buf, t + 1);
|
||||||
|
}
|
||||||
|
return fset;
|
||||||
|
}
|
||||||
|
|
||||||
static struct command_result *handle_init(struct command *cmd,
|
static struct command_result *handle_init(struct command *cmd,
|
||||||
const char *buf,
|
const char *buf,
|
||||||
const jsmntok_t *params)
|
const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
const jsmntok_t *configtok, *rpctok, *dirtok, *opttok, *nettok, *t;
|
const jsmntok_t *configtok, *rpctok, *dirtok, *opttok, *nettok, *fsettok,
|
||||||
|
*t;
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
size_t i;
|
size_t i;
|
||||||
char *dir, *network;
|
char *dir, *network;
|
||||||
@@ -734,6 +769,9 @@ static struct command_result *handle_init(struct command *cmd,
|
|||||||
network = json_strdup(tmpctx, buf, nettok);
|
network = json_strdup(tmpctx, buf, nettok);
|
||||||
chainparams = chainparams_for_network(network);
|
chainparams = chainparams_for_network(network);
|
||||||
|
|
||||||
|
fsettok = json_delve(buf, configtok, ".feature_set");
|
||||||
|
p->fset = json_to_feature_set(p, buf, fsettok);
|
||||||
|
|
||||||
rpctok = json_delve(buf, configtok, ".rpc-file");
|
rpctok = json_delve(buf, configtok, ".rpc-file");
|
||||||
p->rpc_conn->fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
p->rpc_conn->fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (rpctok->end - rpctok->start + 1 > sizeof(addr.sun_path))
|
if (rpctok->end - rpctok->start + 1 > sizeof(addr.sun_path))
|
||||||
|
|||||||
@@ -90,6 +90,9 @@ struct plugin_hook {
|
|||||||
const jsmntok_t *params);
|
const jsmntok_t *params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Return the feature set of the current lightning node */
|
||||||
|
const struct feature_set *plugin_feature_set(const struct plugin *p);
|
||||||
|
|
||||||
/* Helper to create a JSONRPC2 request stream. Send it with `send_outreq`. */
|
/* Helper to create a JSONRPC2 request stream. Send it with `send_outreq`. */
|
||||||
struct out_req *
|
struct out_req *
|
||||||
jsonrpc_request_start_(struct plugin *plugin, struct command *cmd,
|
jsonrpc_request_start_(struct plugin *plugin, struct command *cmd,
|
||||||
|
|||||||
Reference in New Issue
Block a user