Skip to content

Commit 72a8fa2

Browse files
committed
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 <[email protected]>
1 parent 40a86da commit 72a8fa2

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

devtools/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ devtools/onion.c: ccan/config.h
7979

8080
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
8181

82-
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
82+
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
8383

8484
$(DEVTOOLS_OBJS) $(DEVTOOLS_TOOL_OBJS): wire/wire.h
8585

devtools/gossipwith.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <common/features.h>
1414
#include <common/peer_failed.h>
1515
#include <common/per_peer_state.h>
16+
#include <common/ping.h>
1617
#include <common/status.h>
1718
#include <inttypes.h>
1819
#include <netdb.h>
@@ -26,6 +27,7 @@
2627
#define io_close simple_close
2728
static bool stream_stdin = false;
2829
static bool no_init = false;
30+
static bool handle_pings = false;
2931
static bool hex = false;
3032
static bool explicit_network = false;
3133
static int timeout_after = -1;
@@ -250,9 +252,17 @@ static struct io_plan *handshake_success(struct io_conn *conn,
250252
sync_crypto_write(peer_fd, cs, take(msg));
251253
}
252254
} else if (pollfd[1].revents & POLLIN) {
255+
u8 *pong;
256+
253257
msg = sync_crypto_read(NULL, peer_fd, cs);
254258
if (!msg)
255259
err(1, "Reading msg");
260+
if (handle_pings
261+
&& fromwire_peektype(msg) == WIRE_PING
262+
&& check_ping_make_pong(tmpctx, msg, &pong)
263+
&& pong) {
264+
sync_crypto_write(peer_fd, cs, take(pong));
265+
}
256266
if (!accept_message(msg)) {
257267
tal_free(msg);
258268
continue;
@@ -330,6 +340,8 @@ int main(int argc, char *argv[])
330340

331341
opt_register_noarg("--all-gossip", opt_set_bool, &all_gossip,
332342
"Stream complete gossip history at start");
343+
opt_register_noarg("--handle-pings", opt_set_bool, &handle_pings,
344+
"Reply to pings");
333345
opt_register_noarg("--no-gossip", opt_set_bool, &no_gossip,
334346
"Suppress all gossip at start");
335347
opt_register_arg("--filter", opt_set_filter, NULL, &accept_messages,

0 commit comments

Comments
 (0)