|
|
@ -1,4 +1,6 @@ |
|
|
|
#include <common/ping.h> |
|
|
|
#include <common/status.h> |
|
|
|
#include <common/version.h> |
|
|
|
#include <wire/gen_peer_wire.h> |
|
|
|
|
|
|
|
bool check_ping_make_pong(const tal_t *ctx, const u8 *ping, u8 **pong) |
|
|
@ -31,6 +33,10 @@ bool check_ping_make_pong(const tal_t *ctx, const u8 *ping, u8 **pong) |
|
|
|
* as secrets, or portions of initialized memory. |
|
|
|
*/ |
|
|
|
ignored = tal_arrz(ctx, u8, num_pong_bytes); |
|
|
|
#if DEVELOPER |
|
|
|
/* Embed version */ |
|
|
|
strncpy((char *)ignored, version(), num_pong_bytes); |
|
|
|
#endif |
|
|
|
*pong = towire_pong(ctx, ignored); |
|
|
|
tal_free(ignored); |
|
|
|
} else |
|
|
@ -53,3 +59,25 @@ u8 *make_ping(const tal_t *ctx, u16 num_pong_bytes, u16 padlen) |
|
|
|
tal_free(ignored); |
|
|
|
return ping; |
|
|
|
} |
|
|
|
|
|
|
|
const char *got_pong(const u8 *pong, size_t *num_pings_outstanding) |
|
|
|
{ |
|
|
|
u8 *ignored; |
|
|
|
int i; |
|
|
|
|
|
|
|
if (!fromwire_pong(pong, pong, &ignored)) |
|
|
|
return "Bad pong"; |
|
|
|
|
|
|
|
if (*num_pings_outstanding == 0) |
|
|
|
return "Unexpected pong"; |
|
|
|
|
|
|
|
for (i = 0; i < tal_len(ignored); i++) { |
|
|
|
if (ignored[i] < ' ' || ignored[i] == 127) |
|
|
|
break; |
|
|
|
} |
|
|
|
status_trace("Got pong %zu bytes (%.*s...)", |
|
|
|
tal_len(ignored), i, (char *)ignored); |
|
|
|
|
|
|
|
(*num_pings_outstanding)--; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|