Browse Source

hsm: channeld now also just uses the handle_client entry point

Signed-off-by: Christian Decker <decker.christian@gmail.com>
ppa-0.6.1
Christian Decker 7 years ago
parent
commit
8ff69e0307
  1. 54
      hsmd/hsm.c
  2. 7
      hsmd/hsm_wire.csv
  3. 5
      lightningd/peer_control.c

54
hsmd/hsm.c

@ -278,37 +278,6 @@ static struct io_plan *handle_client(struct io_conn *conn,
return io_close(conn);
}
static struct io_plan *handle_channeld(struct io_conn *conn,
struct daemon_conn *dc)
{
struct client *c = container_of(dc, struct client, dc);
enum hsm_client_wire_type t = fromwire_peektype(dc->msg_in);
status_trace("Client: type %s len %zu",
hsm_client_wire_type_name(t), tal_count(dc->msg_in));
switch (t) {
case WIRE_HSM_ECDH_REQ:
return handle_ecdh(conn, dc);
case WIRE_HSM_CANNOUNCEMENT_SIG_REQ:
return handle_cannouncement_sig(conn, dc);
case WIRE_HSM_CUPDATE_SIG_REQ:
return handle_channel_update_sig(conn, dc);
case WIRE_HSM_ECDH_RESP:
case WIRE_HSM_CANNOUNCEMENT_SIG_REPLY:
case WIRE_HSM_CUPDATE_SIG_REPLY:
break;
}
daemon_conn_send(c->master,
take(towire_hsmstatus_client_bad_request(c,
&c->id,
dc->msg_in)));
return io_close(conn);
}
/* Control messages */
static void send_init_response(struct daemon_conn *master)
{
struct pubkey node_id;
@ -498,25 +467,6 @@ static void pass_client_hsmfd(struct daemon_conn *master, const u8 *msg)
daemon_conn_send_fd(master, fds[1]);
}
/* Reply to an incoming request for an HSMFD for a channeld. */
static void pass_hsmfd_channeld(struct daemon_conn *master, const u8 *msg)
{
int fds[2];
struct pubkey id;
if (!fromwire_hsmctl_hsmfd_channeld(msg, NULL, &id))
master_badmsg(WIRE_HSMCTL_HSMFD_CHANNELD, msg);
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) != 0)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"creating fds: %s", strerror(errno));
new_client(master, &id, HSM_CAP_ECDH | HSM_CAP_SIGN_GOSSIP, handle_channeld, fds[0]);
daemon_conn_send(master,
take(towire_hsmctl_hsmfd_channeld_reply(master)));
daemon_conn_send_fd(master, fds[1]);
}
/* Note that it's the main daemon that asks for the funding signature so it
* can broadcast it. */
static void sign_funding_tx(struct daemon_conn *master, const u8 *msg)
@ -724,9 +674,6 @@ static struct io_plan *control_received_req(struct io_conn *conn,
case WIRE_HSMCTL_CLIENT_HSMFD:
pass_client_hsmfd(master, master->msg_in);
return daemon_conn_read_next(conn, master);
case WIRE_HSMCTL_HSMFD_CHANNELD:
pass_hsmfd_channeld(master, master->msg_in);
return daemon_conn_read_next(conn, master);
case WIRE_HSMCTL_SIGN_FUNDING:
sign_funding_tx(master, master->msg_in);
return daemon_conn_read_next(conn, master);
@ -745,7 +692,6 @@ static struct io_plan *control_received_req(struct io_conn *conn,
case WIRE_HSMCTL_INIT_REPLY:
case WIRE_HSMCTL_CLIENT_HSMFD_REPLY:
case WIRE_HSMCTL_HSMFD_CHANNELD_REPLY:
case WIRE_HSMCTL_SIGN_FUNDING_REPLY:
case WIRE_HSMCTL_SIGN_WITHDRAWAL_REPLY:
case WIRE_HSMCTL_SIGN_INVOICE_REPLY:

7
hsmd/hsm_wire.csv

@ -38,13 +38,6 @@ hsmctl_sign_funding_reply,104
hsmctl_sign_funding_reply,,num_sigs,u16
hsmctl_sign_funding_reply,,sig,num_sigs*secp256k1_ecdsa_signature
# Request a client socket for a `channeld`, allows signing announcements
hsmctl_hsmfd_channeld,5
hsmctl_hsmfd_channeld,,id,struct pubkey
# Empty reply, just an fd
hsmctl_hsmfd_channeld_reply,105
# Master asks the HSM to sign a node_announcement
hsmctl_node_announcement_sig_req,6
hsmctl_node_announcement_sig_req,,annlen,u16

Can't render this file because it has a wrong number of fields in line 2.

5
lightningd/peer_control.c

@ -23,6 +23,7 @@
#include <errno.h>
#include <fcntl.h>
#include <gossipd/gen_gossip_wire.h>
#include <hsmd/capabilities.h>
#include <hsmd/gen_hsm_wire.h>
#include <inttypes.h>
#include <lightningd/build_utxos.h>
@ -2052,12 +2053,12 @@ static bool peer_start_channeld(struct peer *peer,
} else
assert(peer->our_msatoshi);
msg = towire_hsmctl_hsmfd_channeld(tmpctx, &peer->id);
msg = towire_hsmctl_client_hsmfd(tmpctx, &peer->id, HSM_CAP_SIGN_GOSSIP | HSM_CAP_ECDH);
if (!wire_sync_write(peer->ld->hsm_fd, take(msg)))
fatal("Could not write to HSM: %s", strerror(errno));
msg = hsm_sync_read(tmpctx, peer->ld);
if (!fromwire_hsmctl_hsmfd_channeld_reply(msg, NULL))
if (!fromwire_hsmctl_client_hsmfd_reply(msg, NULL))
fatal("Bad reply from HSM: %s", tal_hex(tmpctx, msg));
hsmfd = fdpass_recv(peer->ld->hsm_fd);

Loading…
Cancel
Save