mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 17:47:30 +01:00
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:
parent
7b56b2b8ce
commit
f97a51cc0f
2 changed files with 15 additions and 1 deletions
|
@ -419,6 +419,11 @@ static bool handle_version(struct subd *sd, const u8 *msg)
|
||||||
io_break(sd->ld);
|
io_break(sd->ld);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sd->rcvd_version = true;
|
||||||
|
/* In case there are outgoing msgs, we can send now. */
|
||||||
|
msg_wake(sd->outq);
|
||||||
|
|
||||||
return true;
|
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)
|
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;
|
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. */
|
/* Nothing to do? Wait for msg_enqueue. */
|
||||||
|
msg = msg_dequeue(sd->outq);
|
||||||
if (!msg)
|
if (!msg)
|
||||||
return msg_queue_wait(conn, sd->outq, msg_send_next, sd);
|
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);
|
tal_add_destructor(sd, destroy_subd);
|
||||||
list_head_init(&sd->reqs);
|
list_head_init(&sd->reqs);
|
||||||
sd->channel = channel;
|
sd->channel = channel;
|
||||||
|
sd->rcvd_version = false;
|
||||||
if (node_id)
|
if (node_id)
|
||||||
sd->node_id = tal_dup(sd, struct node_id, node_id);
|
sd->node_id = tal_dup(sd, struct node_id, node_id);
|
||||||
else
|
else
|
||||||
|
|
|
@ -32,6 +32,9 @@ struct subd {
|
||||||
/* If we are associated with a single channel, this points to it. */
|
/* If we are associated with a single channel, this points to it. */
|
||||||
void *channel;
|
void *channel;
|
||||||
|
|
||||||
|
/* Have we received the version msg yet? Don't send until we do. */
|
||||||
|
bool rcvd_version;
|
||||||
|
|
||||||
/* For logging */
|
/* For logging */
|
||||||
struct log *log;
|
struct log *log;
|
||||||
const struct node_id *node_id;
|
const struct node_id *node_id;
|
||||||
|
|
Loading…
Add table
Reference in a new issue