connectd: at disconnected, tell lightningd how long we were connected.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2025-11-11 11:33:22 +10:30
parent 88b9b0bc28
commit 565f7deec0
15 changed files with 79 additions and 25 deletions

View File

@@ -43,6 +43,7 @@
static void peer_disconnected(struct lightningd *ld,
const struct node_id *id,
u64 connectd_counter,
u64 connected_time_nsec,
bool fail_connect_attempts);
/* Common pattern: create a sockpair for this channel, return one as a peer_fd */
@@ -1723,21 +1724,22 @@ void handle_peer_connected(struct lightningd *ld, const u8 *msg)
&their_features,
&connect_reason,
&connect_nsec)) {
u64 prev_connectd_counter;
u64 prev_connectd_counter, connected_time_nsec;
if (!fromwire_connectd_peer_reconnected(hook_payload, msg,
&id, &prev_connectd_counter,
&connectd_counter,
&hook_payload->addr,
&hook_payload->remote_addr,
&hook_payload->incoming,
&their_features)) {
&their_features,
&connected_time_nsec)) {
fatal("Connectd gave bad CONNECT_PEER_(RE)CONNECTED message %s",
tal_hex(msg, msg));
}
/* Reconnect? Mark the disconnect *first*, but don't
* fail any connect attempts: this is a race. */
log_peer_debug(ld->log, &id, "peer reconnected");
peer_disconnected(ld, &id, prev_connectd_counter, false);
peer_disconnected(ld, &id, prev_connectd_counter, connected_time_nsec, false);
connect_reason = tal_strdup(hook_payload, "");
connect_nsec = 0;
}
@@ -2083,6 +2085,7 @@ static void destroy_disconnect_command(struct disconnect_command *dc)
static void peer_disconnected(struct lightningd *ld,
const struct node_id *id,
u64 connectd_counter,
u64 connected_time_nsec,
bool fail_connect_attempts)
{
struct disconnect_command *i, *next;
@@ -2127,13 +2130,16 @@ static void peer_disconnected(struct lightningd *ld,
void handle_peer_disconnected(struct lightningd *ld, const u8 *msg)
{
struct node_id id;
u64 connectd_counter;
u64 connectd_counter, connected_time_nsec;
if (!fromwire_connectd_peer_disconnected(msg, &id, &connectd_counter))
if (!fromwire_connectd_peer_disconnected(msg,
&id,
&connectd_counter,
&connected_time_nsec))
fatal("Connectd gave bad PEER_DISCONNECTED message %s",
tal_hex(msg, msg));
peer_disconnected(ld, &id, connectd_counter, true);
peer_disconnected(ld, &id, connectd_counter, connected_time_nsec, true);
}
void update_channel_from_inflight(struct lightningd *ld,

View File

@@ -273,10 +273,10 @@ bool fromwire_channeld_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNE
bool fromwire_connectd_peer_connected(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct node_id *id UNNEEDED, u64 *counter UNNEEDED, struct wireaddr_internal *addr UNNEEDED, struct wireaddr **remote_addr UNNEEDED, bool *incoming UNNEEDED, u8 **features UNNEEDED, wirestring **connect_reason UNNEEDED, u64 *connect_nsec UNNEEDED)
{ fprintf(stderr, "fromwire_connectd_peer_connected called!\n"); abort(); }
/* Generated stub for fromwire_connectd_peer_disconnected */
bool fromwire_connectd_peer_disconnected(const void *p UNNEEDED, struct node_id *id UNNEEDED, u64 *counter UNNEEDED)
bool fromwire_connectd_peer_disconnected(const void *p UNNEEDED, struct node_id *id UNNEEDED, u64 *counter UNNEEDED, u64 *connect_time_nsec UNNEEDED)
{ fprintf(stderr, "fromwire_connectd_peer_disconnected called!\n"); abort(); }
/* Generated stub for fromwire_connectd_peer_reconnected */
bool fromwire_connectd_peer_reconnected(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct node_id *id UNNEEDED, u64 *prev_counter UNNEEDED, u64 *counter UNNEEDED, struct wireaddr_internal *addr UNNEEDED, struct wireaddr **remote_addr UNNEEDED, bool *incoming UNNEEDED, u8 **features UNNEEDED)
bool fromwire_connectd_peer_reconnected(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct node_id *id UNNEEDED, u64 *prev_counter UNNEEDED, u64 *counter UNNEEDED, struct wireaddr_internal *addr UNNEEDED, struct wireaddr **remote_addr UNNEEDED, bool *incoming UNNEEDED, u8 **features UNNEEDED, u64 *connect_time_nsec UNNEEDED)
{ fprintf(stderr, "fromwire_connectd_peer_reconnected called!\n"); abort(); }
/* Generated stub for fromwire_connectd_peer_spoke */
bool fromwire_connectd_peer_spoke(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct node_id *id UNNEEDED, u64 *counter UNNEEDED, u16 *msgtype UNNEEDED, struct channel_id *channel_id UNNEEDED, wirestring **error UNNEEDED)