Browse Source

common/sphinx: make TOTAL_PACKET_SIZE a macro.

This paves the way for using it on different-sized onions.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
fix-mocks
Rusty Russell 4 years ago
committed by Christian Decker
parent
commit
3776af4a35
  1. 10
      channeld/channeld.c
  2. 6
      channeld/full_channel.c
  3. 2
      channeld/full_channel.h
  4. 4
      channeld/test/run-full_channel.c
  5. 2
      common/htlc_wire.c
  6. 6
      common/htlc_wire.h
  7. 6
      common/sphinx.c
  8. 2
      common/sphinx.h
  9. 2
      devtools/blindedpath.c
  10. 4
      devtools/onion.c
  11. 4
      lightningd/htlc_end.h
  12. 2
      lightningd/onion_message.c
  13. 2
      lightningd/peer_htlcs.c
  14. 2
      wire/test/run-peer-wire.c

10
channeld/channeld.c

@ -684,7 +684,7 @@ static void handle_peer_add_htlc(struct peer *peer, const u8 *msg)
struct amount_msat amount;
u32 cltv_expiry;
struct sha256 payment_hash;
u8 onion_routing_packet[TOTAL_PACKET_SIZE];
u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
enum channel_add_err add_err;
struct htlc *htlc;
#if EXPERIMENTAL_FEATURES
@ -1813,7 +1813,7 @@ static void handle_onion_message(struct peer *peer, const u8 *msg)
struct secret ss, *blinding_ss;
struct pubkey *blinding_in;
struct route_step *rs;
u8 onion[TOTAL_PACKET_SIZE];
u8 onion[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
const u8 *cursor;
size_t max, maxlen;
struct tlv_onionmsg_payload *om;
@ -1825,7 +1825,7 @@ static void handle_onion_message(struct peer *peer, const u8 *msg)
"Bad onion_message %s", tal_hex(peer, msg));
/* We unwrap the onion now. */
badreason = parse_onionpacket(onion, TOTAL_PACKET_SIZE, &op);
badreason = parse_onionpacket(onion, TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE), &op);
if (badreason != 0) {
status_debug("onion msg: can't parse onionpacket: %s",
onion_wire_name(badreason));
@ -2014,7 +2014,7 @@ static void handle_onion_message(struct peer *peer, const u8 *msg)
/* We send onion msg. */
static void send_onionmsg(struct peer *peer, const u8 *msg)
{
u8 onion_routing_packet[TOTAL_PACKET_SIZE];
u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
struct pubkey *blinding;
struct tlv_onion_message_tlvs *tlvs = tlv_onion_message_tlvs_new(msg);
@ -3057,7 +3057,7 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
u32 cltv_expiry;
struct amount_msat amount;
struct sha256 payment_hash;
u8 onion_routing_packet[TOTAL_PACKET_SIZE];
u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
enum channel_add_err e;
const u8 *failwiremsg;
const char *failstr;

6
channeld/full_channel.c

@ -477,7 +477,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
struct amount_msat amount,
u32 cltv_expiry,
const struct sha256 *payment_hash,
const u8 routing[TOTAL_PACKET_SIZE],
const u8 routing[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)],
const struct pubkey *blinding TAKES,
struct htlc **htlcp,
bool enforce_aggregate_limits,
@ -517,7 +517,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
htlc->blinding = NULL;
htlc->failed = NULL;
htlc->r = NULL;
htlc->routing = tal_dup_arr(htlc, u8, routing, TOTAL_PACKET_SIZE, 0);
htlc->routing = tal_dup_arr(htlc, u8, routing, TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE), 0);
old = htlc_get(channel->htlcs, htlc->id, htlc_owner(htlc));
if (old) {
@ -746,7 +746,7 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
struct amount_msat amount,
u32 cltv_expiry,
const struct sha256 *payment_hash,
const u8 routing[TOTAL_PACKET_SIZE],
const u8 routing[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)],
const struct pubkey *blinding TAKES,
struct htlc **htlcp,
struct amount_sat *htlc_fee)

