lightningd: make "is peer connected" a tristate.

First, connectd tells us the peer has connected, and we call the connected hook,
and if it says it's fine, we are actually connected and we fire off notifications.

Of course, we could be disconnected while in the connected hook, and that would
mean we tell people about a connection which is no longer current.

Make this clear with a tristate: if we're not marked disconnected by
the time the hooks finish, we're good.  It also gives us a cleaner
"connect" command return when we connected but disconnected before
processing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-07-16 14:19:31 +09:30
committed by neil saitug
parent 571f0fad1b
commit eff53495db
10 changed files with 104 additions and 42 deletions

View File

@@ -31,7 +31,14 @@ struct peer {
struct list_head channels;
/* Are we connected? */
bool is_connected;
enum {
/* Connectd said we're connecting, we called hooks... */
PEER_CONNECTING,
/* Hooks succeeded, we're connected. */
PEER_CONNECTED,
/* Start state, also connectd told us we're disconnected */
PEER_DISCONNECTED,
} connected;
/* Our (only) uncommitted channel, still opening. */
struct uncommitted_channel *uncommitted_channel;
@@ -70,6 +77,7 @@ struct peer *peer_from_json(struct lightningd *ld,
const char *buffer,
const jsmntok_t *peeridtok);
/* connectd tells us what peer is doing */
void peer_connected(struct lightningd *ld, const u8 *msg);
void peer_disconnect_done(struct lightningd *ld, const u8 *msg);
void peer_active(struct lightningd *ld, const u8 *msg, int peer_fd);