Browse Source

lightningd/subd: msgcb return -1 to close channel.

They can't free it while we're using it, but they can return a value
to close it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
e36a65a189
  1. 2
      lightningd/gossip_control.c
  2. 2
      lightningd/hsm_control.c
  3. 6
      lightningd/peer_control.c
  4. 8
      lightningd/subd.c
  5. 7
      lightningd/subd.h

2
lightningd/gossip_control.c

@ -128,7 +128,7 @@ static void peer_ready(struct subd *gossip, const u8 *msg)
peer_set_condition(peer, "Exchanging gossip");
}
static size_t gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
static int gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
{
enum gossip_wire_type t = fromwire_peektype(msg);

2
lightningd/hsm_control.c

@ -38,7 +38,7 @@ static void hsm_finished(struct subd *hsm, int status)
errx(1, "HSM failed (signal %u), exiting.", WTERMSIG(status));
}
static size_t hsm_msg(struct subd *hsm, const u8 *msg, const int *fds)
static int hsm_msg(struct subd *hsm, const u8 *msg, const int *fds)
{
enum hsm_wire_type t = fromwire_peektype(msg);
u8 *badmsg;

6
lightningd/peer_control.c

@ -616,9 +616,7 @@ static bool opening_got_hsm_funding_sig(struct subd *hsm, const u8 *resp,
return true;
}
static size_t update_channel_status(struct subd *sd,
const u8 *msg,
const int *unused)
static int channel_msg(struct subd *sd, const u8 *msg, const int *unused)
{
enum channel_wire_type t = fromwire_peektype(msg);
@ -674,7 +672,7 @@ static void peer_start_channeld(struct peer *peer, bool am_funder,
peer->owner = new_subd(peer->ld, peer->ld,
"lightningd_channel", peer,
channel_wire_type_name,
update_channel_status, NULL,
channel_msg, NULL,
peer->fd, peer->gossip_client_fd, -1);
if (!peer->owner) {
log_unusual(peer->log, "Could not subdaemon channel: %s",

8
lightningd/subd.c

@ -262,7 +262,9 @@ static struct io_plan *sd_msg_read(struct io_conn *conn, struct subd *sd)
log_info(sd->log, "UPDATE %s", sd->msgname(type));
if (sd->msgcb) {
size_t i = sd->msgcb(sd, sd->msg_in, sd->fds_in);
int i = sd->msgcb(sd, sd->msg_in, sd->fds_in);
if (i < 0)
return io_close(conn);
if (i != 0) {
/* Don't ask for fds twice! */
assert(!sd->fds_in);
@ -328,8 +330,8 @@ struct subd *new_subd(const tal_t *ctx,
const char *name,
struct peer *peer,
const char *(*msgname)(int msgtype),
size_t (*msgcb)(struct subd *, const u8 *,
const int *fds),
int (*msgcb)(struct subd *, const u8 *,
const int *fds),
void (*finished)(struct subd *, int),
...)
{

7
lightningd/subd.h

@ -30,7 +30,7 @@ struct subd {
struct log *log;
/* Callback when non-reply message comes in. */
size_t (*msgcb)(struct subd *, const u8 *, const int *);
int (*msgcb)(struct subd *, const u8 *, const int *);
const char *(*msgname)(int msgtype);
void (*finished)(struct subd *sd, int status);
@ -60,7 +60,8 @@ struct subd {
* @...: the fds to hand as fd 3, 4... terminated with -1.
*
* @msgcb gets called with @fds set to NULL: if it returns a positive number,
* that many @fds are received before calling again.
* that many @fds are received before calling again. If it returns -1, the
* subdaemon is shutdown.
*
* If this succeeds subd owns @peer.
*/
@ -69,7 +70,7 @@ struct subd *new_subd(const tal_t *ctx,
const char *name,
struct peer *peer,
const char *(*msgname)(int msgtype),
size_t (*msgcb)(struct subd *, const u8 *, const int *fds),
int (*msgcb)(struct subd *, const u8 *, const int *fds),
void (*finished)(struct subd *, int), ...);
/**

Loading…
Cancel
Save