|
13 | 13 | #include <common/features.h> |
14 | 14 | #include <common/peer_failed.h> |
15 | 15 | #include <common/per_peer_state.h> |
| 16 | +#include <common/ping.h> |
16 | 17 | #include <common/status.h> |
17 | 18 | #include <inttypes.h> |
18 | 19 | #include <netdb.h> |
|
26 | 27 | #define io_close simple_close |
27 | 28 | static bool stream_stdin = false; |
28 | 29 | static bool no_init = false; |
| 30 | +static bool handle_pings = false; |
29 | 31 | static bool hex = false; |
30 | 32 | static bool explicit_network = false; |
31 | 33 | static int timeout_after = -1; |
@@ -250,9 +252,17 @@ static struct io_plan *handshake_success(struct io_conn *conn, |
250 | 252 | sync_crypto_write(peer_fd, cs, take(msg)); |
251 | 253 | } |
252 | 254 | } else if (pollfd[1].revents & POLLIN) { |
| 255 | + u8 *pong; |
| 256 | + |
253 | 257 | msg = sync_crypto_read(NULL, peer_fd, cs); |
254 | 258 | if (!msg) |
255 | 259 | 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 | + } |
256 | 266 | if (!accept_message(msg)) { |
257 | 267 | tal_free(msg); |
258 | 268 | continue; |
@@ -330,6 +340,8 @@ int main(int argc, char *argv[]) |
330 | 340 |
|
331 | 341 | opt_register_noarg("--all-gossip", opt_set_bool, &all_gossip, |
332 | 342 | "Stream complete gossip history at start"); |
| 343 | + opt_register_noarg("--handle-pings", opt_set_bool, &handle_pings, |
| 344 | + "Reply to pings"); |
333 | 345 | opt_register_noarg("--no-gossip", opt_set_bool, &no_gossip, |
334 | 346 | "Suppress all gossip at start"); |
335 | 347 | opt_register_arg("--filter", opt_set_filter, NULL, &accept_messages, |
|
0 commit comments