mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
f7ebbb2ec5
Now "raw_payload" is always the complete string (including realm or length bytes at the front). This has several effects: 1. We can receive an decrypt an onion which is grossly malformed. 2. We can still hand this to the htlc_accepted hook. 3. We then fail it unless the htlc_accepted accepts it manually. 4. The createonion API now takes the raw payload, and does not know anything about "style". The only caveat is that the sphinx code needs to know the payload length: we have a call for that, which simply tells it to copy the entire onion (and treat us as the final node) if it's invalid. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
65 lines
1.9 KiB
C
65 lines
1.9 KiB
C
#ifndef LIGHTNING_COMMON_ONION_H
|
|
#define LIGHTNING_COMMON_ONION_H
|
|
#include "config.h"
|
|
#include <ccan/short_types/short_types.h>
|
|
#include <common/amount.h>
|
|
|
|
struct route_step;
|
|
|
|
enum onion_payload_type {
|
|
ONION_V0_PAYLOAD = 0,
|
|
ONION_TLV_PAYLOAD = 1,
|
|
};
|
|
|
|
struct onion_payload {
|
|
enum onion_payload_type type;
|
|
|
|
struct amount_msat amt_to_forward;
|
|
u32 outgoing_cltv;
|
|
struct amount_msat *total_msat;
|
|
struct short_channel_id *forward_channel;
|
|
struct secret *payment_secret;
|
|
};
|
|
|
|
u8 *onion_nonfinal_hop(const tal_t *ctx,
|
|
bool use_tlv,
|
|
const struct short_channel_id *scid,
|
|
struct amount_msat forward,
|
|
u32 outgoing_cltv);
|
|
|
|
/* Note that this can fail if we supply payment_secret and !use_tlv! */
|
|
u8 *onion_final_hop(const tal_t *ctx,
|
|
bool use_tlv,
|
|
struct amount_msat forward,
|
|
u32 outgoing_cltv,
|
|
struct amount_msat total_msat,
|
|
const struct secret *payment_secret);
|
|
|
|
/**
|
|
* onion_payload_length: measure payload length in decrypted onion.
|
|
* @raw_payload: payload to look at.
|
|
* @len: length of @raw_payload in bytes.
|
|
* @valid: set to true if it is valid, false otherwise.
|
|
* @type: if non-NULL, set to type of payload if *@valid is true.
|
|
*
|
|
* If @valid is set, there is room for the HMAC immediately following,
|
|
* as the return value is <= ROUTING_INFO_SIZE - HMAC_SIZE. Otherwise,
|
|
* the return value is @len (i.e. the entire payload).
|
|
*/
|
|
size_t onion_payload_length(const u8 *raw_payload, size_t len,
|
|
bool *valid,
|
|
enum onion_payload_type *type);
|
|
|
|
/**
|
|
* onion_decode: decode payload from a decrypted onion.
|
|
* @ctx: context to allocate onion_contents off.
|
|
* @rs: the route_step, whose raw_payload is of at least length
|
|
* onion_payload_length().
|
|
*
|
|
* If the payload is not valid, returns NULL.
|
|
*/
|
|
struct onion_payload *onion_decode(const tal_t *ctx,
|
|
const struct route_step *rs);
|
|
|
|
#endif /* LIGHTNING_COMMON_ONION_H */
|