Browse Source

subd: handle status_peer_billboard messages from subdaemons.

We use a callback which updates the appropriate slot.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
26b004e5af
  1. 3
      common/status_wire.csv
  2. 1
      lightningd/channel_control.c
  3. 1
      lightningd/closing_control.c
  4. 1
      lightningd/onchain_control.c
  5. 11
      lightningd/opening_control.c
  6. 31
      lightningd/subd.c
  7. 13
      lightningd/subd.h

3
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!

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

1
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));

1
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) {

1
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) {

11
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) {

31
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;
}

13
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)

Loading…
Cancel
Save