mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
connectd: restore obs2 onion support.
I removed these prematurely: we *haven't* had a release since
introducing them!
This consists of reverting d15d629b8b
"plugins/fetchinvoice: remove obsolete string-based API." and
plugins/fetchinvoice: remove obsolete string-based
API. "onion_messages: remove obs2 support."
Some minor changes due to updated fromwire_tlv API since they
were removed, but not much.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: REVERT: Removed backwards compat with onion messages from v0.10.1.
This commit is contained in:
@@ -639,13 +639,96 @@ static struct pubkey *path_to_node(const tal_t *ctx,
|
||||
/* Marshal arguments for sending onion messages */
|
||||
struct sending {
|
||||
struct sent *sent;
|
||||
struct tlv_onionmsg_payload *payload;
|
||||
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,
|
||||
@@ -683,7 +766,7 @@ send_modern_message(struct command *cmd,
|
||||
&node_alias[i]);
|
||||
}
|
||||
/* Final payload contains the actual data. */
|
||||
payloads[nhops-1] = sending->payload;
|
||||
payloads[nhops-1] = tlv_onionmsg_payload_new(payloads);
|
||||
|
||||
/* We don't include enctlv in final, but it gives us final alias */
|
||||
if (!create_final_enctlv(tmpctx, &blinding_iter, &sent->path[nhops-1],
|
||||
@@ -695,12 +778,22 @@ send_modern_message(struct command *cmd,
|
||||
"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 = reply_path;
|
||||
|
||||
req = jsonrpc_request_start(cmd->plugin, cmd, "sendonionmessage",
|
||||
sending->done,
|
||||
/* Try sending older version next */
|
||||
send_obs2_message,
|
||||
forward_error,
|
||||
sending->sent);
|
||||
sending);
|
||||
json_add_pubkey(req->js, "first_id", &sent->path[1]);
|
||||
json_add_pubkey(req->js, "blinding", &fwd_blinding);
|
||||
json_array_start(req->js, "hops");
|
||||
@@ -734,6 +827,15 @@ 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,
|
||||
@@ -769,7 +871,8 @@ static struct command_result *make_reply_path(struct command *cmd,
|
||||
|
||||
static struct command_result *send_message(struct command *cmd,
|
||||
struct sent *sent,
|
||||
struct tlv_onionmsg_payload *payload STEALS,
|
||||
const char *msgfield TAKES,
|
||||
const u8 *msgval TAKES,
|
||||
struct command_result *(*done)
|
||||
(struct command *cmd,
|
||||
const char *buf UNUSED,
|
||||
@@ -778,7 +881,8 @@ static struct command_result *send_message(struct command *cmd,
|
||||
{
|
||||
struct sending *sending = tal(cmd, struct sending);
|
||||
sending->sent = sent;
|
||||
sending->payload = tal_steal(sending, payload);
|
||||
sending->msgfield = tal_strdup(sending, msgfield);
|
||||
sending->msgval = tal_dup_talarr(sending, u8, msgval);
|
||||
sending->done = done;
|
||||
|
||||
return make_reply_path(cmd, sending);
|
||||
@@ -817,12 +921,11 @@ sendinvreq_after_connect(struct command *cmd,
|
||||
const jsmntok_t *result UNUSED,
|
||||
struct sent *sent)
|
||||
{
|
||||
struct tlv_onionmsg_payload *payload = tlv_onionmsg_payload_new(sent);
|
||||
u8 *rawinvreq = tal_arr(tmpctx, u8, 0);
|
||||
towire_tlv_invoice_request(&rawinvreq, sent->invreq);
|
||||
|
||||
payload->invoice_request = tal_arr(payload, u8, 0);
|
||||
towire_tlv_invoice_request(&payload->invoice_request, sent->invreq);
|
||||
|
||||
return send_message(cmd, sent, payload, sendonionmsg_done);
|
||||
return send_message(cmd, sent, "invoice_request", rawinvreq,
|
||||
sendonionmsg_done);
|
||||
}
|
||||
|
||||
struct connect_attempt {
|
||||
@@ -1367,12 +1470,9 @@ sendinvoice_after_connect(struct command *cmd,
|
||||
const jsmntok_t *result UNUSED,
|
||||
struct sent *sent)
|
||||
{
|
||||
struct tlv_onionmsg_payload *payload = tlv_onionmsg_payload_new(sent);
|
||||
|
||||
payload->invoice = tal_arr(payload, u8, 0);
|
||||
towire_tlv_invoice(&payload->invoice, sent->inv);
|
||||
|
||||
return send_message(cmd, sent, payload, prepare_inv_timeout);
|
||||
u8 *rawinv = tal_arr(tmpctx, u8, 0);
|
||||
towire_tlv_invoice(&rawinv, sent->inv);
|
||||
return send_message(cmd, sent, "invoice", rawinv, prepare_inv_timeout);
|
||||
}
|
||||
|
||||
static struct command_result *createinvoice_done(struct command *cmd,
|
||||
|
||||
Reference in New Issue
Block a user