2017-04-01 13:01:13 +02:00
|
|
|
#ifndef LIGHTNING_LIGHTNINGD_HTLC_END_H
|
|
|
|
#define LIGHTNING_LIGHTNINGD_HTLC_END_H
|
|
|
|
#include "config.h"
|
|
|
|
#include <ccan/htable/htable_type.h>
|
|
|
|
#include <ccan/short_types/short_types.h>
|
2017-06-20 07:50:03 +02:00
|
|
|
#include <daemon/htlc_state.h>
|
2017-04-30 23:49:15 +02:00
|
|
|
#include <lightningd/sphinx.h>
|
2017-06-20 08:07:03 +02:00
|
|
|
#include <wire/gen_onion_wire.h>
|
2017-04-01 13:01:13 +02:00
|
|
|
|
2017-06-20 07:53:03 +02:00
|
|
|
/* We look up HTLCs by peer & id */
|
|
|
|
struct htlc_key {
|
2017-04-01 13:01:13 +02:00
|
|
|
struct peer *peer;
|
2017-06-20 07:53:03 +02:00
|
|
|
u64 id;
|
|
|
|
};
|
2017-04-01 13:01:13 +02:00
|
|
|
|
2017-06-20 07:53:03 +02:00
|
|
|
/* Incoming HTLC */
|
|
|
|
struct htlc_in {
|
|
|
|
struct htlc_key key;
|
|
|
|
u64 msatoshi;
|
|
|
|
u32 cltv_expiry;
|
|
|
|
struct sha256 payment_hash;
|
2017-04-30 23:49:15 +02:00
|
|
|
|
2017-06-20 07:50:03 +02:00
|
|
|
enum htlc_state hstate;
|
|
|
|
|
2017-06-20 07:53:03 +02:00
|
|
|
/* Onion information */
|
|
|
|
u8 onion_routing_packet[TOTAL_PACKET_SIZE];
|
|
|
|
|
|
|
|
/* Shared secret for us to send any failure message. */
|
|
|
|
struct secret shared_secret;
|
|
|
|
|
2017-06-20 08:07:03 +02:00
|
|
|
/* If we failed HTLC, here's the message. */
|
2017-06-20 07:53:03 +02:00
|
|
|
const u8 *failuremsg;
|
|
|
|
|
2017-06-20 08:07:03 +02:00
|
|
|
/* If it was malformed, here's the error. */
|
|
|
|
enum onion_type malformed;
|
|
|
|
|
2017-06-20 07:53:03 +02:00
|
|
|
/* If they fulfilled, here's the preimage. */
|
|
|
|
struct preimage *preimage;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct htlc_out {
|
|
|
|
struct htlc_key key;
|
|
|
|
u64 msatoshi;
|
2017-04-30 23:49:15 +02:00
|
|
|
u32 cltv_expiry;
|
|
|
|
struct sha256 payment_hash;
|
2017-05-03 11:01:58 +02:00
|
|
|
|
2017-06-20 07:53:03 +02:00
|
|
|
enum htlc_state hstate;
|
|
|
|
|
|
|
|
/* Onion information */
|
|
|
|
u8 onion_routing_packet[TOTAL_PACKET_SIZE];
|
|
|
|
|
|
|
|
/* If we failed HTLC, here's the message. */
|
|
|
|
const u8 *failuremsg;
|
2017-06-20 07:42:03 +02:00
|
|
|
|
2017-06-20 08:07:03 +02:00
|
|
|
/* If it was malformed, here's the error. */
|
|
|
|
enum onion_type malformed;
|
|
|
|
|
2017-06-20 07:53:03 +02:00
|
|
|
/* If we fulfilled, here's the preimage. */
|
|
|
|
struct preimage *preimage;
|
2017-06-20 07:50:03 +02:00
|
|
|
|
2017-06-20 07:53:03 +02:00
|
|
|
/* Where it's from, if not going to us. */
|
|
|
|
struct htlc_in *in;
|
2017-05-03 11:01:58 +02:00
|
|
|
|
2017-06-20 07:53:03 +02:00
|
|
|
/* Otherwise, payment command which created it. */
|
|
|
|
struct pay_command *pay_command;
|
2017-04-01 13:01:13 +02:00
|
|
|
};
|
|
|
|
|
2017-06-20 07:53:03 +02:00
|
|
|
static inline const struct htlc_key *keyof_htlc_in(const struct htlc_in *in)
|
|
|
|
{
|
|
|
|
return &in->key;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const struct htlc_key *keyof_htlc_out(const struct htlc_out *out)
|
2017-04-01 13:01:13 +02:00
|
|
|
{
|
2017-06-20 07:53:03 +02:00
|
|
|
return &out->key;
|
2017-04-01 13:01:13 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 07:53:03 +02:00
|
|
|
size_t hash_htlc_key(const struct htlc_key *htlc_key);
|
|
|
|
|
|
|
|
static inline bool htlc_in_eq(const struct htlc_in *in, const struct htlc_key *k)
|
|
|
|
{
|
|
|
|
return in->key.peer == k->peer && in->key.id == k->id;
|
|
|
|
}
|
2017-04-01 13:01:13 +02:00
|
|
|
|
2017-06-20 07:53:03 +02:00
|
|
|
static inline bool htlc_out_eq(const struct htlc_out *out,
|
|
|
|
const struct htlc_key *k)
|
2017-04-01 13:01:13 +02:00
|
|
|
{
|
2017-06-20 07:53:03 +02:00
|
|
|
return out->key.peer == k->peer && out->key.id == k->id;
|
2017-04-01 13:01:13 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 07:53:03 +02:00
|
|
|
|
|
|
|
HTABLE_DEFINE_TYPE(struct htlc_in, keyof_htlc_in, hash_htlc_key, htlc_in_eq,
|
|
|
|
htlc_in_map);
|
|
|
|
|
|
|
|
HTABLE_DEFINE_TYPE(struct htlc_out, keyof_htlc_out, hash_htlc_key, htlc_out_eq,
|
|
|
|
htlc_out_map);
|
|
|
|
|
|
|
|
struct htlc_in *find_htlc_in(const struct htlc_in_map *map,
|
|
|
|
const struct peer *peer,
|
|
|
|
u64 htlc_id);
|
|
|
|
|
|
|
|
struct htlc_out *find_htlc_out(const struct htlc_out_map *map,
|
2017-04-01 13:01:13 +02:00
|
|
|
const struct peer *peer,
|
2017-06-20 07:53:03 +02:00
|
|
|
u64 htlc_id);
|
|
|
|
|
|
|
|
/* You still need to connect_htlc_in this! */
|
|
|
|
struct htlc_in *new_htlc_in(const tal_t *ctx,
|
|
|
|
struct peer *peer, u64 id,
|
|
|
|
u64 msatoshi, u32 cltv_expiry,
|
|
|
|
const struct sha256 *payment_hash,
|
|
|
|
const struct secret *shared_secret,
|
|
|
|
const u8 *onion_routing_packet);
|
|
|
|
|
|
|
|
/* You need to set the ID, then connect_htlc_out this! */
|
|
|
|
struct htlc_out *new_htlc_out(const tal_t *ctx,
|
|
|
|
struct peer *peer,
|
|
|
|
u64 msatoshi, u32 cltv_expiry,
|
|
|
|
const struct sha256 *payment_hash,
|
|
|
|
const u8 *onion_routing_packet,
|
|
|
|
struct htlc_in *in,
|
|
|
|
struct pay_command *pc);
|
|
|
|
|
|
|
|
void connect_htlc_in(struct htlc_in_map *map, struct htlc_in *hin);
|
|
|
|
void connect_htlc_out(struct htlc_out_map *map, struct htlc_out *hout);
|
2017-04-01 13:01:13 +02:00
|
|
|
|
2017-06-20 07:53:03 +02:00
|
|
|
struct htlc_out *htlc_out_check(const struct htlc_out *hout,
|
|
|
|
const char *abortstr);
|
|
|
|
struct htlc_in *htlc_in_check(const struct htlc_in *hin, const char *abortstr);
|
2017-04-01 13:01:13 +02:00
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_HTLC_END_H */
|