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