MCPcopy Create free account
hub / github.com/ElementsProject/lightning / check_ping_make_pong

Function check_ping_make_pong

common/ping.c:7–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include <wire/peer_wire.h>
6
7bool check_ping_make_pong(const tal_t *ctx, const u8 *ping, u8 **pong)
8{
9 u16 num_pong_bytes;
10 u8 *ignored;
11
12 if (!fromwire_ping(ctx, ping, &num_pong_bytes, &ignored))
13 return false;
14 tal_free(ignored);
15
16 /* BOLT #1:
17 *
18 * A node receiving a `ping` message:
19 * - if `num_pong_bytes` is less than 65532:
20 * - MUST respond by sending a `pong` message, with `byteslen` equal
21 * to `num_pong_bytes`.
22 * - otherwise (`num_pong_bytes` is **not** less than 65532):
23 * - MUST ignore the `ping`.
24 */
25 if (num_pong_bytes < 65532) {
26 /* BOLT #1:
27 *
28 * A node sending a `pong` message:
29 * - SHOULD set `ignored` to 0s.
30 * - MUST NOT set `ignored` to sensitive data such as secrets
31 * or portions of initialized memory.
32 */
33 ignored = tal_arrz(ctx, u8, num_pong_bytes);
34#if DEVELOPER
35 /* Embed version */
36 strncpy((char *)ignored, version(), num_pong_bytes);
37#endif
38 *pong = towire_pong(ctx, ignored);
39 tal_free(ignored);
40 } else
41 *pong = NULL;
42
43 return true;
44}
45
46u8 *make_ping(const tal_t *ctx, u16 num_pong_bytes, u16 padlen)
47{

Callers 1

handle_ping_inFunction · 0.85

Calls 2

tal_freeFunction · 0.85
versionFunction · 0.70

Tested by

no test coverage detected