mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 10:46:58 +01:00
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>
This commit is contained in:
parent
eb61446ec8
commit
e36a65a189
5 changed files with 13 additions and 12 deletions
|
@ -128,7 +128,7 @@ static void peer_ready(struct subd *gossip, const u8 *msg)
|
||||||
peer_set_condition(peer, "Exchanging gossip");
|
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);
|
enum gossip_wire_type t = fromwire_peektype(msg);
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ static void hsm_finished(struct subd *hsm, int status)
|
||||||
errx(1, "HSM failed (signal %u), exiting.", WTERMSIG(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);
|
enum hsm_wire_type t = fromwire_peektype(msg);
|
||||||
u8 *badmsg;
|
u8 *badmsg;
|
||||||
|
|
|
@ -616,9 +616,7 @@ static bool opening_got_hsm_funding_sig(struct subd *hsm, const u8 *resp,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t update_channel_status(struct subd *sd,
|
static int channel_msg(struct subd *sd, const u8 *msg, const int *unused)
|
||||||
const u8 *msg,
|
|
||||||
const int *unused)
|
|
||||||
{
|
{
|
||||||
enum channel_wire_type t = fromwire_peektype(msg);
|
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,
|
peer->owner = new_subd(peer->ld, peer->ld,
|
||||||
"lightningd_channel", peer,
|
"lightningd_channel", peer,
|
||||||
channel_wire_type_name,
|
channel_wire_type_name,
|
||||||
update_channel_status, NULL,
|
channel_msg, NULL,
|
||||||
peer->fd, peer->gossip_client_fd, -1);
|
peer->fd, peer->gossip_client_fd, -1);
|
||||||
if (!peer->owner) {
|
if (!peer->owner) {
|
||||||
log_unusual(peer->log, "Could not subdaemon channel: %s",
|
log_unusual(peer->log, "Could not subdaemon channel: %s",
|
||||||
|
|
|
@ -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));
|
log_info(sd->log, "UPDATE %s", sd->msgname(type));
|
||||||
|
|
||||||
if (sd->msgcb) {
|
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) {
|
if (i != 0) {
|
||||||
/* Don't ask for fds twice! */
|
/* Don't ask for fds twice! */
|
||||||
assert(!sd->fds_in);
|
assert(!sd->fds_in);
|
||||||
|
@ -328,8 +330,8 @@ struct subd *new_subd(const tal_t *ctx,
|
||||||
const char *name,
|
const char *name,
|
||||||
struct peer *peer,
|
struct peer *peer,
|
||||||
const char *(*msgname)(int msgtype),
|
const char *(*msgname)(int msgtype),
|
||||||
size_t (*msgcb)(struct subd *, const u8 *,
|
int (*msgcb)(struct subd *, const u8 *,
|
||||||
const int *fds),
|
const int *fds),
|
||||||
void (*finished)(struct subd *, int),
|
void (*finished)(struct subd *, int),
|
||||||
...)
|
...)
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,7 +30,7 @@ struct subd {
|
||||||
struct log *log;
|
struct log *log;
|
||||||
|
|
||||||
/* Callback when non-reply message comes in. */
|
/* 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);
|
const char *(*msgname)(int msgtype);
|
||||||
void (*finished)(struct subd *sd, int status);
|
void (*finished)(struct subd *sd, int status);
|
||||||
|
|
||||||
|
@ -60,7 +60,8 @@ struct subd {
|
||||||
* @...: the fds to hand as fd 3, 4... terminated with -1.
|
* @...: 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,
|
* @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.
|
* If this succeeds subd owns @peer.
|
||||||
*/
|
*/
|
||||||
|
@ -69,7 +70,7 @@ struct subd *new_subd(const tal_t *ctx,
|
||||||
const char *name,
|
const char *name,
|
||||||
struct peer *peer,
|
struct peer *peer,
|
||||||
const char *(*msgname)(int msgtype),
|
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), ...);
|
void (*finished)(struct subd *, int), ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue