mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 13:25:43 +01:00
gossipd: receive hsm fd from master.
We'll need this soon. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
f172be71dc
commit
4fa36c585d
@ -36,6 +36,8 @@
|
|||||||
#include <wire/gen_peer_wire.h>
|
#include <wire/gen_peer_wire.h>
|
||||||
#include <wire/wire_io.h>
|
#include <wire/wire_io.h>
|
||||||
|
|
||||||
|
#define HSM_FD 3
|
||||||
|
|
||||||
struct daemon {
|
struct daemon {
|
||||||
struct list_head peers;
|
struct list_head peers;
|
||||||
|
|
||||||
|
@ -3,16 +3,21 @@
|
|||||||
#include "peer_control.h"
|
#include "peer_control.h"
|
||||||
#include "subd.h"
|
#include "subd.h"
|
||||||
#include <ccan/err/err.h>
|
#include <ccan/err/err.h>
|
||||||
|
#include <ccan/fdpass/fdpass.h>
|
||||||
#include <ccan/take/take.h>
|
#include <ccan/take/take.h>
|
||||||
#include <ccan/tal/str/str.h>
|
#include <ccan/tal/str/str.h>
|
||||||
#include <common/type_to_string.h>
|
#include <common/type_to_string.h>
|
||||||
#include <common/utils.h>
|
#include <common/utils.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <gossipd/gen_gossip_wire.h>
|
#include <gossipd/gen_gossip_wire.h>
|
||||||
|
#include <hsmd/gen_hsm_wire.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <lightningd/gossip_msg.h>
|
#include <lightningd/gossip_msg.h>
|
||||||
|
#include <lightningd/hsm_control.h>
|
||||||
#include <lightningd/jsonrpc.h>
|
#include <lightningd/jsonrpc.h>
|
||||||
#include <lightningd/log.h>
|
#include <lightningd/log.h>
|
||||||
#include <wire/gen_peer_wire.h>
|
#include <wire/gen_peer_wire.h>
|
||||||
|
#include <wire/wire_sync.h>
|
||||||
|
|
||||||
static void gossip_finished(struct subd *gossip, int status)
|
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)
|
void gossip_init(struct lightningd *ld)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(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,
|
ld->gossip = new_subd(ld, "lightning_gossipd", NULL,
|
||||||
gossip_wire_type_name,
|
gossip_wire_type_name,
|
||||||
gossip_msg, NULL, gossip_finished, NULL);
|
gossip_msg, NULL, gossip_finished,
|
||||||
|
take(&hsmfd), NULL);
|
||||||
if (!ld->gossip)
|
if (!ld->gossip)
|
||||||
err(1, "Could not subdaemon gossip");
|
err(1, "Could not subdaemon gossip");
|
||||||
|
|
||||||
init = towire_gossipctl_init(tmpctx, ld->broadcast_interval,
|
msg = towire_gossipctl_init(tmpctx, ld->broadcast_interval,
|
||||||
&get_chainparams(ld)->genesis_blockhash);
|
&get_chainparams(ld)->genesis_blockhash);
|
||||||
subd_send_msg(ld->gossip, init);
|
subd_send_msg(ld->gossip, msg);
|
||||||
tal_free(tmpctx);
|
tal_free(tmpctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ struct connection *new_connection(const tal_t *ctx,
|
|||||||
struct command *cmd,
|
struct command *cmd,
|
||||||
const struct pubkey *known_id)
|
const struct pubkey *known_id)
|
||||||
{
|
{
|
||||||
static u64 id_counter;
|
static u64 id_counter = 1;
|
||||||
struct connection *c = tal(ctx, struct connection);
|
struct connection *c = tal(ctx, struct connection);
|
||||||
|
|
||||||
c->ld = ld;
|
c->ld = ld;
|
||||||
|
Loading…
Reference in New Issue
Block a user