mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
connectd: temporarily have two fds to gossipd.
We want to stream gossip through this, but currently connectd treats the fd as synchronous. While we work on getting rid of that, it's easiest to have two fds. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -52,6 +52,7 @@
|
|||||||
* thus may know how to reach certain peers. */
|
* thus may know how to reach certain peers. */
|
||||||
#define HSM_FD 3
|
#define HSM_FD 3
|
||||||
#define GOSSIPCTL_FD 4
|
#define GOSSIPCTL_FD 4
|
||||||
|
#define GOSSIPCTL2_FD 5
|
||||||
|
|
||||||
/*~ In C convention, constants are UPPERCASE macros. Not everything needs to
|
/*~ In C convention, constants are UPPERCASE macros. Not everything needs to
|
||||||
* be a constant, but it soothes the programmer's conscience to encapsulate
|
* be a constant, but it soothes the programmer's conscience to encapsulate
|
||||||
@@ -1577,7 +1578,7 @@ static void connect_init(struct daemon *daemon, const u8 *msg)
|
|||||||
announcable)));
|
announcable)));
|
||||||
#if DEVELOPER
|
#if DEVELOPER
|
||||||
if (dev_disconnect)
|
if (dev_disconnect)
|
||||||
dev_disconnect_init(5);
|
dev_disconnect_init(6);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2001,6 +2002,15 @@ static void master_gone(struct daemon_conn *master UNUSED)
|
|||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*~ gossipd sends us gossip to send to the peers. */
|
||||||
|
static struct io_plan *recv_gossip(struct io_conn *conn,
|
||||||
|
const u8 *msg,
|
||||||
|
struct daemon *daemon)
|
||||||
|
{
|
||||||
|
/* FIXME! */
|
||||||
|
return daemon_conn_read_next(conn, daemon->gossipd);
|
||||||
|
}
|
||||||
|
|
||||||
/*~ This is a hook used by the memleak code (if DEVELOPER=1): it can't see
|
/*~ This is a hook used by the memleak code (if DEVELOPER=1): it can't see
|
||||||
* pointers inside hash tables, so we give it a hint here. */
|
* pointers inside hash tables, so we give it a hint here. */
|
||||||
#if DEVELOPER
|
#if DEVELOPER
|
||||||
@@ -2037,6 +2047,11 @@ int main(int argc, char *argv[])
|
|||||||
* our status_ and failed messages. */
|
* our status_ and failed messages. */
|
||||||
status_setup_async(daemon->master);
|
status_setup_async(daemon->master);
|
||||||
|
|
||||||
|
/* This streams gossip to and from gossipd */
|
||||||
|
daemon->gossipd = daemon_conn_new(daemon, GOSSIPCTL2_FD,
|
||||||
|
recv_gossip, NULL,
|
||||||
|
daemon);
|
||||||
|
|
||||||
/* Set up ecdh() function so it uses our HSM fd, and calls
|
/* Set up ecdh() function so it uses our HSM fd, and calls
|
||||||
* status_failed on error. */
|
* status_failed on error. */
|
||||||
ecdh_hsmd_setup(HSM_FD, status_failed);
|
ecdh_hsmd_setup(HSM_FD, status_failed);
|
||||||
|
|||||||
@@ -126,6 +126,9 @@ struct daemon {
|
|||||||
/* Connection to main daemon. */
|
/* Connection to main daemon. */
|
||||||
struct daemon_conn *master;
|
struct daemon_conn *master;
|
||||||
|
|
||||||
|
/* Connection to gossip daemon. */
|
||||||
|
struct daemon_conn *gossipd;
|
||||||
|
|
||||||
/* Allow localhost to be considered "public": DEVELOPER-only option,
|
/* Allow localhost to be considered "public": DEVELOPER-only option,
|
||||||
* but for simplicity we don't #if DEVELOPER-wrap it here. */
|
* but for simplicity we don't #if DEVELOPER-wrap it here. */
|
||||||
bool dev_allow_localhost;
|
bool dev_allow_localhost;
|
||||||
|
|||||||
@@ -403,9 +403,9 @@ static void connect_init_done(struct subd *connectd,
|
|||||||
io_break(connectd);
|
io_break(connectd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int connectd_init(struct lightningd *ld)
|
int connectd_init(struct lightningd *ld, int *gossipd_fd2)
|
||||||
{
|
{
|
||||||
int fds[2];
|
int fds[2], fds2[2];
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
int hsmfd;
|
int hsmfd;
|
||||||
struct wireaddr_internal *wireaddrs = ld->proposed_wireaddr;
|
struct wireaddr_internal *wireaddrs = ld->proposed_wireaddr;
|
||||||
@@ -418,11 +418,16 @@ int connectd_init(struct lightningd *ld)
|
|||||||
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0)
|
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0)
|
||||||
fatal("Could not socketpair for connectd<->gossipd");
|
fatal("Could not socketpair for connectd<->gossipd");
|
||||||
|
|
||||||
|
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds2) != 0)
|
||||||
|
fatal("Could not socketpair for connectd<->gossipd 2");
|
||||||
|
|
||||||
hsmfd = hsm_get_global_fd(ld, HSM_CAP_ECDH);
|
hsmfd = hsm_get_global_fd(ld, HSM_CAP_ECDH);
|
||||||
|
|
||||||
ld->connectd = new_global_subd(ld, "lightning_connectd",
|
ld->connectd = new_global_subd(ld, "lightning_connectd",
|
||||||
connectd_wire_name, connectd_msg,
|
connectd_wire_name, connectd_msg,
|
||||||
take(&hsmfd), take(&fds[1]),
|
take(&hsmfd),
|
||||||
|
take(&fds[1]),
|
||||||
|
take(&fds2[1]),
|
||||||
#if DEVELOPER
|
#if DEVELOPER
|
||||||
/* Not take(): we share it */
|
/* Not take(): we share it */
|
||||||
ld->dev_disconnect_fd >= 0 ?
|
ld->dev_disconnect_fd >= 0 ?
|
||||||
@@ -463,6 +468,7 @@ int connectd_init(struct lightningd *ld)
|
|||||||
/* Wait for init_reply */
|
/* Wait for init_reply */
|
||||||
io_loop(NULL, NULL);
|
io_loop(NULL, NULL);
|
||||||
|
|
||||||
|
*gossipd_fd2 = fds2[0];
|
||||||
return fds[0];
|
return fds[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ struct pubkey;
|
|||||||
struct wireaddr_internal;
|
struct wireaddr_internal;
|
||||||
|
|
||||||
/* Returns fd for gossipd to talk to connectd */
|
/* Returns fd for gossipd to talk to connectd */
|
||||||
int connectd_init(struct lightningd *ld);
|
int connectd_init(struct lightningd *ld, int *gossipd_fd2);
|
||||||
void connectd_activate(struct lightningd *ld);
|
void connectd_activate(struct lightningd *ld);
|
||||||
|
|
||||||
void try_reconnect(struct channel *channel, u32 seconds_delay,
|
void try_reconnect(struct channel *channel, u32 seconds_delay,
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ static void gossipd_init_done(struct subd *gossipd,
|
|||||||
|
|
||||||
/* Create the `gossipd` subdaemon and send the initialization
|
/* Create the `gossipd` subdaemon and send the initialization
|
||||||
* message */
|
* message */
|
||||||
void gossip_init(struct lightningd *ld, int connectd_fd)
|
void gossip_init(struct lightningd *ld, int connectd_fd, int connectd_fd2)
|
||||||
{
|
{
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
int hsmfd;
|
int hsmfd;
|
||||||
@@ -248,7 +248,10 @@ void gossip_init(struct lightningd *ld, int connectd_fd)
|
|||||||
|
|
||||||
ld->gossip = new_global_subd(ld, "lightning_gossipd",
|
ld->gossip = new_global_subd(ld, "lightning_gossipd",
|
||||||
gossipd_wire_name, gossip_msg,
|
gossipd_wire_name, gossip_msg,
|
||||||
take(&hsmfd), take(&connectd_fd), NULL);
|
take(&hsmfd),
|
||||||
|
take(&connectd_fd),
|
||||||
|
take(&connectd_fd2),
|
||||||
|
NULL);
|
||||||
if (!ld->gossip)
|
if (!ld->gossip)
|
||||||
err(1, "Could not subdaemon gossip");
|
err(1, "Could not subdaemon gossip");
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
struct channel;
|
struct channel;
|
||||||
struct lightningd;
|
struct lightningd;
|
||||||
|
|
||||||
void gossip_init(struct lightningd *ld, int connectd_fd);
|
void gossip_init(struct lightningd *ld, int connectd_fd, int connectd_fd2);
|
||||||
|
|
||||||
void gossipd_notify_spend(struct lightningd *ld,
|
void gossipd_notify_spend(struct lightningd *ld,
|
||||||
const struct short_channel_id *scid);
|
const struct short_channel_id *scid);
|
||||||
|
|||||||
@@ -850,7 +850,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
struct lightningd *ld;
|
struct lightningd *ld;
|
||||||
u32 min_blockheight, max_blockheight;
|
u32 min_blockheight, max_blockheight;
|
||||||
int connectd_gossipd_fd;
|
int connectd_gossipd_fd, connectd_gossipd_fd2;
|
||||||
int stop_fd;
|
int stop_fd;
|
||||||
struct timers *timers;
|
struct timers *timers;
|
||||||
const char *stop_response;
|
const char *stop_response;
|
||||||
@@ -1022,7 +1022,7 @@ int main(int argc, char *argv[])
|
|||||||
* which knows (via node_announcement messages) the public
|
* which knows (via node_announcement messages) the public
|
||||||
* addresses of nodes, so connectd_init hands it one end of a
|
* addresses of nodes, so connectd_init hands it one end of a
|
||||||
* socket pair, and gives us the other */
|
* socket pair, and gives us the other */
|
||||||
connectd_gossipd_fd = connectd_init(ld);
|
connectd_gossipd_fd = connectd_init(ld, &connectd_gossipd_fd2);
|
||||||
|
|
||||||
/*~ We do every database operation within a transaction; usually this
|
/*~ We do every database operation within a transaction; usually this
|
||||||
* is covered by the infrastructure (eg. opening a transaction before
|
* is covered by the infrastructure (eg. opening a transaction before
|
||||||
@@ -1074,7 +1074,7 @@ int main(int argc, char *argv[])
|
|||||||
* channel_announcement, channel_update, node_announcement and gossip
|
* channel_announcement, channel_update, node_announcement and gossip
|
||||||
* queries. It also hands us the latest channel_updates for our
|
* queries. It also hands us the latest channel_updates for our
|
||||||
* channels. */
|
* channels. */
|
||||||
gossip_init(ld, connectd_gossipd_fd);
|
gossip_init(ld, connectd_gossipd_fd, connectd_gossipd_fd2);
|
||||||
|
|
||||||
/*~ Create RPC socket: now lightning-cli can send us JSON RPC commands
|
/*~ Create RPC socket: now lightning-cli can send us JSON RPC commands
|
||||||
* over a UNIX domain socket specified by `ld->rpc_filename`. */
|
* over a UNIX domain socket specified by `ld->rpc_filename`. */
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ void channel_notify_new_block(struct lightningd *ld UNNEEDED,
|
|||||||
void connectd_activate(struct lightningd *ld UNNEEDED)
|
void connectd_activate(struct lightningd *ld UNNEEDED)
|
||||||
{ fprintf(stderr, "connectd_activate called!\n"); abort(); }
|
{ fprintf(stderr, "connectd_activate called!\n"); abort(); }
|
||||||
/* Generated stub for connectd_init */
|
/* Generated stub for connectd_init */
|
||||||
int connectd_init(struct lightningd *ld UNNEEDED)
|
int connectd_init(struct lightningd *ld UNNEEDED, int *gossipd_fd2 UNNEEDED)
|
||||||
{ fprintf(stderr, "connectd_init called!\n"); abort(); }
|
{ fprintf(stderr, "connectd_init called!\n"); abort(); }
|
||||||
/* Generated stub for daemon_poll */
|
/* Generated stub for daemon_poll */
|
||||||
int daemon_poll(struct pollfd *fds UNNEEDED, nfds_t nfds UNNEEDED, int timeout UNNEEDED)
|
int daemon_poll(struct pollfd *fds UNNEEDED, nfds_t nfds UNNEEDED, int timeout UNNEEDED)
|
||||||
@@ -92,7 +92,7 @@ bool fromwire_status_peer_error(const tal_t *ctx UNNEEDED, const void *p UNNEEDE
|
|||||||
bool fromwire_status_version(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, wirestring **version UNNEEDED)
|
bool fromwire_status_version(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, wirestring **version UNNEEDED)
|
||||||
{ fprintf(stderr, "fromwire_status_version called!\n"); abort(); }
|
{ fprintf(stderr, "fromwire_status_version called!\n"); abort(); }
|
||||||
/* Generated stub for gossip_init */
|
/* Generated stub for gossip_init */
|
||||||
void gossip_init(struct lightningd *ld UNNEEDED, int connectd_fd UNNEEDED)
|
void gossip_init(struct lightningd *ld UNNEEDED, int connectd_fd UNNEEDED, int connectd_fd2 UNNEEDED)
|
||||||
{ fprintf(stderr, "gossip_init called!\n"); abort(); }
|
{ fprintf(stderr, "gossip_init called!\n"); abort(); }
|
||||||
/* Generated stub for gossip_notify_new_block */
|
/* Generated stub for gossip_notify_new_block */
|
||||||
void gossip_notify_new_block(struct lightningd *ld UNNEEDED, u32 blockheight UNNEEDED)
|
void gossip_notify_new_block(struct lightningd *ld UNNEEDED, u32 blockheight UNNEEDED)
|
||||||
|
|||||||
Reference in New Issue
Block a user