| 5 | #include <wire/peer_wire.h> |
| 6 | |
| 7 | bool 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 | |
| 46 | u8 *make_ping(const tal_t *ctx, u16 num_pong_bytes, u16 padlen) |
| 47 | { |
no test coverage detected