Browse Source

lightningd: use hsm_get_client_fd() helper for global daemons too.

We couldn't use it before because it asserted dbid was non-zero.  Remove
assert and save some code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>



Header from folded patch 'fixup!_lightningd__use_hsm_get_client_fd()_helper_for_global_daemons_too.patch':

fixup! lightningd: use hsm_get_client_fd() helper for global daemons too.

Suggested-by: @ZmnSCPxj
json-streaming
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
04c77f4853
  1. 14
      lightningd/connect_control.c
  2. 13
      lightningd/gossip_control.c
  3. 18
      lightningd/hsm_control.c
  4. 3
      lightningd/hsm_control.h

14
lightningd/connect_control.c

@ -14,6 +14,7 @@
#include <hsmd/gen_hsm_wire.h> #include <hsmd/gen_hsm_wire.h>
#include <lightningd/channel.h> #include <lightningd/channel.h>
#include <lightningd/connect_control.h> #include <lightningd/connect_control.h>
#include <lightningd/hsm_control.h>
#include <lightningd/json.h> #include <lightningd/json.h>
#include <lightningd/jsonrpc.h> #include <lightningd/jsonrpc.h>
#include <lightningd/jsonrpc_errors.h> #include <lightningd/jsonrpc_errors.h>
@ -333,7 +334,6 @@ int connectd_init(struct lightningd *ld)
int fds[2]; int fds[2];
u8 *msg; u8 *msg;
int hsmfd; int hsmfd;
u64 capabilities = HSM_CAP_ECDH;
struct wireaddr_internal *wireaddrs = ld->proposed_wireaddr; struct wireaddr_internal *wireaddrs = ld->proposed_wireaddr;
enum addr_listen_announce *listen_announce = ld->proposed_listen_announce; enum addr_listen_announce *listen_announce = ld->proposed_listen_announce;
bool allow_localhost = false; bool allow_localhost = false;
@ -345,17 +345,7 @@ 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");
msg = towire_hsm_client_hsmfd(tmpctx, &ld->id, 0, capabilities); hsmfd = hsm_get_global_fd(ld, HSM_CAP_ECDH);
if (!wire_sync_write(ld->hsm_fd, msg))
fatal("Could not write to HSM: %s", strerror(errno));
msg = wire_sync_read(tmpctx, ld->hsm_fd);
if (!fromwire_hsm_client_hsmfd_reply(msg))
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->connectd = new_global_subd(ld, "lightning_connectd", ld->connectd = new_global_subd(ld, "lightning_connectd",
connect_wire_type_name, connectd_msg, connect_wire_type_name, connectd_msg,

13
lightningd/gossip_control.c

@ -148,19 +148,8 @@ void gossip_init(struct lightningd *ld, int connectd_fd)
{ {
u8 *msg; u8 *msg;
int hsmfd; int hsmfd;
u64 capabilities = HSM_CAP_SIGN_GOSSIP;
msg = towire_hsm_client_hsmfd(tmpctx, &ld->id, 0, capabilities); hsmfd = hsm_get_global_fd(ld, HSM_CAP_SIGN_GOSSIP);
if (!wire_sync_write(ld->hsm_fd, msg))
fatal("Could not write to HSM: %s", strerror(errno));
msg = wire_sync_read(tmpctx, ld->hsm_fd);
if (!fromwire_hsm_client_hsmfd_reply(msg))
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_global_subd(ld, "lightning_gossipd", ld->gossip = new_global_subd(ld, "lightning_gossipd",
gossip_wire_type_name, gossip_msg, gossip_wire_type_name, gossip_msg,

18
lightningd/hsm_control.c

@ -19,7 +19,7 @@
#include <wally_bip32.h> #include <wally_bip32.h>
#include <wire/wire_sync.h> #include <wire/wire_sync.h>
int hsm_get_client_fd(struct lightningd *ld, static int hsm_get_fd(struct lightningd *ld,
const struct pubkey *id, const struct pubkey *id,
u64 dbid, u64 dbid,
int capabilities) int capabilities)
@ -27,7 +27,6 @@ int hsm_get_client_fd(struct lightningd *ld,
int hsm_fd; int hsm_fd;
u8 *msg; u8 *msg;
assert(dbid);
msg = towire_hsm_client_hsmfd(NULL, id, dbid, capabilities); msg = towire_hsm_client_hsmfd(NULL, id, dbid, capabilities);
if (!wire_sync_write(ld->hsm_fd, take(msg))) if (!wire_sync_write(ld->hsm_fd, take(msg)))
fatal("Could not write to HSM: %s", strerror(errno)); fatal("Could not write to HSM: %s", strerror(errno));
@ -42,6 +41,21 @@ int hsm_get_client_fd(struct lightningd *ld,
return hsm_fd; return hsm_fd;
} }
int hsm_get_client_fd(struct lightningd *ld,
const struct pubkey *id,
u64 dbid,
int capabilities)
{
assert(dbid);
return hsm_get_fd(ld, id, dbid, capabilities);
}
int hsm_get_global_fd(struct lightningd *ld, int capabilities)
{
return hsm_get_fd(ld, &ld->id, 0, capabilities);
}
static unsigned int hsm_msg(struct subd *hsmd, static unsigned int hsm_msg(struct subd *hsmd,
const u8 *msg, const int *fds UNUSED) const u8 *msg, const int *fds UNUSED)
{ {

3
lightningd/hsm_control.h

@ -15,5 +15,8 @@ int hsm_get_client_fd(struct lightningd *ld,
u64 dbid, u64 dbid,
int capabilities); int capabilities);
/* Ask HSM for an fd for a global subdaemon to use (gossipd, connectd) */
int hsm_get_global_fd(struct lightningd *ld, int capabilities);
void hsm_init(struct lightningd *ld); void hsm_init(struct lightningd *ld);
#endif /* LIGHTNING_LIGHTNINGD_HSM_CONTROL_H */ #endif /* LIGHTNING_LIGHTNINGD_HSM_CONTROL_H */

Loading…
Cancel
Save