2
channeld/full_channel.h

@ -112,7 +112,7 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
struct amount_msat msatoshi,
u32 cltv_expiry,
const struct sha256 *payment_hash,
const u8 routing[TOTAL_PACKET_SIZE],
const u8 routing[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)],
const struct pubkey *blinding TAKES,
struct htlc **htlcp,
struct amount_sat *htlc_fee);

4
channeld/test/run-full_channel.c

@ -136,7 +136,7 @@ static const struct htlc **include_htlcs(struct channel *channel, enum side side
int i;
const struct htlc **htlcs = tal_arr(channel, const struct htlc *, 5);
const struct htlc **changed_htlcs;
u8 *dummy_routing = tal_arr(htlcs, u8, TOTAL_PACKET_SIZE);
u8 *dummy_routing = tal_arr(htlcs, u8, TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE));
bool ret;
for (i = 0; i < 5; i++) {
@ -257,7 +257,7 @@ static void send_and_fulfill_htlc(struct channel *channel,
{
struct preimage r;
struct sha256 rhash;
u8 *dummy_routing = tal_arr(channel, u8, TOTAL_PACKET_SIZE);
u8 *dummy_routing = tal_arr(channel, u8, TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE));
bool ret;
const struct htlc **changed_htlcs;

2
common/htlc_wire.c

@ -34,7 +34,7 @@ struct existing_htlc *new_existing_htlc(const tal_t *ctx,
struct amount_msat amount,
const struct sha256 *payment_hash,
u32 cltv_expiry,
const u8 onion_routing_packet[TOTAL_PACKET_SIZE],
const u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)],
const struct pubkey *blinding TAKES,
const struct preimage *preimage TAKES,
const struct failed_htlc *failed TAKES)

6
common/htlc_wire.h

@ -17,7 +17,7 @@ struct added_htlc {
struct amount_msat amount;
struct sha256 payment_hash;
u32 cltv_expiry;
u8 onion_routing_packet[TOTAL_PACKET_SIZE];
u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
/* If this is non-NULL, secret is the resulting shared secret */
struct pubkey *blinding;
@ -31,7 +31,7 @@ struct existing_htlc {
struct amount_msat amount;
struct sha256 payment_hash;
u32 cltv_expiry;
u8 onion_routing_packet[TOTAL_PACKET_SIZE];
u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
/* If this is non-NULL, this is blinding to send with (outgoing) HTLC */
struct pubkey *blinding;
/* If fulfilled, this is non-NULL */
@ -71,7 +71,7 @@ struct existing_htlc *new_existing_htlc(const tal_t *ctx,
struct amount_msat amount,
const struct sha256 *payment_hash,
u32 cltv_expiry,
const u8 onion_routing_packet[TOTAL_PACKET_SIZE],
const u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)],
const struct pubkey *blinding TAKES,
const struct preimage *preimage TAKES,
const struct failed_htlc *failed TAKES);

6
common/sphinx.c

@ -131,7 +131,7 @@ u8 *serialize_onionpacket(
const tal_t *ctx,
const struct onionpacket *m)
{
u8 *dst = tal_arr(ctx, u8, TOTAL_PACKET_SIZE);
u8 *dst = tal_arr(ctx, u8, TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE));
u8 der[PUBKEY_CMPR_LEN];
int p = 0;
@ -151,7 +151,7 @@ enum onion_wire parse_onionpacket(const u8 *src,
const u8 *cursor = src;
size_t max = srclen;
assert(srclen == TOTAL_PACKET_SIZE);
assert(srclen == TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE));
dest->version = fromwire_u8(&cursor, &max);
if (dest->version != 0x00) {
@ -833,7 +833,7 @@ sphinx_compressed_onion_deserialize(const tal_t *ctx, const u8 *src)
tal(ctx, struct sphinx_compressed_onion);
/* This is not a compressed onion, so let's not parse it. */
if (max > TOTAL_PACKET_SIZE)
if (max > TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE))
return tal_free(dst);
dst->version = fromwire_u8(&cursor, &max);

