offers: send a modern onion reply in response to a modern request.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Experimental: Protocol: Updated onion_message support to match updated draft specification (with backwards compat for old version)
This commit is contained in:
Rusty Russell
2021-10-01 06:49:37 +09:30
committed by Christian Decker
parent af7e0a1183
commit 368fc07d05
6 changed files with 148 additions and 19 deletions

View File

@@ -13,6 +13,7 @@ struct inv {
const char *buf;
/* May be NULL */
const jsmntok_t *replytok;
struct tlv_onionmsg_payload_reply_path *reply_path;
/* The offer, once we've looked it up. */
struct tlv_offer *offer;
@@ -40,7 +41,7 @@ fail_inv_level(struct command *cmd,
plugin_log(cmd->plugin, l, "%s", msg);
/* Only reply if they gave us a path */
if (!inv->replytok)
if (!inv->replytok && !inv->reply_path)
return command_hook_success(cmd);
/* Don't send back internal error details. */
@@ -54,7 +55,8 @@ fail_inv_level(struct command *cmd,
errdata = tal_arr(cmd, u8, 0);
towire_invoice_error(&errdata, err);
return send_onion_reply(cmd, inv->buf, inv->replytok, "invoice_error", errdata);
return send_onion_reply(cmd, inv->reply_path, inv->buf, inv->replytok,
"invoice_error", errdata);
}
static struct command_result *WARN_UNUSED_RESULT
@@ -315,7 +317,8 @@ static struct command_result *listoffers_error(struct command *cmd,
struct command_result *handle_invoice(struct command *cmd,
const char *buf,
const jsmntok_t *invtok,
const jsmntok_t *replytok)
const jsmntok_t *replytok,
struct tlv_onionmsg_payload_reply_path *reply_path)
{
const u8 *invbin = json_tok_bin_from_hex(cmd, buf, invtok);
size_t len = tal_count(invbin);
@@ -325,10 +328,17 @@ struct command_result *handle_invoice(struct command *cmd,
int bad_feature;
struct sha256 m, shash;
/* Make a copy of entire buffer, for later. */
inv->buf = tal_dup_arr(inv, char, buf, replytok->end, 0);
inv->replytok = tal_dup_arr(inv, jsmntok_t, replytok,
json_next(replytok) - replytok, 0);
if (reply_path) {
inv->buf = NULL;
inv->replytok = NULL;
inv->reply_path = reply_path;
} else {
/* Make a copy of entire buffer, for later. */
inv->buf = tal_dup_arr(inv, char, buf, replytok->end, 0);
inv->replytok = tal_dup_arr(inv, jsmntok_t, replytok,
json_next(replytok) - replytok, 0);
inv->reply_path = NULL;
}
inv->inv = tlv_invoice_new(cmd);
if (!fromwire_invoice(&invbin, &len, inv->inv)) {