mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 16:14:23 +01:00
onionmessages: remove obsolete onion message parsing.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -135,7 +135,6 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
|
||||
ld->dev_no_version_checks = false;
|
||||
ld->dev_max_funding_unconfirmed = 2016;
|
||||
ld->dev_ignore_modern_onion = false;
|
||||
ld->dev_ignore_obsolete_onion = false;
|
||||
ld->dev_disable_commit = -1;
|
||||
ld->dev_no_ping_timer = false;
|
||||
#endif
|
||||
|
||||
@@ -283,7 +283,7 @@ struct lightningd {
|
||||
u32 dev_max_funding_unconfirmed;
|
||||
|
||||
/* Special switches to test onion compatibility */
|
||||
bool dev_ignore_modern_onion, dev_ignore_obsolete_onion;
|
||||
bool dev_ignore_modern_onion;
|
||||
|
||||
/* Tell channeld to disable commits after this many. */
|
||||
int dev_disable_commit;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "config.h"
|
||||
#include <ccan/mem/mem.h>
|
||||
#include <common/blindedpath.h>
|
||||
#include <common/configdir.h>
|
||||
#include <common/json_command.h>
|
||||
#include <common/json_param.h>
|
||||
#include <common/type_to_string.h>
|
||||
@@ -18,10 +19,7 @@ struct onion_message_hook_payload {
|
||||
struct onionmsg_path **reply_path;
|
||||
struct pubkey *reply_first_node;
|
||||
struct pubkey *our_alias;
|
||||
|
||||
/* Exactly one of these is set! */
|
||||
struct tlv_onionmsg_payload *om;
|
||||
struct tlv_obs2_onionmsg_payload *obs2_om;
|
||||
};
|
||||
|
||||
static void json_add_blindedpath(struct json_stream *stream,
|
||||
@@ -60,56 +58,29 @@ static void onion_message_serialize(struct onion_message_hook_payload *payload,
|
||||
payload->reply_path);
|
||||
}
|
||||
|
||||
/* Common convenience fields */
|
||||
if (payload->obs2_om) {
|
||||
json_add_bool(stream, "obs2", true);
|
||||
if (payload->obs2_om->invoice_request)
|
||||
json_add_hex_talarr(stream, "invoice_request",
|
||||
payload->obs2_om->invoice_request);
|
||||
if (payload->obs2_om->invoice)
|
||||
json_add_hex_talarr(stream, "invoice", payload->obs2_om->invoice);
|
||||
if (payload->om->invoice_request)
|
||||
json_add_hex_talarr(stream, "invoice_request",
|
||||
payload->om->invoice_request);
|
||||
if (payload->om->invoice)
|
||||
json_add_hex_talarr(stream, "invoice", payload->om->invoice);
|
||||
|
||||
if (payload->obs2_om->invoice_error)
|
||||
json_add_hex_talarr(stream, "invoice_error",
|
||||
payload->obs2_om->invoice_error);
|
||||
if (payload->om->invoice_error)
|
||||
json_add_hex_talarr(stream, "invoice_error",
|
||||
payload->om->invoice_error);
|
||||
|
||||
json_array_start(stream, "unknown_fields");
|
||||
for (size_t i = 0; i < tal_count(payload->obs2_om->fields); i++) {
|
||||
if (payload->obs2_om->fields[i].meta)
|
||||
continue;
|
||||
json_object_start(stream, NULL);
|
||||
json_add_u64(stream, "number", payload->obs2_om->fields[i].numtype);
|
||||
json_add_hex(stream, "value",
|
||||
payload->obs2_om->fields[i].value,
|
||||
payload->obs2_om->fields[i].length);
|
||||
json_object_end(stream);
|
||||
}
|
||||
json_array_end(stream);
|
||||
} else {
|
||||
json_add_bool(stream, "obs2", false);
|
||||
if (payload->om->invoice_request)
|
||||
json_add_hex_talarr(stream, "invoice_request",
|
||||
payload->om->invoice_request);
|
||||
if (payload->om->invoice)
|
||||
json_add_hex_talarr(stream, "invoice", payload->om->invoice);
|
||||
|
||||
if (payload->om->invoice_error)
|
||||
json_add_hex_talarr(stream, "invoice_error",
|
||||
payload->om->invoice_error);
|
||||
|
||||
json_array_start(stream, "unknown_fields");
|
||||
for (size_t i = 0; i < tal_count(payload->om->fields); i++) {
|
||||
if (payload->om->fields[i].meta)
|
||||
continue;
|
||||
json_object_start(stream, NULL);
|
||||
json_add_u64(stream, "number", payload->om->fields[i].numtype);
|
||||
json_add_hex(stream, "value",
|
||||
payload->om->fields[i].value,
|
||||
payload->om->fields[i].length);
|
||||
json_object_end(stream);
|
||||
}
|
||||
json_array_end(stream);
|
||||
json_array_start(stream, "unknown_fields");
|
||||
for (size_t i = 0; i < tal_count(payload->om->fields); i++) {
|
||||
if (payload->om->fields[i].meta)
|
||||
continue;
|
||||
json_object_start(stream, NULL);
|
||||
json_add_u64(stream, "number", payload->om->fields[i].numtype);
|
||||
json_add_hex(stream, "value",
|
||||
payload->om->fields[i].value,
|
||||
payload->om->fields[i].length);
|
||||
json_object_end(stream);
|
||||
}
|
||||
json_array_end(stream);
|
||||
|
||||
json_object_end(stream);
|
||||
}
|
||||
|
||||
@@ -140,7 +111,6 @@ void handle_onionmsg_to_us(struct lightningd *ld, const u8 *msg)
|
||||
struct onion_message_hook_payload *payload;
|
||||
u8 *submsg;
|
||||
struct secret *self_id;
|
||||
bool obs2;
|
||||
size_t submsglen;
|
||||
const u8 *subptr;
|
||||
|
||||
@@ -148,7 +118,6 @@ void handle_onionmsg_to_us(struct lightningd *ld, const u8 *msg)
|
||||
payload->our_alias = tal(payload, struct pubkey);
|
||||
|
||||
if (!fromwire_connectd_got_onionmsg_to_us(payload, msg,
|
||||
&obs2,
|
||||
payload->our_alias,
|
||||
&self_id,
|
||||
&payload->reply_blinding,
|
||||
@@ -161,9 +130,7 @@ void handle_onionmsg_to_us(struct lightningd *ld, const u8 *msg)
|
||||
}
|
||||
|
||||
#if DEVELOPER
|
||||
if (!obs2 && ld->dev_ignore_modern_onion)
|
||||
return;
|
||||
if (obs2 && ld->dev_ignore_obsolete_onion)
|
||||
if (ld->dev_ignore_modern_onion)
|
||||
return;
|
||||
#endif
|
||||
|
||||
@@ -175,22 +142,11 @@ void handle_onionmsg_to_us(struct lightningd *ld, const u8 *msg)
|
||||
|
||||
submsglen = tal_bytelen(submsg);
|
||||
subptr = submsg;
|
||||
if (obs2) {
|
||||
payload->om = NULL;
|
||||
payload->obs2_om = fromwire_tlv_obs2_onionmsg_payload(payload, &subptr, &submsglen);
|
||||
if (!payload->obs2_om) {
|
||||
log_broken(ld->log, "bad got_obs2_onionmsg_tous om: %s",
|
||||
tal_hex(tmpctx, msg));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
payload->obs2_om = NULL;
|
||||
payload->om = fromwire_tlv_onionmsg_payload(payload, &subptr, &submsglen);
|
||||
if (!payload->om) {
|
||||
log_broken(ld->log, "bad got_onionmsg_tous om: %s",
|
||||
tal_hex(tmpctx, msg));
|
||||
return;
|
||||
}
|
||||
payload->om = fromwire_tlv_onionmsg_payload(payload, &subptr, &submsglen);
|
||||
if (!payload->om) {
|
||||
log_broken(ld->log, "bad got_onionmsg_tous om: %s",
|
||||
tal_hex(tmpctx, msg));
|
||||
return;
|
||||
}
|
||||
tal_free(submsg);
|
||||
|
||||
@@ -247,11 +203,10 @@ static struct command_result *param_onion_hops(struct command *cmd,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct command_result *json_sendonionmessage2(struct command *cmd,
|
||||
const char *buffer,
|
||||
const jsmntok_t *obj UNNEEDED,
|
||||
const jsmntok_t *params,
|
||||
bool obs2)
|
||||
static struct command_result *json_sendonionmessage(struct command *cmd,
|
||||
const char *buffer,
|
||||
const jsmntok_t *obj UNNEEDED,
|
||||
const jsmntok_t *params)
|
||||
{
|
||||
struct onion_hop *hops;
|
||||
struct node_id *first_id;
|
||||
@@ -297,29 +252,13 @@ static struct command_result *json_sendonionmessage2(struct command *cmd,
|
||||
"Creating onion failed (tlvs too long?)");
|
||||
|
||||
subd_send_msg(cmd->ld->connectd,
|
||||
take(towire_connectd_send_onionmsg(NULL, obs2, first_id,
|
||||
take(towire_connectd_send_onionmsg(NULL, first_id,
|
||||
serialize_onionpacket(tmpctx, op),
|
||||
blinding)));
|
||||
|
||||
return command_success(cmd, json_stream_success(cmd));
|
||||
}
|
||||
|
||||
static struct command_result *json_sendonionmessage(struct command *cmd,
|
||||
const char *buffer,
|
||||
const jsmntok_t *obj,
|
||||
const jsmntok_t *params)
|
||||
{
|
||||
return json_sendonionmessage2(cmd, buffer, obj, params, false);
|
||||
}
|
||||
|
||||
static struct command_result *json_sendobs2onionmessage(struct command *cmd,
|
||||
const char *buffer,
|
||||
const jsmntok_t *obj,
|
||||
const jsmntok_t *params)
|
||||
{
|
||||
return json_sendonionmessage2(cmd, buffer, obj, params, true);
|
||||
}
|
||||
|
||||
static const struct json_command sendonionmessage_command = {
|
||||
"sendonionmessage",
|
||||
"utility",
|
||||
@@ -328,14 +267,6 @@ static const struct json_command sendonionmessage_command = {
|
||||
};
|
||||
AUTODATA(json_command, &sendonionmessage_command);
|
||||
|
||||
static const struct json_command sendobs2onionmessage_command = {
|
||||
"sendobs2onionmessage",
|
||||
"utility",
|
||||
json_sendobs2onionmessage,
|
||||
"Send obsolete message to {first_id}, using {blinding}, encoded over {hops} (id, tlv)"
|
||||
};
|
||||
AUTODATA(json_command, &sendobs2onionmessage_command);
|
||||
|
||||
static struct command_result *param_pubkeys(struct command *cmd,
|
||||
const char *name,
|
||||
const char *buffer,
|
||||
@@ -427,32 +358,6 @@ static struct command_result *json_blindedpath(struct command *cmd,
|
||||
json_add_blindedpath(response, "blindedpath",
|
||||
&first_blinding_pubkey, &first_node, path);
|
||||
|
||||
/* Now create obsolete one! */
|
||||
blinding_iter = first_blinding;
|
||||
for (size_t i = 0; i < nhops - 1; i++) {
|
||||
path[i] = tal(path, struct onionmsg_path);
|
||||
path[i]->encrypted_recipient_data = create_obs2_enctlv(path[i],
|
||||
&blinding_iter,
|
||||
&ids[i],
|
||||
&ids[i+1],
|
||||
/* FIXME: Pad? */
|
||||
0,
|
||||
NULL,
|
||||
&blinding_iter,
|
||||
&path[i]->node_id);
|
||||
}
|
||||
|
||||
/* FIXME: Add padding! */
|
||||
path[nhops-1] = tal(path, struct onionmsg_path);
|
||||
path[nhops-1]->encrypted_recipient_data = create_obs2_final_enctlv(path[nhops-1],
|
||||
&blinding_iter,
|
||||
&ids[nhops-1],
|
||||
/* FIXME: Pad? */
|
||||
0,
|
||||
&cmd->ld->onion_reply_secret,
|
||||
&path[nhops-1]->node_id);
|
||||
json_add_blindedpath(response, "obs2blindedpath",
|
||||
&first_blinding_pubkey, &first_node, path);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
|
||||
@@ -745,9 +745,6 @@ static void dev_register_opts(struct lightningd *ld)
|
||||
opt_register_noarg("--dev-no-modern-onion", opt_set_bool,
|
||||
&ld->dev_ignore_modern_onion,
|
||||
"Ignore modern onion messages");
|
||||
opt_register_noarg("--dev-no-obsolete-onion", opt_set_bool,
|
||||
&ld->dev_ignore_obsolete_onion,
|
||||
"Ignore obsolete onion messages");
|
||||
opt_register_arg("--dev-disable-commit-after",
|
||||
opt_set_intval, opt_show_intval,
|
||||
&ld->dev_disable_commit,
|
||||
|
||||
Reference in New Issue
Block a user