2
common/sphinx.h

@ -20,7 +20,7 @@ struct node_id;
#define PUBKEY_SIZE 33
#define FRAME_SIZE 65
#define ROUTING_INFO_SIZE 1300
#define TOTAL_PACKET_SIZE (VERSION_SIZE + PUBKEY_SIZE + HMAC_SIZE + ROUTING_INFO_SIZE)
#define TOTAL_PACKET_SIZE(payload) (VERSION_SIZE + PUBKEY_SIZE + (payload) + HMAC_SIZE)
struct onionpacket {
/* Cleartext information */

2
devtools/blindedpath.c

@ -205,7 +205,7 @@ int main(int argc, char **argv)
} else if (streq(argv[1], "unwrap")) {
struct privkey privkey;
struct pubkey blinding;
u8 onion[TOTAL_PACKET_SIZE], *dec;
u8 onion[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)], *dec;
struct onionpacket op;
struct secret ss, onion_ss;
struct secret hmac, rho;

4
devtools/onion.c

@ -129,7 +129,7 @@ static struct route_step *decode_with_privkey(const tal_t *ctx, const u8 *onion,
if (!hex_decode(hexprivkey, strlen(hexprivkey), &seckey, sizeof(seckey)))
errx(1, "Invalid private key hex '%s'", hexprivkey);
why_bad = parse_onionpacket(onion, TOTAL_PACKET_SIZE, &packet);
why_bad = parse_onionpacket(onion, TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE), &packet);
if (why_bad != 0)
errx(1, "Error parsing message: %s", onion_wire_name(why_bad));
@ -146,7 +146,7 @@ static struct route_step *decode_with_privkey(const tal_t *ctx, const u8 *onion,
static void do_decode(int argc, char **argv, const u8 *assocdata)
{
const tal_t *ctx = talz(NULL, tal_t);
u8 serialized[TOTAL_PACKET_SIZE];
u8 serialized[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
struct route_step *step;
if (argc != 4)

4
lightningd/htlc_end.h

@ -31,7 +31,7 @@ struct htlc_in {
enum htlc_state hstate;
/* Onion information */
u8 onion_routing_packet[TOTAL_PACKET_SIZE];
u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
/* Shared secret for us to send any failure message (NULL if malformed) */
struct secret *shared_secret;
@ -70,7 +70,7 @@ struct htlc_out {
enum htlc_state hstate;
/* Onion information */
u8 onion_routing_packet[TOTAL_PACKET_SIZE];
u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
/* If a local error, this is non-NULL. */
const u8 *failmsg;

2
lightningd/onion_message.c

@ -168,7 +168,7 @@ void handle_onionmsg_forward(struct channel *channel, const u8 *msg)
struct short_channel_id *next_scid;
struct node_id *next_node;
struct pubkey *next_blinding;
u8 onion[TOTAL_PACKET_SIZE];
u8 onion[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
struct channel *outchan;
if (!fromwire_got_onionmsg_forward(msg, msg, &next_scid, &next_node,

2
lightningd/peer_htlcs.c

@ -678,7 +678,7 @@ static void forward_htlc(struct htlc_in *hin,
struct amount_msat amt_to_forward,
u32 outgoing_cltv_value,
const struct short_channel_id *scid,
const u8 next_onion[TOTAL_PACKET_SIZE],
const u8 next_onion[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)],
const struct pubkey *next_blinding)
{
const u8 *failmsg;

2
wire/test/run-peer-wire.c

@ -218,7 +218,7 @@ struct msg_update_add_htlc {
struct amount_msat amount_msat;
u32 expiry;
struct sha256 payment_hash;
u8 onion_routing_packet[TOTAL_PACKET_SIZE];
u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
};
struct msg_update_fee {
struct channel_id channel_id;

Loading…
Cancel
Save