lightningd: don't send other messages until we've received version.

This avoids subdaemons complaining about malformed messages from us,
or doing the completely wrong thing, if they are really the wrong
version.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2021-04-16 14:01:26 +09:30
parent 7b56b2b8ce
commit f97a51cc0f
2 changed files with 15 additions and 1 deletions

View File

@ -419,6 +419,11 @@ static bool handle_version(struct subd *sd, const u8 *msg)
io_break(sd->ld);
return false;
}
sd->rcvd_version = true;
/* In case there are outgoing msgs, we can send now. */
msg_wake(sd->outq);
return true;
}
@ -605,10 +610,15 @@ static void destroy_subd(struct subd *sd)
static struct io_plan *msg_send_next(struct io_conn *conn, struct subd *sd)
{
const u8 *msg = msg_dequeue(sd->outq);
const u8 *msg;
int fd;
/* Don't send if we haven't read version! */
if (!sd->rcvd_version)
return msg_queue_wait(conn, sd->outq, msg_send_next, sd);
/* Nothing to do? Wait for msg_enqueue. */
msg = msg_dequeue(sd->outq);
if (!msg)
return msg_queue_wait(conn, sd->outq, msg_send_next, sd);
@ -702,6 +712,7 @@ static struct subd *new_subd(struct lightningd *ld,
tal_add_destructor(sd, destroy_subd);
list_head_init(&sd->reqs);
sd->channel = channel;
sd->rcvd_version = false;
if (node_id)
sd->node_id = tal_dup(sd, struct node_id, node_id);
else

View File

@ -32,6 +32,9 @@ struct subd {
/* If we are associated with a single channel, this points to it. */
void *channel;
/* Have we received the version msg yet? Don't send until we do. */
bool rcvd_version;
/* For logging */
struct log *log;
const struct node_id *node_id;