core-lightning/common/ping.c
Rusty Russell 2526e804f7 doc: big BOLT update to incorporate warnings language.
We do this (send warnings) in almost all cases anyway, so mainly this
is a textual update, but there are some changes:

1. Send ERROR not WARNING if they send a malformed commitment secret.
2. Send WARNING not ERROR if they get the shutdown_scriptpubkey wrong (vs upfront)
3. Send WARNING not ERROR if they send a bad shutdown_scriptpubkey (e.g. p2pkh in future)
4. Rename some vars 'err' to 'warn' to make it clear we send a warning.

This means test_option_upfront_shutdown_script can be made reliable, too,
and it now warns and doesn't automatically close channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-02 09:40:18 +10:30

61 lines
1.5 KiB
C

#include "config.h"
#include <common/ping.h>
#include <common/status.h>
#include <common/version.h>
#include <wire/peer_wire.h>
bool check_ping_make_pong(const tal_t *ctx, const u8 *ping, u8 **pong)
{
u16 num_pong_bytes;
u8 *ignored;
if (!fromwire_ping(ctx, ping, &num_pong_bytes, &ignored))
return false;
tal_free(ignored);
/* BOLT #1:
*
* A node receiving a `ping` message:
* - if `num_pong_bytes` is less than 65532:
* - MUST respond by sending a `pong` message, with `byteslen` equal
* to `num_pong_bytes`.
* - otherwise (`num_pong_bytes` is **not** less than 65532):
* - MUST ignore the `ping`.
*/
if (num_pong_bytes < 65532) {
/* BOLT #1:
*
* A node sending a `pong` message:
* - SHOULD set `ignored` to 0s.
* - MUST NOT set `ignored` to sensitive data such 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
*pong = NULL;
return true;
}
u8 *make_ping(const tal_t *ctx, u16 num_pong_bytes, u16 padlen)
{
/* BOLT #1:
*
* A node sending a `ping` message:
* - SHOULD set `ignored` to 0s.
* - MUST NOT set `ignored` to sensitive data such as secrets or
* portions of initialized memory.
*/
u8 *ping, *ignored = tal_arrz(ctx, u8, padlen);
ping = towire_ping(ctx, num_pong_bytes, ignored);
tal_free(ignored);
return ping;
}