sphinx: rename confusing functions, ensure valid payloads.

"sphinx_add_hop" takes a literal hop to include,
"sphinx_add_modern_hop" prepends the length.  Now we always prepend a
length, make it clear that the literal version is a shortcut:

* sphinx_add_hop -> sphinx_add_hop_has_length
* sphinx_add_modern_hop -> sphinx_add_hop

In addition, we check that length is actually correct!  This means
`createonion` can no longer create legacy or otherwise-invalid onions:
fix tests and update man page to remove legacy usage.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: JSON-RPC: `createonion` no longer allows non-TLV-style payloads.
This commit is contained in:
Rusty Russell
2022-09-28 14:19:37 +09:30
committed by Christian Decker
parent 8771c86379
commit f00cc23f67
11 changed files with 59 additions and 49 deletions

View File

@@ -202,17 +202,19 @@ struct sphinx_path *sphinx_path_new_with_key(const tal_t *ctx,
const struct secret *session_key);
/**
* Add a payload hop to the path.
* Add a payload hop to the path (already has length prepended).
*
* Fails if length actually isn't prepended!
*/
void sphinx_add_hop(struct sphinx_path *path, const struct pubkey *pubkey,
const u8 *payload TAKES);
bool sphinx_add_hop_has_length(struct sphinx_path *path, const struct pubkey *pubkey,
const u8 *payload TAKES);
/**
* Prepend length to payload and add: for onionmessage, any size is OK,
* for HTLC onions tal_bytelen(payload) must be > 1.
*/
void sphinx_add_modern_hop(struct sphinx_path *path, const struct pubkey *pubkey,
const u8 *payload TAKES);
void sphinx_add_hop(struct sphinx_path *path, const struct pubkey *pubkey,
const u8 *payload TAKES);
/**
* Compute the size of the serialized payloads.