From 26b004e5af8aeb1fc8adcfe4a21b5ccb547336d4 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 23 Feb 2018 16:23:47 +1030 Subject: [PATCH] subd: handle status_peer_billboard messages from subdaemons. We use a callback which updates the appropriate slot. Signed-off-by: Rusty Russell --- common/status_wire.csv | 3 +++ lightningd/channel_control.c | 1 + lightningd/closing_control.c | 1 + lightningd/onchain_control.c | 1 + lightningd/opening_control.c | 11 +++++++++++ lightningd/subd.c | 31 ++++++++++++++++++++++++++++--- lightningd/subd.h | 13 ++++++++++++- 7 files changed, 57 insertions(+), 4 deletions(-) diff --git a/common/status_wire.csv b/common/status_wire.csv index 97ae9c2dc..ddbad6902 100644 --- a/common/status_wire.csv +++ b/common/status_wire.csv @@ -15,4 +15,7 @@ status_fail,,desc,wirestring status_peer_connection_lost,0xFFF3 +status_peer_billboard,0xFFF5 +status_peer_billboard,,perm,bool +status_peer_billboard,,happenings,wirestring # Note: 0xFFFF is reserved for MSG_PASS_FD! diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 83a83556a..c4f65b7a9 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -238,6 +238,7 @@ bool peer_start_channeld(struct channel *channel, channel_wire_type_name, channel_msg, channel_errmsg, + channel_set_billboard, take(&peer_fd), take(&gossip_fd), take(&hsmfd), NULL)); diff --git a/lightningd/closing_control.c b/lightningd/closing_control.c index 1cece38f7..9ce9ce7f1 100644 --- a/lightningd/closing_control.c +++ b/lightningd/closing_control.c @@ -163,6 +163,7 @@ void peer_start_closingd(struct channel *channel, channel, channel->log, closing_wire_type_name, closing_msg, channel_errmsg, + channel_set_billboard, take(&peer_fd), take(&gossip_fd), NULL)); if (!channel->owner) { diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 0269f479e..15cfb5e95 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -372,6 +372,7 @@ enum watch_result funding_spent(struct channel *channel, onchain_wire_type_name, onchain_msg, onchain_error, + channel_set_billboard, NULL)); if (!channel->owner) { diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 21487b44c..c8bf611fc 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -485,6 +485,15 @@ static void opening_channel_errmsg(struct uncommitted_channel *uc, tal_free(uc); } +/* There's nothing permanent in an unconfirmed transaction */ +static void opening_channel_set_billboard(struct uncommitted_channel *uc, + bool perm UNUSED, + const char *happenings TAKES) +{ + tal_free(uc->transient_billboard); + uc->transient_billboard = tal_strdup(uc, happenings); +} + static void destroy_uncommitted_channel(struct uncommitted_channel *uc) { uc->peer->uncommitted_channel = NULL; @@ -607,6 +616,7 @@ u8 *peer_accept_channel(struct lightningd *ld, uc->openingd = new_channel_subd(ld, "lightning_openingd", uc, uc->log, opening_wire_type_name, NULL, opening_channel_errmsg, + opening_channel_set_billboard, take(&peer_fd), take(&gossip_fd), NULL); if (!uc->openingd) { @@ -692,6 +702,7 @@ static void peer_offer_channel(struct lightningd *ld, "lightning_openingd", fc->uc, fc->uc->log, opening_wire_type_name, NULL, opening_channel_errmsg, + opening_channel_set_billboard, take(&peer_fd), take(&gossip_fd), NULL); if (!fc->uc->openingd) { diff --git a/lightningd/subd.c b/lightningd/subd.c index 05c73e20a..7f3c0dc73 100644 --- a/lightningd/subd.c +++ b/lightningd/subd.c @@ -413,6 +413,18 @@ static bool handle_peer_error(struct subd *sd, const u8 *msg, int fds[2]) return true; } +static bool handle_set_billboard(struct subd *sd, const u8 *msg) +{ + bool perm; + char *happenings; + + if (!fromwire_status_peer_billboard(msg, msg, &perm, &happenings)) + return false; + + sd->billboardcb(sd->channel, perm, happenings); + return true; +} + static struct io_plan *sd_msg_read(struct io_conn *conn, struct subd *sd) { int type = fromwire_peektype(sd->msg_in); @@ -460,6 +472,12 @@ static struct io_plan *sd_msg_read(struct io_conn *conn, struct subd *sd) goto malformed; log_info(sd->log, "Peer connection lost"); goto close; + case WIRE_STATUS_PEER_BILLBOARD: + if (!sd->channel) + goto malformed; + if (!handle_set_billboard(sd, sd->msg_in)) + goto malformed; + goto next; } if (sd->channel) { @@ -629,6 +647,9 @@ static struct subd *new_subd(struct lightningd *ld, const struct channel_id *channel_id, const char *desc, const u8 *err_for_them), + void (*billboardcb)(void *channel, + bool perm, + const char *happenings), va_list *ap) { struct subd *sd = tal(ld, struct subd); @@ -661,6 +682,7 @@ static struct subd *new_subd(struct lightningd *ld, sd->msgname = msgname; sd->msgcb = msgcb; sd->errcb = errcb; + sd->billboardcb = billboardcb; sd->fds_in = NULL; msg_queue_init(&sd->outq, sd); tal_add_destructor(sd, destroy_subd); @@ -687,7 +709,7 @@ struct subd *new_global_subd(struct lightningd *ld, struct subd *sd; va_start(ap, msgcb); - sd = new_subd(ld, name, NULL, NULL, msgname, msgcb, NULL, &ap); + sd = new_subd(ld, name, NULL, NULL, msgname, msgcb, NULL, NULL, &ap); va_end(ap); sd->must_not_exit = true; @@ -708,13 +730,16 @@ struct subd *new_channel_subd_(struct lightningd *ld, const struct channel_id *channel_id, const char *desc, const u8 *err_for_them), + void (*billboardcb)(void *channel, bool perm, + const char *happenings), ...) { va_list ap; struct subd *sd; - va_start(ap, errcb); - sd = new_subd(ld, name, channel, base_log, msgname, msgcb, errcb, &ap); + va_start(ap, billboardcb); + sd = new_subd(ld, name, channel, base_log, msgname, + msgcb, errcb, billboardcb, &ap); va_end(ap); return sd; } diff --git a/lightningd/subd.h b/lightningd/subd.h index 874f92779..ac0aa7720 100644 --- a/lightningd/subd.h +++ b/lightningd/subd.h @@ -48,6 +48,9 @@ struct subd { const char *desc, const u8 *err_for_them); + /* Callback to display information for listpeers RPC */ + void (*billboardcb)(void *channel, bool perm, const char *happenings); + /* Buffer for input. */ u8 *msg_in; @@ -93,6 +96,8 @@ struct subd *new_global_subd(struct lightningd *ld, * @base_log: log to use (actually makes a copy so it has name in prefix) * @msgname: function to get name from messages * @msgcb: function to call (inside db transaction) when non-fatal message received (or NULL) + * @errcb: function to call on errors. + * @billboardcb: function to call for billboard updates. * @...: NULL-terminated list of pointers to fds to hand as fd 3, 4... * (can be take, if so, set to -1) * @@ -114,9 +119,12 @@ struct subd *new_channel_subd_(struct lightningd *ld, const struct channel_id *channel_id, const char *desc, const u8 *err_for_them), + void (*billboardcb)(void *channel, bool perm, + const char *happenings), ...); -#define new_channel_subd(ld, name, channel, log, msgname, msgcb, errcb, ...) \ +#define new_channel_subd(ld, name, channel, log, msgname, \ + msgcb, errcb, billboardcb, ...) \ new_channel_subd_((ld), (name), (channel), (log), (msgname), (msgcb), \ typesafe_cb_postargs(void, void *, (errcb), \ (channel), int, int, \ @@ -124,6 +132,9 @@ struct subd *new_channel_subd_(struct lightningd *ld, u64, \ const struct channel_id *, \ const char *, const u8 *), \ + typesafe_cb_postargs(void, void *, (billboardcb), \ + (channel), bool, \ + const char *), \ __VA_ARGS__) /** * subd_raw - raw interface to get a subdaemon on an fd (for HSM)