mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 23:54:22 +01:00
onionmessages: remove obsolete onion message parsing.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -645,94 +645,12 @@ struct sending {
|
||||
struct sent *sent;
|
||||
const char *msgfield;
|
||||
const u8 *msgval;
|
||||
struct tlv_obs2_onionmsg_payload_reply_path *obs2_reply_path;
|
||||
struct command_result *(*done)(struct command *cmd,
|
||||
const char *buf UNUSED,
|
||||
const jsmntok_t *result UNUSED,
|
||||
struct sent *sent);
|
||||
};
|
||||
|
||||
static struct command_result *
|
||||
send_obs2_message(struct command *cmd,
|
||||
const char *buf,
|
||||
const jsmntok_t *result,
|
||||
struct sending *sending)
|
||||
{
|
||||
struct sent *sent = sending->sent;
|
||||
struct privkey blinding_iter;
|
||||
struct pubkey fwd_blinding, *node_alias;
|
||||
size_t nhops = tal_count(sent->path);
|
||||
struct tlv_obs2_onionmsg_payload **payloads;
|
||||
struct out_req *req;
|
||||
|
||||
/* Now create enctlvs for *forward* path. */
|
||||
randombytes_buf(&blinding_iter, sizeof(blinding_iter));
|
||||
if (!pubkey_from_privkey(&blinding_iter, &fwd_blinding))
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"Could not convert blinding %s to pubkey!",
|
||||
type_to_string(tmpctx, struct privkey,
|
||||
&blinding_iter));
|
||||
|
||||
/* We overallocate: this node (0) doesn't have payload or alias */
|
||||
payloads = tal_arr(cmd, struct tlv_obs2_onionmsg_payload *, nhops);
|
||||
node_alias = tal_arr(cmd, struct pubkey, nhops);
|
||||
|
||||
for (size_t i = 1; i < nhops - 1; i++) {
|
||||
payloads[i] = tlv_obs2_onionmsg_payload_new(payloads);
|
||||
payloads[i]->enctlv = create_obs2_enctlv(payloads[i],
|
||||
&blinding_iter,
|
||||
&sent->path[i],
|
||||
&sent->path[i+1],
|
||||
/* FIXME: Pad? */
|
||||
0,
|
||||
NULL,
|
||||
&blinding_iter,
|
||||
&node_alias[i]);
|
||||
}
|
||||
/* Final payload contains the actual data. */
|
||||
payloads[nhops-1] = tlv_obs2_onionmsg_payload_new(payloads);
|
||||
|
||||
/* We don't include enctlv in final, but it gives us final alias */
|
||||
if (!create_obs2_final_enctlv(tmpctx, &blinding_iter, &sent->path[nhops-1],
|
||||
/* FIXME: Pad? */ 0,
|
||||
NULL,
|
||||
&node_alias[nhops-1])) {
|
||||
/* Should not happen! */
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"Could create final enctlv");
|
||||
}
|
||||
|
||||
/* FIXME: This interface is a string for sendobsonionmessage! */
|
||||
if (streq(sending->msgfield, "invoice_request")) {
|
||||
payloads[nhops-1]->invoice_request
|
||||
= cast_const(u8 *, sending->msgval);
|
||||
} else {
|
||||
assert(streq(sending->msgfield, "invoice"));
|
||||
payloads[nhops-1]->invoice
|
||||
= cast_const(u8 *, sending->msgval);
|
||||
}
|
||||
payloads[nhops-1]->reply_path = sending->obs2_reply_path;
|
||||
|
||||
req = jsonrpc_request_start(cmd->plugin, cmd, "sendobs2onionmessage",
|
||||
sending->done,
|
||||
forward_error,
|
||||
sending->sent);
|
||||
json_add_pubkey(req->js, "first_id", &sent->path[1]);
|
||||
json_add_pubkey(req->js, "blinding", &fwd_blinding);
|
||||
json_array_start(req->js, "hops");
|
||||
for (size_t i = 1; i < nhops; i++) {
|
||||
u8 *tlv;
|
||||
json_object_start(req->js, NULL);
|
||||
json_add_pubkey(req->js, "id", &node_alias[i]);
|
||||
tlv = tal_arr(tmpctx, u8, 0);
|
||||
towire_tlv_obs2_onionmsg_payload(&tlv, payloads[i]);
|
||||
json_add_hex_talarr(req->js, "tlv", tlv);
|
||||
json_object_end(req->js);
|
||||
}
|
||||
json_array_end(req->js);
|
||||
return send_outreq(cmd->plugin, req);
|
||||
}
|
||||
|
||||
static struct command_result *
|
||||
send_modern_message(struct command *cmd,
|
||||
struct tlv_onionmsg_payload_reply_path *reply_path,
|
||||
@@ -794,10 +712,9 @@ send_modern_message(struct command *cmd,
|
||||
payloads[nhops-1]->reply_path = reply_path;
|
||||
|
||||
req = jsonrpc_request_start(cmd->plugin, cmd, "sendonionmessage",
|
||||
/* Try sending older version next */
|
||||
send_obs2_message,
|
||||
sending->done,
|
||||
forward_error,
|
||||
sending);
|
||||
sending->sent);
|
||||
json_add_pubkey(req->js, "first_id", &sent->path[1]);
|
||||
json_add_pubkey(req->js, "blinding", &fwd_blinding);
|
||||
json_array_start(req->js, "hops");
|
||||
@@ -831,15 +748,6 @@ static struct command_result *use_reply_path(struct command *cmd,
|
||||
json_tok_full_len(result),
|
||||
json_tok_full(buf, result));
|
||||
|
||||
sending->obs2_reply_path = json_to_obs2_reply_path(cmd, buf,
|
||||
json_get_member(buf, result,
|
||||
"obs2blindedpath"));
|
||||
if (!sending->obs2_reply_path)
|
||||
plugin_err(cmd->plugin,
|
||||
"could not parse obs2 reply path %.*s?",
|
||||
json_tok_full_len(result),
|
||||
json_tok_full(buf, result));
|
||||
|
||||
/* Remember our alias we used so we can recognize reply */
|
||||
sending->sent->reply_alias
|
||||
= tal_dup(sending->sent, struct pubkey,
|
||||
|
||||
@@ -44,64 +44,15 @@ static struct command_result *sendonionmessage_error(struct command *cmd,
|
||||
}
|
||||
|
||||
/* FIXME: replyfield string interface is to accomodate obsolete API */
|
||||
static struct command_result *
|
||||
send_obs2_onion_reply(struct command *cmd,
|
||||
struct tlv_obs2_onionmsg_payload_reply_path *reply_path,
|
||||
const char *replyfield,
|
||||
const u8 *replydata)
|
||||
{
|
||||
struct out_req *req;
|
||||
size_t nhops = tal_count(reply_path->path);
|
||||
|
||||
req = jsonrpc_request_start(cmd->plugin, cmd, "sendobs2onionmessage",
|
||||
finished, sendonionmessage_error, NULL);
|
||||
|
||||
json_add_pubkey(req->js, "first_id", &reply_path->first_node_id);
|
||||
json_add_pubkey(req->js, "blinding", &reply_path->blinding);
|
||||
json_array_start(req->js, "hops");
|
||||
for (size_t i = 0; i < nhops; i++) {
|
||||
struct tlv_obs2_onionmsg_payload *omp;
|
||||
u8 *tlv;
|
||||
|
||||
json_object_start(req->js, NULL);
|
||||
json_add_pubkey(req->js, "id", &reply_path->path[i]->node_id);
|
||||
|
||||
omp = tlv_obs2_onionmsg_payload_new(tmpctx);
|
||||
omp->enctlv = reply_path->path[i]->encrypted_recipient_data;
|
||||
|
||||
/* Put payload in last hop. */
|
||||
if (i == nhops - 1) {
|
||||
if (streq(replyfield, "invoice")) {
|
||||
omp->invoice = cast_const(u8 *, replydata);
|
||||
} else {
|
||||
assert(streq(replyfield, "invoice_error"));
|
||||
omp->invoice_error = cast_const(u8 *, replydata);
|
||||
}
|
||||
}
|
||||
tlv = tal_arr(tmpctx, u8, 0);
|
||||
towire_tlv_obs2_onionmsg_payload(&tlv, omp);
|
||||
json_add_hex_talarr(req->js, "tlv", tlv);
|
||||
json_object_end(req->js);
|
||||
}
|
||||
json_array_end(req->js);
|
||||
return send_outreq(cmd->plugin, req);
|
||||
}
|
||||
|
||||
struct command_result *
|
||||
send_onion_reply(struct command *cmd,
|
||||
struct tlv_onionmsg_payload_reply_path *reply_path,
|
||||
struct tlv_obs2_onionmsg_payload_reply_path *obs2_reply_path,
|
||||
const char *replyfield,
|
||||
const u8 *replydata)
|
||||
{
|
||||
struct out_req *req;
|
||||
size_t nhops;
|
||||
|
||||
/* Exactly one must be set! */
|
||||
assert(!reply_path != !obs2_reply_path);
|
||||
if (obs2_reply_path)
|
||||
return send_obs2_onion_reply(cmd, obs2_reply_path, replyfield, replydata);
|
||||
|
||||
req = jsonrpc_request_start(cmd->plugin, cmd, "sendonionmessage",
|
||||
finished, sendonionmessage_error, NULL);
|
||||
|
||||
@@ -143,7 +94,6 @@ static struct command_result *onion_message_modern_call(struct command *cmd,
|
||||
const jsmntok_t *params)
|
||||
{
|
||||
const jsmntok_t *om, *replytok, *invreqtok, *invtok;
|
||||
struct tlv_obs2_onionmsg_payload_reply_path *obs2_reply_path = NULL;
|
||||
struct tlv_onionmsg_payload_reply_path *reply_path = NULL;
|
||||
|
||||
if (!offers_enabled)
|
||||
@@ -152,31 +102,20 @@ static struct command_result *onion_message_modern_call(struct command *cmd,
|
||||
om = json_get_member(buf, params, "onion_message");
|
||||
replytok = json_get_member(buf, om, "reply_blindedpath");
|
||||
if (replytok) {
|
||||
bool obs2;
|
||||
json_to_bool(buf, json_get_member(buf, om, "obs2"), &obs2);
|
||||
if (obs2) {
|
||||
obs2_reply_path = json_to_obs2_reply_path(cmd, buf, replytok);
|
||||
if (!obs2_reply_path)
|
||||
plugin_err(cmd->plugin, "Invalid obs2 reply path %.*s?",
|
||||
json_tok_full_len(replytok),
|
||||
json_tok_full(buf, replytok));
|
||||
} else {
|
||||
reply_path = json_to_reply_path(cmd, buf, replytok);
|
||||
if (!reply_path)
|
||||
plugin_err(cmd->plugin, "Invalid reply path %.*s?",
|
||||
json_tok_full_len(replytok),
|
||||
json_tok_full(buf, replytok));
|
||||
}
|
||||
reply_path = json_to_reply_path(cmd, buf, replytok);
|
||||
if (!reply_path)
|
||||
plugin_err(cmd->plugin, "Invalid reply path %.*s?",
|
||||
json_tok_full_len(replytok),
|
||||
json_tok_full(buf, replytok));
|
||||
}
|
||||
|
||||
invreqtok = json_get_member(buf, om, "invoice_request");
|
||||
if (invreqtok) {
|
||||
const u8 *invreqbin = json_tok_bin_from_hex(tmpctx, buf, invreqtok);
|
||||
if (reply_path || obs2_reply_path)
|
||||
if (reply_path)
|
||||
return handle_invoice_request(cmd,
|
||||
invreqbin,
|
||||
reply_path,
|
||||
obs2_reply_path);
|
||||
reply_path);
|
||||
else
|
||||
plugin_log(cmd->plugin, LOG_DBG,
|
||||
"invoice_request without reply_path");
|
||||
@@ -186,7 +125,7 @@ static struct command_result *onion_message_modern_call(struct command *cmd,
|
||||
if (invtok) {
|
||||
const u8 *invbin = json_tok_bin_from_hex(tmpctx, buf, invtok);
|
||||
if (invbin)
|
||||
return handle_invoice(cmd, invbin, reply_path, obs2_reply_path);
|
||||
return handle_invoice(cmd, invbin, reply_path);
|
||||
}
|
||||
|
||||
return command_hook_success(cmd);
|
||||
|
||||
@@ -9,7 +9,6 @@ struct command;
|
||||
struct command_result *WARN_UNUSED_RESULT
|
||||
send_onion_reply(struct command *cmd,
|
||||
struct tlv_onionmsg_payload_reply_path *reply_path,
|
||||
struct tlv_obs2_onionmsg_payload_reply_path *obs2_reply_path,
|
||||
const char *replyfield,
|
||||
const u8 *replydata);
|
||||
#endif /* LIGHTNING_PLUGINS_OFFERS_H */
|
||||
|
||||
@@ -13,7 +13,6 @@ struct inv {
|
||||
struct tlv_invoice *inv;
|
||||
|
||||
/* May be NULL */
|
||||
struct tlv_obs2_onionmsg_payload_reply_path *obs2_reply_path;
|
||||
struct tlv_onionmsg_payload_reply_path *reply_path;
|
||||
|
||||
/* The offer, once we've looked it up. */
|
||||
@@ -45,7 +44,7 @@ fail_inv_level(struct command *cmd,
|
||||
plugin_log(cmd->plugin, l, "%s", msg);
|
||||
|
||||
/* Only reply if they gave us a path */
|
||||
if (!inv->reply_path && !inv->obs2_reply_path)
|
||||
if (!inv->reply_path)
|
||||
return command_hook_success(cmd);
|
||||
|
||||
/* Don't send back internal error details. */
|
||||
@@ -59,8 +58,7 @@ fail_inv_level(struct command *cmd,
|
||||
|
||||
errdata = tal_arr(cmd, u8, 0);
|
||||
towire_tlv_invoice_error(&errdata, err);
|
||||
return send_onion_reply(cmd, inv->reply_path, inv->obs2_reply_path,
|
||||
"invoice_error", errdata);
|
||||
return send_onion_reply(cmd, inv->reply_path, "invoice_error", errdata);
|
||||
}
|
||||
|
||||
static struct command_result *WARN_UNUSED_RESULT
|
||||
@@ -320,8 +318,7 @@ static struct command_result *listoffers_error(struct command *cmd,
|
||||
|
||||
struct command_result *handle_invoice(struct command *cmd,
|
||||
const u8 *invbin,
|
||||
struct tlv_onionmsg_payload_reply_path *reply_path STEALS,
|
||||
struct tlv_obs2_onionmsg_payload_reply_path *obs2_reply_path STEALS)
|
||||
struct tlv_onionmsg_payload_reply_path *reply_path STEALS)
|
||||
{
|
||||
size_t len = tal_count(invbin);
|
||||
struct inv *inv = tal(cmd, struct inv);
|
||||
@@ -330,7 +327,6 @@ struct command_result *handle_invoice(struct command *cmd,
|
||||
int bad_feature;
|
||||
struct sha256 m, shash;
|
||||
|
||||
inv->obs2_reply_path = tal_steal(inv, obs2_reply_path);
|
||||
inv->reply_path = tal_steal(inv, reply_path);
|
||||
|
||||
inv->inv = fromwire_tlv_invoice(cmd, &invbin, &len);
|
||||
|
||||
@@ -6,6 +6,5 @@
|
||||
/* We got an onionmessage with an invoice! reply_path could be NULL. */
|
||||
struct command_result *handle_invoice(struct command *cmd,
|
||||
const u8 *invbin,
|
||||
struct tlv_onionmsg_payload_reply_path *reply_path STEALS,
|
||||
struct tlv_obs2_onionmsg_payload_reply_path *obs2_reply_path STEALS);
|
||||
struct tlv_onionmsg_payload_reply_path *reply_path STEALS);
|
||||
#endif /* LIGHTNING_PLUGINS_OFFERS_INV_HOOK_H */
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
struct invreq {
|
||||
struct tlv_invoice_request *invreq;
|
||||
struct tlv_onionmsg_payload_reply_path *reply_path;
|
||||
struct tlv_obs2_onionmsg_payload_reply_path *obs2_reply_path;
|
||||
|
||||
/* The offer, once we've looked it up. */
|
||||
struct tlv_offer *offer;
|
||||
@@ -64,8 +63,7 @@ fail_invreq_level(struct command *cmd,
|
||||
|
||||
errdata = tal_arr(cmd, u8, 0);
|
||||
towire_tlv_invoice_error(&errdata, err);
|
||||
return send_onion_reply(cmd, invreq->reply_path, invreq->obs2_reply_path,
|
||||
"invoice_error", errdata);
|
||||
return send_onion_reply(cmd, invreq->reply_path, "invoice_error", errdata);
|
||||
}
|
||||
|
||||
static struct command_result *WARN_UNUSED_RESULT PRINTF_FMT(3,4)
|
||||
@@ -184,8 +182,7 @@ static struct command_result *createinvoice_done(struct command *cmd,
|
||||
json_tok_full(buf, t));
|
||||
}
|
||||
|
||||
return send_onion_reply(cmd, ir->reply_path, ir->obs2_reply_path,
|
||||
"invoice", rawinv);
|
||||
return send_onion_reply(cmd, ir->reply_path, "invoice", rawinv);
|
||||
}
|
||||
|
||||
static struct command_result *createinvoice_error(struct command *cmd,
|
||||
@@ -835,15 +832,13 @@ static struct command_result *handle_offerless_request(struct command *cmd,
|
||||
|
||||
struct command_result *handle_invoice_request(struct command *cmd,
|
||||
const u8 *invreqbin,
|
||||
struct tlv_onionmsg_payload_reply_path *reply_path,
|
||||
struct tlv_obs2_onionmsg_payload_reply_path *obs2_reply_path)
|
||||
struct tlv_onionmsg_payload_reply_path *reply_path)
|
||||
{
|
||||
size_t len = tal_count(invreqbin);
|
||||
struct invreq *ir = tal(cmd, struct invreq);
|
||||
struct out_req *req;
|
||||
int bad_feature;
|
||||
|
||||
ir->obs2_reply_path = tal_steal(ir, obs2_reply_path);
|
||||
ir->reply_path = tal_steal(ir, reply_path);
|
||||
|
||||
ir->invreq = fromwire_tlv_invoice_request(cmd, &invreqbin, &len);
|
||||
|
||||
@@ -8,6 +8,5 @@ extern u16 cltv_final;
|
||||
/* We got an onionmessage with an invreq! */
|
||||
struct command_result *handle_invoice_request(struct command *cmd,
|
||||
const u8 *invreqbin,
|
||||
struct tlv_onionmsg_payload_reply_path *reply_path STEALS,
|
||||
struct tlv_obs2_onionmsg_payload_reply_path *obs2_reply_path STEALS);
|
||||
struct tlv_onionmsg_payload_reply_path *reply_path STEALS);
|
||||
#endif /* LIGHTNING_PLUGINS_OFFERS_INVREQ_HOOK_H */
|
||||
|
||||
Reference in New Issue
Block a user