2016-01-21 21:11:48 +01:00
|
|
|
#ifndef LIGHTNING_DAEMON_PEER_H
|
|
|
|
#define LIGHTNING_DAEMON_PEER_H
|
|
|
|
#include "config.h"
|
2016-01-21 21:14:13 +01:00
|
|
|
#include "bitcoin/locktime.h"
|
2016-04-12 05:37:04 +02:00
|
|
|
#include "bitcoin/privkey.h"
|
2016-01-21 21:11:49 +01:00
|
|
|
#include "bitcoin/pubkey.h"
|
2016-01-21 21:14:27 +01:00
|
|
|
#include "bitcoin/script.h"
|
|
|
|
#include "bitcoin/shadouble.h"
|
2016-06-30 01:38:10 +02:00
|
|
|
#include "channel.h"
|
2016-08-31 07:21:41 +02:00
|
|
|
#include "failure.h"
|
2016-08-26 08:01:19 +02:00
|
|
|
#include "feechange.h"
|
2016-06-30 01:38:11 +02:00
|
|
|
#include "htlc.h"
|
2016-01-21 21:11:48 +01:00
|
|
|
#include "lightning.pb-c.h"
|
2016-01-21 21:11:48 +01:00
|
|
|
#include "netaddr.h"
|
2016-06-28 23:19:20 +02:00
|
|
|
#include "protobuf_convert.h"
|
2016-01-21 21:14:25 +01:00
|
|
|
#include "state.h"
|
2017-01-04 04:39:20 +01:00
|
|
|
#include "wire/gen_peer_wire.h"
|
2016-01-21 21:14:13 +01:00
|
|
|
#include <ccan/crypto/sha256/sha256.h>
|
2016-06-23 16:38:35 +02:00
|
|
|
#include <ccan/crypto/shachain/shachain.h>
|
2016-01-21 21:11:48 +01:00
|
|
|
#include <ccan/list/list.h>
|
2016-01-21 21:15:28 +01:00
|
|
|
#include <ccan/time/time.h>
|
2016-01-21 21:11:48 +01:00
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
struct log;
|
|
|
|
struct lightningd_state;
|
|
|
|
struct peer;
|
2016-01-21 21:11:48 +01:00
|
|
|
|
2016-08-18 06:55:14 +02:00
|
|
|
/* Mapping for id -> network address. */
|
|
|
|
struct peer_address {
|
|
|
|
struct list_node list;
|
|
|
|
struct pubkey id;
|
|
|
|
struct netaddr addr;
|
|
|
|
};
|
|
|
|
|
2017-01-04 04:39:15 +01:00
|
|
|
void setup_listeners(struct lightningd_state *dstate);
|
2016-01-21 21:11:48 +01:00
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
void peer_debug(struct peer *peer, const char *fmt, ...)
|
|
|
|
PRINTF_FMT(2,3);
|
|
|
|
|
2016-06-28 23:19:21 +02:00
|
|
|
struct peer *find_peer(struct lightningd_state *dstate, const struct pubkey *id);
|
2016-10-06 22:06:20 +02:00
|
|
|
struct peer *find_peer_by_pkhash(struct lightningd_state *dstate, const u8 *pkhash);
|
2016-06-28 23:19:21 +02:00
|
|
|
|
2016-08-18 06:55:13 +02:00
|
|
|
struct peer *new_peer(struct lightningd_state *dstate,
|
2016-08-31 08:36:31 +02:00
|
|
|
struct log *log,
|
2016-08-18 06:55:13 +02:00
|
|
|
enum state state,
|
2016-11-08 22:34:24 +01:00
|
|
|
bool offer_anchor);
|
2016-08-18 06:55:13 +02:00
|
|
|
|
2016-05-26 07:55:24 +02:00
|
|
|
/* Populates very first peer->{local,remote}.commit->{tx,cstate} */
|
2016-03-31 08:43:20 +02:00
|
|
|
bool setup_first_commit(struct peer *peer);
|
2016-01-21 21:14:27 +01:00
|
|
|
|
2016-08-18 06:53:45 +02:00
|
|
|
/* Whenever we send a signature, remember the txid -> commit_num mapping */
|
2016-09-06 09:17:49 +02:00
|
|
|
void peer_add_their_commit(struct peer *peer,
|
2016-08-18 06:53:45 +02:00
|
|
|
const struct sha256_double *txid, u64 commit_num);
|
|
|
|
|
2016-08-18 06:53:45 +02:00
|
|
|
/* Allocate a new commit_info struct. */
|
2016-08-18 06:53:46 +02:00
|
|
|
struct commit_info *new_commit_info(const tal_t *ctx, u64 commit_num);
|
2016-08-18 06:53:45 +02:00
|
|
|
|
2016-06-30 01:38:11 +02:00
|
|
|
/* Freeing removes from map, too */
|
2016-11-11 00:02:04 +01:00
|
|
|
struct htlc *peer_new_htlc(struct peer *peer,
|
2016-06-30 01:38:11 +02:00
|
|
|
u64 id,
|
2016-09-06 09:17:49 +02:00
|
|
|
u64 msatoshi,
|
2016-06-30 01:38:11 +02:00
|
|
|
const struct sha256 *rhash,
|
|
|
|
u32 expiry,
|
|
|
|
const u8 *route,
|
|
|
|
size_t route_len,
|
2016-06-30 01:38:11 +02:00
|
|
|
struct htlc *src,
|
2016-08-18 06:53:45 +02:00
|
|
|
enum htlc_state state);
|
2016-06-30 01:38:11 +02:00
|
|
|
|
2016-09-06 09:17:49 +02:00
|
|
|
const char *command_htlc_add(struct peer *peer, u64 msatoshi,
|
2016-08-31 07:21:41 +02:00
|
|
|
unsigned int expiry,
|
|
|
|
const struct sha256 *rhash,
|
|
|
|
struct htlc *src,
|
|
|
|
const u8 *route,
|
|
|
|
enum fail_error *error_code,
|
|
|
|
struct htlc **htlc);
|
2016-06-30 01:38:11 +02:00
|
|
|
|
2016-09-02 04:30:18 +02:00
|
|
|
/* Peer has an issue, breakdown and fail. */
|
|
|
|
void peer_fail(struct peer *peer, const char *caller);
|
|
|
|
|
2016-11-08 22:34:25 +01:00
|
|
|
void peer_watch_anchor(struct peer *peer, int depth);
|
2016-05-26 07:55:25 +02:00
|
|
|
|
2016-11-07 13:33:02 +01:00
|
|
|
struct bitcoin_tx *peer_create_close_tx(const tal_t *ctx,
|
|
|
|
struct peer *peer, u64 fee);
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
u32 get_peer_min_block(struct lightningd_state *dstate);
|
|
|
|
|
2016-08-18 06:55:14 +02:00
|
|
|
void debug_dump_peers(struct lightningd_state *dstate);
|
|
|
|
|
2016-08-18 06:55:08 +02:00
|
|
|
void reconnect_peers(struct lightningd_state *dstate);
|
2016-11-09 09:22:15 +01:00
|
|
|
void rebroadcast_anchors(struct lightningd_state *dstate);
|
2016-06-30 01:38:11 +02:00
|
|
|
void cleanup_peers(struct lightningd_state *dstate);
|
2016-01-21 21:11:48 +01:00
|
|
|
#endif /* LIGHTNING_DAEMON_PEER_H */
|