diff --git a/gossipd/gossip.c b/gossipd/gossip.c index 4bf10c9b0..cfa7571cc 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -36,6 +36,8 @@ #include #include +#define HSM_FD 3 + struct daemon { struct list_head peers; diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 90e1410d1..a8aa897a9 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -3,16 +3,21 @@ #include "peer_control.h" #include "subd.h" #include +#include #include #include #include #include +#include #include +#include #include #include +#include #include #include #include +#include static void gossip_finished(struct subd *gossip, int status) { @@ -136,16 +141,31 @@ static int gossip_msg(struct subd *gossip, const u8 *msg, const int *fds) void gossip_init(struct lightningd *ld) { tal_t *tmpctx = tal_tmpctx(ld); - u8 *init; + u8 *msg; + int hsmfd; + + msg = towire_hsmctl_hsmfd_ecdh(tmpctx, 0); + if (!wire_sync_write(ld->hsm_fd, msg)) + fatal("Could not write to HSM: %s", strerror(errno)); + + msg = hsm_sync_read(tmpctx, ld); + if (!fromwire_hsmctl_hsmfd_ecdh_fd_reply(msg, NULL)) + fatal("Malformed hsmfd response: %s", tal_hex(msg, msg)); + + hsmfd = fdpass_recv(ld->hsm_fd); + if (hsmfd < 0) + fatal("Could not read fd from HSM: %s", strerror(errno)); + ld->gossip = new_subd(ld, "lightning_gossipd", NULL, gossip_wire_type_name, - gossip_msg, NULL, gossip_finished, NULL); + gossip_msg, NULL, gossip_finished, + take(&hsmfd), NULL); if (!ld->gossip) err(1, "Could not subdaemon gossip"); - init = towire_gossipctl_init(tmpctx, ld->broadcast_interval, - &get_chainparams(ld)->genesis_blockhash); - subd_send_msg(ld->gossip, init); + msg = towire_gossipctl_init(tmpctx, ld->broadcast_interval, + &get_chainparams(ld)->genesis_blockhash); + subd_send_msg(ld->gossip, msg); tal_free(tmpctx); } diff --git a/lightningd/new_connection.c b/lightningd/new_connection.c index 39fa22d0f..20064ae0b 100644 --- a/lightningd/new_connection.c +++ b/lightningd/new_connection.c @@ -68,7 +68,7 @@ struct connection *new_connection(const tal_t *ctx, struct command *cmd, const struct pubkey *known_id) { - static u64 id_counter; + static u64 id_counter = 1; struct connection *c = tal(ctx, struct connection); c->ld = ld;