Browse Source

channeld: hand up onionmessage fields.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
fix-mocks
Rusty Russell 4 years ago
parent
commit
28a903c917
  1. 11
      channeld/channeld.c
  2. 2
      channeld/channeld_wire.csv
  3. 14
      channeld/channeld_wiregen.c
  4. 6
      channeld/channeld_wiregen.h
  5. 38
      lightningd/onion_message.c

11
channeld/channeld.c

@ -67,6 +67,9 @@
#include <secp256k1.h>
#include <sodium/crypto_aead_chacha20poly1305.h>
#include <stdio.h>
#if EXPERIMENTAL_FEATURES
#include <wire/bolt12_exp_wiregen.h>
#endif
#include <wire/common_wiregen.h>
#include <wire/onion_wire.h>
#include <wire/peer_wire.h>
@ -1953,6 +1956,7 @@ static void handle_onion_message(struct peer *peer, const u8 *msg)
if (rs->nextcase == ONION_END) {
struct pubkey *blinding;
const struct onionmsg_path **path;
u8 *omsg;
if (om->reply_path) {
blinding = &om->reply_path->blinding;
@ -1962,11 +1966,16 @@ static void handle_onion_message(struct peer *peer, const u8 *msg)
blinding = NULL;
path = NULL;
}
/* We re-marshall here by policy, before handing to lightningd */
omsg = tal_arr(tmpctx, u8, 0);
towire_tlvstream_raw(&omsg, om->fields);
wire_sync_write(MASTER_FD,
take(towire_got_onionmsg_to_us(NULL,
blinding_in,
blinding,
path)));
path,
omsg)));
} else {
struct pubkey *next_blinding;
struct node_id *next_node;

2
channeld/channeld_wire.csv

@ -231,6 +231,8 @@ msgdata,got_onionmsg_to_us,blinding_in,?pubkey,
msgdata,got_onionmsg_to_us,reply_blinding,?pubkey,
msgdata,got_onionmsg_to_us,reply_path_len,u16,
msgdata,got_onionmsg_to_us,reply_path,onionmsg_path,reply_path_len
msgdata,got_onionmsg_to_us,rawmsg_len,u16,
msgdata,got_onionmsg_to_us,rawmsg,u8,rawmsg_len
msgtype,got_onionmsg_forward,1143
msgdata,got_onionmsg_forward,next_scid,?short_channel_id,

Can't render this file because it has a wrong number of fields in line 12.

14
channeld/channeld_wiregen.c

@ -1105,9 +1105,10 @@ bool fromwire_channeld_send_error_reply(const void *p)
/* WIRE: GOT_ONIONMSG_TO_US */
/* Tell lightningd we got a onion message (for us */
u8 *towire_got_onionmsg_to_us(const tal_t *ctx, const struct pubkey *blinding_in, const struct pubkey *reply_blinding, const struct onionmsg_path **reply_path)
u8 *towire_got_onionmsg_to_us(const tal_t *ctx, const struct pubkey *blinding_in, const struct pubkey *reply_blinding, const struct onionmsg_path **reply_path, const u8 *rawmsg)
{
u16 reply_path_len = tal_count(reply_path);
u16 rawmsg_len = tal_count(rawmsg);
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_GOT_ONIONMSG_TO_US);
@ -1126,12 +1127,15 @@ u8 *towire_got_onionmsg_to_us(const tal_t *ctx, const struct pubkey *blinding_in
towire_u16(&p, reply_path_len);
for (size_t i = 0; i < reply_path_len; i++)
towire_onionmsg_path(&p, reply_path[i]);
towire_u16(&p, rawmsg_len);
towire_u8_array(&p, rawmsg, rawmsg_len);
return memcheck(p, tal_count(p));
}
bool fromwire_got_onionmsg_to_us(const tal_t *ctx, const void *p, struct pubkey **blinding_in, struct pubkey **reply_blinding, struct onionmsg_path ***reply_path)
bool fromwire_got_onionmsg_to_us(const tal_t *ctx, const void *p, struct pubkey **blinding_in, struct pubkey **reply_blinding, struct onionmsg_path ***reply_path, u8 **rawmsg)
{
u16 reply_path_len;
u16 rawmsg_len;
const u8 *cursor = p;
size_t plen = tal_count(p);
@ -1155,6 +1159,10 @@ bool fromwire_got_onionmsg_to_us(const tal_t *ctx, const void *p, struct pubkey
*reply_path = reply_path_len ? tal_arr(ctx, struct onionmsg_path *, reply_path_len) : NULL;
for (size_t i = 0; i < reply_path_len; i++)
(*reply_path)[i] = fromwire_onionmsg_path(*reply_path, &cursor, &plen);
rawmsg_len = fromwire_u16(&cursor, &plen);
// 2nd case rawmsg
*rawmsg = rawmsg_len ? tal_arr(ctx, u8, rawmsg_len) : NULL;
fromwire_u8_array(&cursor, &plen, *rawmsg, rawmsg_len);
return cursor != NULL;
}
@ -1248,4 +1256,4 @@ bool fromwire_send_onionmsg(const tal_t *ctx, const void *p, u8 onion[1366], str
}
return cursor != NULL;
}
// SHA256STAMP:5fc565464be5cacb6e6ef163e41b1eee4ca3276848a30a3892f6f808f1b4c480
// SHA256STAMP:564860d28225780e0746b0f9e6944d691a342d12bd9d0400bb962577fab64067

6
channeld/channeld_wiregen.h

@ -232,8 +232,8 @@ bool fromwire_channeld_send_error_reply(const void *p);
/* WIRE: GOT_ONIONMSG_TO_US */
/* Tell lightningd we got a onion message (for us */
u8 *towire_got_onionmsg_to_us(const tal_t *ctx, const struct pubkey *blinding_in, const struct pubkey *reply_blinding, const struct onionmsg_path **reply_path);
bool fromwire_got_onionmsg_to_us(const tal_t *ctx, const void *p, struct pubkey **blinding_in, struct pubkey **reply_blinding, struct onionmsg_path ***reply_path);
u8 *towire_got_onionmsg_to_us(const tal_t *ctx, const struct pubkey *blinding_in, const struct pubkey *reply_blinding, const struct onionmsg_path **reply_path, const u8 *rawmsg);
bool fromwire_got_onionmsg_to_us(const tal_t *ctx, const void *p, struct pubkey **blinding_in, struct pubkey **reply_blinding, struct onionmsg_path ***reply_path, u8 **rawmsg);
/* WIRE: GOT_ONIONMSG_FORWARD */
u8 *towire_got_onionmsg_forward(const tal_t *ctx, const struct short_channel_id *next_scid, const struct node_id *next_node_id, const struct pubkey *next_blinding, const u8 next_onion[1366]);
@ -246,4 +246,4 @@ bool fromwire_send_onionmsg(const tal_t *ctx, const void *p, u8 onion[1366], str
#endif /* LIGHTNING_CHANNELD_CHANNELD_WIREGEN_H */
// SHA256STAMP:5fc565464be5cacb6e6ef163e41b1eee4ca3276848a30a3892f6f808f1b4c480
// SHA256STAMP:564860d28225780e0746b0f9e6944d691a342d12bd9d0400bb962577fab64067

38
lightningd/onion_message.c

@ -14,7 +14,7 @@ struct onion_message_hook_payload {
struct pubkey *reply_blinding;
struct onionmsg_path **reply_path;
/* FIXME: Include other TLV fields here! */
struct tlv_onionmsg_payload *om;
};
static void
@ -40,6 +40,29 @@ onion_message_serialize(struct onion_message_hook_payload *payload,
}
json_array_end(stream);
}
/* Common convenience fields */
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_object_end(stream);
}
@ -100,17 +123,28 @@ void handle_onionmsg_to_us(struct channel *channel, const u8 *msg)
{
struct lightningd *ld = channel->peer->ld;
struct onion_message_hook_payload *payload;
u8 *submsg;
size_t submsglen;
payload = tal(ld, struct onion_message_hook_payload);
payload->om = tlv_onionmsg_payload_new(payload);
if (!fromwire_got_onionmsg_to_us(payload, msg,
&payload->blinding_in,
&payload->reply_blinding,
&payload->reply_path)) {
&payload->reply_path,
&submsg)) {
channel_internal_error(channel, "bad got_onionmsg_tous: %s",
tal_hex(tmpctx, msg));
return;
}
submsglen = tal_bytelen(submsg);
if (!fromwire_onionmsg_payload(cast_const2(const u8 **, &submsg),
&submsglen, payload->om)) {
channel_internal_error(channel, "bad got_onionmsg_tous om: %s",
tal_hex(tmpctx, msg));
return;
}
if (payload->reply_path && !payload->reply_blinding) {
log_broken(channel->log,

Loading…
Cancel
Save