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

Function check_ping_make_pong

common/ping.c:5–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

handle_ping_inFunction · 0.85
handshake_successFunction · 0.85

Calls 1

tal_freeFunction · 0.85

Tested by

no test coverage detected