mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
connectd: Pass the init_featurebits down to connectd and use in init
The `init_featurebits` are computed at startup, and then cached indefinitely. They are then used whenever a new `init` handshake is performed. We could add a new message to push updates to `connectd` whenever a plugin is added or removed, but that's up for discussion.
This commit is contained in:
parent
58c9a6a004
commit
8d6c8c3cd1
5 changed files with 24 additions and 8 deletions
|
@ -15,6 +15,8 @@ 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,6 +154,9 @@ 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
|
||||
|
@ -472,7 +475,8 @@ 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);
|
||||
return peer_exchange_initmsg(conn, daemon, cs, &id, addr,
|
||||
daemon->init_featurebits);
|
||||
}
|
||||
|
||||
/*~ When we get a connection in we set up its network address then call
|
||||
|
@ -532,7 +536,8 @@ 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);
|
||||
return peer_exchange_initmsg(conn, connect->daemon, cs, &id, addr,
|
||||
connect->daemon->init_featurebits);
|
||||
}
|
||||
|
||||
struct io_plan *connection_out(struct io_conn *conn, struct connecting *connect)
|
||||
|
@ -1210,7 +1215,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->use_v3_autotor, &daemon->init_featurebits)) {
|
||||
/* 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,7 +155,8 @@ 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 struct wireaddr_internal *addr,
|
||||
const u8 *init_featurebits)
|
||||
{
|
||||
/* If conn is closed, forget peer */
|
||||
struct peer *peer = tal(conn, struct peer);
|
||||
|
@ -200,7 +201,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),
|
||||
get_offered_initfeatures(tmpctx),
|
||||
init_featurebits,
|
||||
tlvs);
|
||||
status_peer_io(LOG_IO_OUT, &peer->id, peer->msg);
|
||||
peer->msg = cryptomsg_encrypt_msg(peer, &peer->cs, take(peer->msg));
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef LIGHTNING_CONNECTD_PEER_EXCHANGE_INITMSG_H
|
||||
#define LIGHTNING_CONNECTD_PEER_EXCHANGE_INITMSG_H
|
||||
#include "config.h"
|
||||
#include <ccan/short_types/short_types.h>
|
||||
|
||||
struct crypto_state;
|
||||
struct daemon;
|
||||
|
@ -13,6 +14,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 struct wireaddr_internal *addr,
|
||||
const u8 *init_featurebits);
|
||||
|
||||
#endif /* LIGHTNING_CONNECTD_PEER_EXCHANGE_INITMSG_H */
|
||||
|
|
|
@ -337,7 +337,7 @@ static void connect_init_done(struct subd *connectd,
|
|||
int connectd_init(struct lightningd *ld)
|
||||
{
|
||||
int fds[2];
|
||||
u8 *msg;
|
||||
u8 *msg, *init_features;
|
||||
int hsmfd;
|
||||
struct wireaddr_internal *wireaddrs = ld->proposed_wireaddr;
|
||||
enum addr_listen_announce *listen_announce = ld->proposed_listen_announce;
|
||||
|
@ -362,6 +362,12 @@ 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->id,
|
||||
|
@ -370,7 +376,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);
|
||||
ld->config.use_v3_autotor, init_features);
|
||||
|
||||
subd_req(ld->connectd, ld->connectd, take(msg), -1, 0,
|
||||
connect_init_done, NULL);
|
||||
|
|
Loading…
Add table
Reference in a new issue