2016-06-28 23:19:21 +02:00
|
|
|
#ifndef LIGHTNING_DAEMON_ROUTING_H
|
|
|
|
#define LIGHTNING_DAEMON_ROUTING_H
|
|
|
|
#include "config.h"
|
|
|
|
#include "bitcoin/pubkey.h"
|
|
|
|
|
|
|
|
#define ROUTING_MAX_HOPS 20
|
|
|
|
|
|
|
|
struct node_connection {
|
|
|
|
struct node *src, *dst;
|
|
|
|
/* millisatoshi. */
|
|
|
|
u32 base_fee;
|
|
|
|
/* millionths */
|
|
|
|
s32 proportional_fee;
|
|
|
|
|
|
|
|
/* Delay for HTLC in blocks.*/
|
|
|
|
u32 delay;
|
|
|
|
/* Minimum allowable HTLC expiry in blocks. */
|
|
|
|
u32 min_blocks;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct node {
|
|
|
|
struct pubkey id;
|
2016-09-28 16:52:03 +02:00
|
|
|
|
|
|
|
/* IP/Hostname and port of this node */
|
|
|
|
char *hostname;
|
|
|
|
int port;
|
|
|
|
|
2016-08-18 06:55:13 +02:00
|
|
|
/* Routes connecting to us, from us. */
|
|
|
|
struct node_connection **in, **out;
|
2016-06-28 23:19:21 +02:00
|
|
|
|
|
|
|
/* Temporary data for routefinding. */
|
|
|
|
struct {
|
|
|
|
/* Total to get to here from target. */
|
|
|
|
s64 total;
|
2016-09-06 09:17:48 +02:00
|
|
|
/* Total risk premium of this route. */
|
|
|
|
u64 risk;
|
2016-06-28 23:19:21 +02:00
|
|
|
/* Where that came from. */
|
|
|
|
struct node_connection *prev;
|
|
|
|
} bfg[ROUTING_MAX_HOPS+1];
|
2016-10-28 16:40:27 +02:00
|
|
|
|
|
|
|
/* UTF-8 encoded alias as tal_arr, not zero terminated */
|
|
|
|
u8 *alias;
|
2016-06-28 23:19:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct lightningd_state;
|
|
|
|
|
|
|
|
struct node *new_node(struct lightningd_state *dstate,
|
|
|
|
const struct pubkey *id);
|
|
|
|
|
|
|
|
struct node *get_node(struct lightningd_state *dstate,
|
|
|
|
const struct pubkey *id);
|
|
|
|
|
|
|
|
/* msatoshi must be possible (< 21 million BTC), ie < 2^60.
|
2016-09-06 09:17:49 +02:00
|
|
|
* If it returns more than msatoshi, it overflowed. */
|
2016-06-28 23:19:21 +02:00
|
|
|
s64 connection_fee(const struct node_connection *c, u64 msatoshi);
|
|
|
|
|
2016-09-28 16:52:03 +02:00
|
|
|
/* Updates existing node, or creates a new one as required. */
|
|
|
|
struct node *add_node(struct lightningd_state *dstate,
|
|
|
|
const struct pubkey *pk,
|
|
|
|
char *hostname,
|
|
|
|
int port);
|
|
|
|
|
2016-06-28 23:19:21 +02:00
|
|
|
/* Updates existing connection, or creates new one as required. */
|
|
|
|
struct node_connection *add_connection(struct lightningd_state *dstate,
|
2016-08-18 06:55:13 +02:00
|
|
|
const struct pubkey *from,
|
|
|
|
const struct pubkey *to,
|
2016-06-28 23:19:21 +02:00
|
|
|
u32 base_fee, s32 proportional_fee,
|
|
|
|
u32 delay, u32 min_blocks);
|
|
|
|
|
2016-08-31 08:40:17 +02:00
|
|
|
void remove_connection(struct lightningd_state *dstate,
|
|
|
|
const struct pubkey *src, const struct pubkey *dst);
|
|
|
|
|
2016-11-04 01:47:04 +01:00
|
|
|
struct peer *find_route(const tal_t *ctx,
|
|
|
|
struct lightningd_state *dstate,
|
2016-06-28 23:19:21 +02:00
|
|
|
const struct pubkey *to,
|
2016-09-06 09:17:48 +02:00
|
|
|
u64 msatoshi,
|
|
|
|
double riskfactor,
|
|
|
|
s64 *fee,
|
2016-06-28 23:19:21 +02:00
|
|
|
struct node_connection ***route);
|
|
|
|
|
|
|
|
struct node_map *empty_node_map(struct lightningd_state *dstate);
|
|
|
|
|
2016-08-18 06:55:14 +02:00
|
|
|
char *opt_add_route(const char *arg, struct lightningd_state *dstate);
|
|
|
|
|
2016-06-28 23:19:21 +02:00
|
|
|
#endif /* LIGHTNING_DAEMON_ROUTING_H */
|