mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
plugin: remove boutique features.
We now manipulate the global features directly. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
a7cc6d33c3
commit
b7db588a8a
@ -17,8 +17,6 @@ msgdata,connectctl_init,dev_allow_localhost,bool,
|
||||
msgdata,connectctl_init,use_dns,bool,
|
||||
msgdata,connectctl_init,tor_password,wirestring,
|
||||
msgdata,connectctl_init,use_v3_autotor,bool,
|
||||
msgdata,connectctl_init,init_featurebits_len,u16,
|
||||
msgdata,connectctl_init,init_featurebits,u8,init_featurebits_len
|
||||
|
||||
# Connectd->master, here are the addresses I bound, can announce.
|
||||
msgtype,connectctl_init_reply,2100
|
||||
|
|
@ -154,9 +154,6 @@ struct daemon {
|
||||
|
||||
/* Allow to define the default behavior of tor services calls*/
|
||||
bool use_v3_autotor;
|
||||
|
||||
/* featurebits that we support internally, and via plugins */
|
||||
u8 *init_featurebits;
|
||||
};
|
||||
|
||||
/* Peers we're trying to reach: we iterate through addrs until we succeed
|
||||
@ -475,8 +472,7 @@ static struct io_plan *handshake_in_success(struct io_conn *conn,
|
||||
struct node_id id;
|
||||
node_id_from_pubkey(&id, id_key);
|
||||
status_peer_debug(&id, "Connect IN");
|
||||
return peer_exchange_initmsg(conn, daemon, cs, &id, addr,
|
||||
daemon->init_featurebits);
|
||||
return peer_exchange_initmsg(conn, daemon, cs, &id, addr);
|
||||
}
|
||||
|
||||
/*~ When we get a connection in we set up its network address then call
|
||||
@ -536,8 +532,7 @@ static struct io_plan *handshake_out_success(struct io_conn *conn,
|
||||
node_id_from_pubkey(&id, key);
|
||||
connect->connstate = "Exchanging init messages";
|
||||
status_peer_debug(&id, "Connect OUT");
|
||||
return peer_exchange_initmsg(conn, connect->daemon, cs, &id, addr,
|
||||
connect->daemon->init_featurebits);
|
||||
return peer_exchange_initmsg(conn, connect->daemon, cs, &id, addr);
|
||||
}
|
||||
|
||||
struct io_plan *connection_out(struct io_conn *conn, struct connecting *connect)
|
||||
@ -1202,7 +1197,7 @@ static struct io_plan *connect_init(struct io_conn *conn,
|
||||
&proxyaddr, &daemon->use_proxy_always,
|
||||
&daemon->dev_allow_localhost, &daemon->use_dns,
|
||||
&tor_password,
|
||||
&daemon->use_v3_autotor, &daemon->init_featurebits)) {
|
||||
&daemon->use_v3_autotor)) {
|
||||
/* This is a helper which prints the type expected and the actual
|
||||
* message, then exits (it should never be called!). */
|
||||
master_badmsg(WIRE_CONNECTCTL_INIT, msg);
|
||||
|
@ -155,8 +155,7 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
|
||||
struct daemon *daemon,
|
||||
const struct crypto_state *cs,
|
||||
const struct node_id *id,
|
||||
const struct wireaddr_internal *addr,
|
||||
const u8 *init_featurebits)
|
||||
const struct wireaddr_internal *addr)
|
||||
{
|
||||
/* If conn is closed, forget peer */
|
||||
struct peer *peer = tal(conn, struct peer);
|
||||
@ -201,7 +200,7 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
|
||||
* from now on they'll all go in initfeatures. */
|
||||
peer->msg = towire_init(NULL,
|
||||
get_offered_globalinitfeatures(tmpctx),
|
||||
init_featurebits,
|
||||
get_offered_initfeatures(tmpctx),
|
||||
tlvs);
|
||||
status_peer_io(LOG_IO_OUT, &peer->id, peer->msg);
|
||||
peer->msg = cryptomsg_encrypt_msg(peer, &peer->cs, take(peer->msg));
|
||||
|
@ -14,7 +14,6 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
|
||||
struct daemon *daemon,
|
||||
const struct crypto_state *cs,
|
||||
const struct node_id *id,
|
||||
const struct wireaddr_internal *addr,
|
||||
const u8 *init_featurebits);
|
||||
const struct wireaddr_internal *addr);
|
||||
|
||||
#endif /* LIGHTNING_CONNECTD_PEER_EXCHANGE_INITMSG_H */
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* Routines to make our own gossip messages. Not as in "we're the gossip
|
||||
* generation, man!" */
|
||||
#include <ccan/mem/mem.h>
|
||||
#include <common/features.h>
|
||||
#include <common/memleak.h>
|
||||
#include <common/status.h>
|
||||
#include <common/timeout.h>
|
||||
@ -37,7 +38,8 @@ static u8 *create_node_announcement(const tal_t *ctx, struct daemon *daemon,
|
||||
towire_wireaddr(&addresses, &daemon->announcable[i]);
|
||||
|
||||
announcement =
|
||||
towire_node_announcement(ctx, sig, daemon->nodefeatures, timestamp,
|
||||
towire_node_announcement(ctx, sig, get_offered_nodefeatures(tmpctx),
|
||||
timestamp,
|
||||
&daemon->id, daemon->rgb, daemon->alias,
|
||||
addresses);
|
||||
return announcement;
|
||||
|
@ -8,8 +8,6 @@ msgtype,gossipctl_init,3000
|
||||
msgdata,gossipctl_init,chainparams,chainparams,
|
||||
msgdata,gossipctl_init,feature_set,feature_set,
|
||||
msgdata,gossipctl_init,id,node_id,
|
||||
msgdata,gossipctl_init,gflen,u16,
|
||||
msgdata,gossipctl_init,globalfeatures,u8,gflen
|
||||
msgdata,gossipctl_init,rgb,u8,3
|
||||
msgdata,gossipctl_init,alias,u8,32
|
||||
msgdata,gossipctl_init,num_announcable,u16,
|
||||
|
Can't render this file because it has a wrong number of fields in line 7.
|
@ -834,7 +834,6 @@ static struct io_plan *gossip_init(struct io_conn *conn,
|
||||
&chainparams,
|
||||
&feature_set,
|
||||
&daemon->id,
|
||||
&daemon->nodefeatures,
|
||||
daemon->rgb,
|
||||
daemon->alias,
|
||||
&daemon->announcable,
|
||||
|
@ -42,9 +42,6 @@ struct daemon {
|
||||
/* Timers: we batch gossip, and also refresh announcements */
|
||||
struct timers timers;
|
||||
|
||||
/* Features to list in node_announcement. */
|
||||
u8 *nodefeatures;
|
||||
|
||||
/* Alias (not NUL terminated) and favorite color for node_announcement */
|
||||
u8 alias[32];
|
||||
u8 rgb[3];
|
||||
|
@ -337,7 +337,7 @@ static void connect_init_done(struct subd *connectd,
|
||||
int connectd_init(struct lightningd *ld)
|
||||
{
|
||||
int fds[2];
|
||||
u8 *msg, *init_features;
|
||||
u8 *msg;
|
||||
int hsmfd;
|
||||
struct wireaddr_internal *wireaddrs = ld->proposed_wireaddr;
|
||||
enum addr_listen_announce *listen_announce = ld->proposed_listen_announce;
|
||||
@ -362,12 +362,6 @@ int connectd_init(struct lightningd *ld)
|
||||
*listen_announce = ADDR_LISTEN_AND_ANNOUNCE;
|
||||
}
|
||||
|
||||
init_features =
|
||||
featurebits_or(tmpctx,
|
||||
take(plugins_collect_featurebits(
|
||||
tmpctx, ld->plugins, PLUGIN_FEATURES_INIT)),
|
||||
take(get_offered_initfeatures(tmpctx)));
|
||||
|
||||
msg = towire_connectctl_init(
|
||||
tmpctx, chainparams,
|
||||
ld->feature_set,
|
||||
@ -377,7 +371,7 @@ int connectd_init(struct lightningd *ld)
|
||||
ld->proxyaddr, ld->use_proxy_always || ld->pure_tor_setup,
|
||||
IFDEV(ld->dev_allow_localhost, false), ld->config.use_dns,
|
||||
ld->tor_service_password ? ld->tor_service_password : "",
|
||||
ld->config.use_v3_autotor, init_features);
|
||||
ld->config.use_v3_autotor);
|
||||
|
||||
subd_req(ld->connectd, ld->connectd, take(msg), -1, 0,
|
||||
connect_init_done, NULL);
|
||||
|
@ -191,7 +191,7 @@ static void gossip_topology_synced(struct chain_topology *topo, void *unused)
|
||||
* message */
|
||||
void gossip_init(struct lightningd *ld, int connectd_fd)
|
||||
{
|
||||
u8 *msg, *node_featurebits;
|
||||
u8 *msg;
|
||||
int hsmfd;
|
||||
|
||||
hsmfd = hsm_get_global_fd(ld, HSM_CAP_SIGN_GOSSIP);
|
||||
@ -206,17 +206,11 @@ void gossip_init(struct lightningd *ld, int connectd_fd)
|
||||
topology_add_sync_waiter(ld->gossip, ld->topology,
|
||||
gossip_topology_synced, NULL);
|
||||
|
||||
node_featurebits =
|
||||
featurebits_or(tmpctx, take(get_offered_nodefeatures(tmpctx)),
|
||||
take(plugins_collect_featurebits(
|
||||
tmpctx, ld->plugins, PLUGIN_FEATURES_NODE)));
|
||||
|
||||
msg = towire_gossipctl_init(
|
||||
tmpctx,
|
||||
chainparams,
|
||||
ld->feature_set,
|
||||
&ld->id,
|
||||
node_featurebits,
|
||||
ld->rgb,
|
||||
ld->alias,
|
||||
ld->announcable,
|
||||
|
@ -1013,14 +1013,7 @@ static struct command_result *json_invoice(struct command *cmd,
|
||||
info->b11->description_hash = NULL;
|
||||
info->b11->payment_secret = tal_dup(info->b11, struct secret,
|
||||
&payment_secret);
|
||||
|
||||
/* Which features should we announce to the node receiving this invoice?
|
||||
* This is a combination of natively supported features and featurebits
|
||||
* that plugins asked us to include in the invoice. */
|
||||
info->b11->features = featurebits_or(
|
||||
info->b11, take(get_offered_bolt11features(NULL)),
|
||||
take(plugins_collect_featurebits(NULL, cmd->ld->plugins,
|
||||
PLUGIN_FEATURES_INVOICE)));
|
||||
info->b11->features = get_offered_bolt11features(info->b11);
|
||||
|
||||
#if DEVELOPER
|
||||
info->b11->routes = unpack_routes(info->b11, buffer, routes);
|
||||
|
@ -47,18 +47,6 @@ struct plugins *plugins_new(const tal_t *ctx, struct log_book *log_book,
|
||||
return p;
|
||||
}
|
||||
|
||||
u8 *plugins_collect_featurebits(const tal_t *ctx, const struct plugins *plugins,
|
||||
enum plugin_features_type type)
|
||||
{
|
||||
struct plugin *p;
|
||||
u8 *res = tal_arr(ctx, u8, 0);
|
||||
list_for_each(&plugins->plugins, p, list) {
|
||||
if (p->featurebits[type])
|
||||
res = featurebits_or(ctx, take(res), p->featurebits[type]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static void destroy_plugin(struct plugin *p)
|
||||
{
|
||||
plugin_hook_unregister_all(p);
|
||||
@ -82,9 +70,6 @@ struct plugin *plugin_register(struct plugins *plugins, const char* path TAKES)
|
||||
p->plugins = plugins;
|
||||
p->cmd = tal_strdup(p, path);
|
||||
|
||||
for (int i = 0; i < NUM_PLUGIN_FEATURES_TYPE; i++)
|
||||
p->featurebits[i] = NULL;
|
||||
|
||||
p->plugin_state = UNCONFIGURED;
|
||||
p->js_arr = tal_arr(p, struct json_stream *, 0);
|
||||
p->used = 0;
|
||||
@ -868,12 +853,8 @@ static void plugin_manifest_timeout(struct plugin *plugin)
|
||||
fatal("Can't recover from plugin failure, terminating.");
|
||||
}
|
||||
|
||||
/* List of JSON keys matching `plugin_features_type`. */
|
||||
static const char *plugin_features_type_names[] = {"node", "init", "invoice", "channel"};
|
||||
static const size_t plugin_features_fset[] = {NODE_ANNOUNCE_FEATURE,
|
||||
INIT_FEATURE,
|
||||
BOLT11_FEATURE,
|
||||
CHANNEL_FEATURE};
|
||||
/* List of JSON keys matching `enum feature_place`. */
|
||||
static const char *plugin_feature_place_names[] = {"init", NULL, "node", "channel", "invoice"};
|
||||
|
||||
bool plugin_parse_getmanifest_response(const char *buffer,
|
||||
const jsmntok_t *toks,
|
||||
@ -881,7 +862,6 @@ bool plugin_parse_getmanifest_response(const char *buffer,
|
||||
struct plugin *plugin)
|
||||
{
|
||||
const jsmntok_t *resulttok, *dynamictok, *featurestok, *tok;
|
||||
u8 *featurebits;
|
||||
|
||||
resulttok = json_get_member(buffer, toks, "result");
|
||||
if (!resulttok || resulttok->type != JSMN_OBJECT)
|
||||
@ -899,21 +879,24 @@ bool plugin_parse_getmanifest_response(const char *buffer,
|
||||
bool have_featurebits = false;
|
||||
struct feature_set *fset = talz(tmpctx, struct feature_set);
|
||||
|
||||
for (int i = 0; i < NUM_PLUGIN_FEATURES_TYPE; i++) {
|
||||
BUILD_ASSERT(ARRAY_SIZE(plugin_feature_place_names)
|
||||
== ARRAY_SIZE(fset->bits));
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(fset->bits); i++) {
|
||||
/* We don't allow setting the obs global init */
|
||||
if (!plugin_feature_place_names[i])
|
||||
continue;
|
||||
|
||||
tok = json_get_member(buffer, featurestok,
|
||||
plugin_features_type_names[i]);
|
||||
plugin_feature_place_names[i]);
|
||||
|
||||
if (!tok)
|
||||
continue;
|
||||
|
||||
featurebits =
|
||||
json_tok_bin_from_hex(plugin, buffer, tok);
|
||||
fset->bits[i] = json_tok_bin_from_hex(fset, buffer, tok);
|
||||
have_featurebits |= tal_bytelen(fset->bits[i]) > 0;
|
||||
|
||||
have_featurebits |= tal_bytelen(featurebits) > 0;
|
||||
|
||||
if (featurebits) {
|
||||
plugin->featurebits[i] = featurebits;
|
||||
} else {
|
||||
if (!fset->bits[i]) {
|
||||
plugin_kill(
|
||||
plugin,
|
||||
"Featurebits returned by plugin is not a "
|
||||
@ -921,7 +904,6 @@ bool plugin_parse_getmanifest_response(const char *buffer,
|
||||
tok->end - tok->start, buffer + tok->start);
|
||||
return true;
|
||||
}
|
||||
fset->bits[plugin_features_fset[i]] = featurebits;
|
||||
}
|
||||
|
||||
if (plugin->dynamic && have_featurebits) {
|
||||
|
@ -26,23 +26,6 @@ enum plugin_state {
|
||||
CONFIGURED
|
||||
};
|
||||
|
||||
/**
|
||||
* A plugin may register any number of featurebits that should be added to
|
||||
* various messages as part of their manifest. The following enum enumerates
|
||||
* the possible locations the featurebits can be added to, and are used as
|
||||
* indices into the array of featurebits in the plugin struct itself.
|
||||
*
|
||||
* If you edit this make sure that there is a matching entry in the
|
||||
* `plugin_features_type_names[]` array in plugin.c.
|
||||
*/
|
||||
enum plugin_features_type {
|
||||
PLUGIN_FEATURES_NODE,
|
||||
PLUGIN_FEATURES_INIT,
|
||||
PLUGIN_FEATURES_INVOICE,
|
||||
PLUGIN_FEATURES_CHANNEL,
|
||||
};
|
||||
#define NUM_PLUGIN_FEATURES_TYPE (PLUGIN_FEATURES_INVOICE+1)
|
||||
|
||||
/**
|
||||
* A plugin, exposed as a stub so we can pass it as an argument.
|
||||
*/
|
||||
@ -83,11 +66,6 @@ struct plugin {
|
||||
|
||||
/* An array of subscribed topics */
|
||||
char **subscriptions;
|
||||
|
||||
/* Featurebits for various locations that the plugin
|
||||
* registered. Indices correspond to the `plugin_features_type`
|
||||
* enum. */
|
||||
u8 *featurebits[NUM_PLUGIN_FEATURES_TYPE];
|
||||
};
|
||||
|
||||
/**
|
||||
@ -279,9 +257,4 @@ struct log *plugin_get_log(struct plugin *plugin);
|
||||
* call both! */
|
||||
struct plugin_destroyed *plugin_detect_destruction(const struct plugin *plugin);
|
||||
bool was_plugin_destroyed(struct plugin_destroyed *destroyed);
|
||||
|
||||
/* Gather all the features of the given type that plugins registered. */
|
||||
u8 *plugins_collect_featurebits(const tal_t *ctx, const struct plugins *plugins,
|
||||
enum plugin_features_type type);
|
||||
|
||||
#endif /* LIGHTNING_LIGHTNINGD_PLUGIN_H */
|
||||
|
@ -99,9 +99,6 @@ const u8 *failmsg_incorrect_or_unknown(const tal_t *ctx UNNEEDED,
|
||||
/* Generated stub for fatal */
|
||||
void fatal(const char *fmt UNNEEDED, ...)
|
||||
{ fprintf(stderr, "fatal called!\n"); abort(); }
|
||||
/* Generated stub for featurebits_or */
|
||||
u8 *featurebits_or(const tal_t *ctx UNNEEDED, const u8 *f1 TAKES UNNEEDED, const u8 *f2 TAKES UNNEEDED)
|
||||
{ fprintf(stderr, "featurebits_or called!\n"); abort(); }
|
||||
/* Generated stub for feature_is_set */
|
||||
bool feature_is_set(const u8 *features UNNEEDED, size_t bit UNNEEDED)
|
||||
{ fprintf(stderr, "feature_is_set called!\n"); abort(); }
|
||||
@ -384,10 +381,6 @@ void per_peer_state_set_fds(struct per_peer_state *pps UNNEEDED,
|
||||
void plugin_hook_call_(struct lightningd *ld UNNEEDED, const struct plugin_hook *hook UNNEEDED,
|
||||
void *payload UNNEEDED, void *cb_arg UNNEEDED)
|
||||
{ fprintf(stderr, "plugin_hook_call_ called!\n"); abort(); }
|
||||
/* Generated stub for plugins_collect_featurebits */
|
||||
u8 *plugins_collect_featurebits(const tal_t *ctx UNNEEDED, const struct plugins *plugins UNNEEDED,
|
||||
enum plugin_features_type type UNNEEDED)
|
||||
{ fprintf(stderr, "plugins_collect_featurebits called!\n"); abort(); }
|
||||
/* Generated stub for subd_release_channel */
|
||||
void subd_release_channel(struct subd *owner UNNEEDED, void *channel UNNEEDED)
|
||||
{ fprintf(stderr, "subd_release_channel called!\n"); abort(); }
|
||||
|
Loading…
Reference in New Issue
Block a user