From c394fd5db2446252ca993cd4ed3f1896f7ba9d64 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 7 Oct 2021 23:23:18 +1030 Subject: [PATCH] common/read_peer_msg: handle pings in handle_peer_gossip_or_error(). This is a noop for now, since gossipd handles them. But that will change in the next patch. Signed-off-by: Rusty Russell --- closingd/Makefile | 1 + common/read_peer_msg.c | 8 +++++++- common/read_peer_msg.h | 2 +- openingd/Makefile | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/closingd/Makefile b/closingd/Makefile index 7e31e6114..6fca67f75 100644 --- a/closingd/Makefile +++ b/closingd/Makefile @@ -47,6 +47,7 @@ CLOSINGD_COMMON_OBJS := \ common/peer_failed.o \ common/per_peer_state.o \ common/permute_tx.o \ + common/ping.o \ common/psbt_open.o \ common/pseudorand.o \ common/read_peer_msg.o \ diff --git a/common/read_peer_msg.c b/common/read_peer_msg.c index 2a521ec20..7fc4b0f05 100644 --- a/common/read_peer_msg.c +++ b/common/read_peer_msg.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -156,6 +157,7 @@ bool handle_peer_gossip_or_error(struct per_peer_state *pps, { char *err; bool warning; + u8 *pong; #if DEVELOPER /* Any odd-typed unknown message is handled by the caller, so if we @@ -174,7 +176,11 @@ bool handle_peer_gossip_or_error(struct per_peer_state *pps, if (handle_timestamp_filter(pps, msg)) return true; - else if (is_msg_for_gossipd(msg)) { + else if (check_ping_make_pong(NULL, msg, &pong)) { + if (pong) + sync_crypto_write(pps, take(pong)); + return true; + } else if (is_msg_for_gossipd(msg)) { gossip_rcvd_filter_add(pps->grf, msg); wire_sync_write(pps->gossip_fd, msg); /* wire_sync_write takes, so don't take again. */ diff --git a/common/read_peer_msg.h b/common/read_peer_msg.h index 698a11976..fbdff761a 100644 --- a/common/read_peer_msg.h +++ b/common/read_peer_msg.h @@ -63,7 +63,7 @@ bool is_wrong_channel(const u8 *msg, const struct channel_id *expected, * * This returns true if it handled the packet: a gossip packet (forwarded * to gossipd), or an error packet (causes peer_failed_received_errmsg or - * ignored). + * ignored), or a ping (may reply with pong). */ bool handle_peer_gossip_or_error(struct per_peer_state *pps, const struct channel_id *channel_id, diff --git a/openingd/Makefile b/openingd/Makefile index b0fc6ef27..091f51ca1 100644 --- a/openingd/Makefile +++ b/openingd/Makefile @@ -70,6 +70,7 @@ OPENINGD_COMMON_OBJS := \ common/peer_billboard.o \ common/peer_failed.o \ common/permute_tx.o \ + common/ping.o \ common/psbt_internal.o \ common/psbt_open.o \ common/pseudorand.o \