From 72a8fa20f75ee063e4d3f685771ec991ac04870e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 16 May 2025 20:04:13 +0930 Subject: [PATCH] gossipwith: add --handle-pings flag. Required for long gossips, where we might get timed out for not replying to pings. Signed-off-by: Rusty Russell --- devtools/Makefile | 2 +- devtools/gossipwith.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/devtools/Makefile b/devtools/Makefile index bdceecc7e..a80ebe4ab 100644 --- a/devtools/Makefile +++ b/devtools/Makefile @@ -79,7 +79,7 @@ devtools/onion.c: ccan/config.h devtools/onion: $(DEVTOOLS_COMMON_OBJS) $(JSMN_OBJS) $(BITCOIN_OBJS) common/onion_decode.o common/onion_encode.o common/onionreply.o wire/fromwire.o wire/towire.o devtools/onion.o common/sphinx.o -devtools/gossipwith: $(DEVTOOLS_COMMON_OBJS) $(JSMN_OBJS) $(BITCOIN_OBJS) wire/fromwire.o wire/towire.o wire/peer_wiregen.o devtools/gossipwith.o common/cryptomsg.o common/cryptomsg.o +devtools/gossipwith: $(DEVTOOLS_COMMON_OBJS) $(JSMN_OBJS) $(BITCOIN_OBJS) wire/fromwire.o wire/towire.o wire/peer_wiregen.o devtools/gossipwith.o common/cryptomsg.o common/ping.o $(DEVTOOLS_OBJS) $(DEVTOOLS_TOOL_OBJS): wire/wire.h diff --git a/devtools/gossipwith.c b/devtools/gossipwith.c index 9acb85fca..c6f427f54 100644 --- a/devtools/gossipwith.c +++ b/devtools/gossipwith.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,7 @@ #define io_close simple_close static bool stream_stdin = false; static bool no_init = false; +static bool handle_pings = false; static bool hex = false; static bool explicit_network = false; static int timeout_after = -1; @@ -250,9 +252,17 @@ static struct io_plan *handshake_success(struct io_conn *conn, sync_crypto_write(peer_fd, cs, take(msg)); } } else if (pollfd[1].revents & POLLIN) { + u8 *pong; + msg = sync_crypto_read(NULL, peer_fd, cs); if (!msg) err(1, "Reading msg"); + if (handle_pings + && fromwire_peektype(msg) == WIRE_PING + && check_ping_make_pong(tmpctx, msg, &pong) + && pong) { + sync_crypto_write(peer_fd, cs, take(pong)); + } if (!accept_message(msg)) { tal_free(msg); continue; @@ -330,6 +340,8 @@ int main(int argc, char *argv[]) opt_register_noarg("--all-gossip", opt_set_bool, &all_gossip, "Stream complete gossip history at start"); + opt_register_noarg("--handle-pings", opt_set_bool, &handle_pings, + "Reply to pings"); opt_register_noarg("--no-gossip", opt_set_bool, &no_gossip, "Suppress all gossip at start"); opt_register_arg("--filter", opt_set_filter, NULL, &accept_messages,