2017-01-10 06:08:33 +01:00
|
|
|
#ifndef LIGHTNING_LIGHTNINGD_PEER_CONTROL_H
|
|
|
|
#define LIGHTNING_LIGHTNINGD_PEER_CONTROL_H
|
|
|
|
#include "config.h"
|
2017-01-10 06:08:33 +01:00
|
|
|
#include <ccan/compiler/compiler.h>
|
2017-06-20 07:51:03 +02:00
|
|
|
#include <ccan/crypto/shachain/shachain.h>
|
2017-04-01 12:24:59 +02:00
|
|
|
#include <ccan/list/list.h>
|
2017-08-28 18:05:01 +02:00
|
|
|
#include <common/channel_config.h>
|
2017-08-28 18:04:01 +02:00
|
|
|
#include <common/htlc.h>
|
|
|
|
#include <common/json.h>
|
2019-04-08 11:58:32 +02:00
|
|
|
#include <common/node_id.h>
|
2017-10-23 06:17:38 +02:00
|
|
|
#include <common/wireaddr.h>
|
2018-02-12 11:12:55 +01:00
|
|
|
#include <lightningd/channel.h>
|
2018-02-19 02:06:14 +01:00
|
|
|
#include <lightningd/channel_state.h>
|
2017-01-10 06:08:33 +01:00
|
|
|
#include <stdbool.h>
|
2017-07-19 16:55:47 +02:00
|
|
|
#include <wallet/wallet.h>
|
2017-06-27 04:55:01 +02:00
|
|
|
#include <wire/peer_wire.h>
|
2017-01-10 06:08:33 +01:00
|
|
|
|
2019-06-03 20:11:25 +02:00
|
|
|
struct per_peer_state;
|
2017-02-24 06:52:56 +01:00
|
|
|
|
2017-01-10 06:08:33 +01:00
|
|
|
struct peer {
|
2017-12-15 11:22:57 +01:00
|
|
|
/* Inside ld->peers. */
|
|
|
|
struct list_node list;
|
|
|
|
|
|
|
|
/* Master context */
|
2017-01-10 06:08:33 +01:00
|
|
|
struct lightningd *ld;
|
|
|
|
|
2017-08-14 22:06:59 +02:00
|
|
|
/* Database ID of the peer */
|
|
|
|
u64 dbid;
|
|
|
|
|
2017-06-06 05:08:42 +02:00
|
|
|
/* ID of peer */
|
2019-04-08 11:58:32 +02:00
|
|
|
struct node_id id;
|
2017-06-06 05:08:42 +02:00
|
|
|
|
2018-02-12 11:12:55 +01:00
|
|
|
/* Our channels */
|
|
|
|
struct list_head channels;
|
2017-01-10 06:08:33 +01:00
|
|
|
|
2018-02-19 02:06:02 +01:00
|
|
|
/* Our (only) uncommitted channel, still opening. */
|
|
|
|
struct uncommitted_channel *uncommitted_channel;
|
|
|
|
|
2017-01-10 06:08:33 +01:00
|
|
|
/* Where we connected to, or it connected from. */
|
2018-05-07 06:29:21 +02:00
|
|
|
struct wireaddr_internal addr;
|
2017-01-10 06:08:33 +01:00
|
|
|
|
2018-07-24 08:18:59 +02:00
|
|
|
/* We keep a copy of their feature bits */
|
2020-04-03 02:03:59 +02:00
|
|
|
const u8 *their_features;
|
2018-07-24 08:18:59 +02:00
|
|
|
|
2018-01-23 22:11:44 +01:00
|
|
|
/* If we open a channel our direction will be this */
|
|
|
|
u8 direction;
|
2018-04-03 09:19:42 +02:00
|
|
|
|
|
|
|
#if DEVELOPER
|
|
|
|
/* Swallow incoming HTLCs (for testing) */
|
|
|
|
bool ignore_htlcs;
|
|
|
|
#endif
|
2017-01-10 06:08:33 +01:00
|
|
|
};
|
2017-01-10 06:08:33 +01:00
|
|
|
|
2018-02-12 11:12:55 +01:00
|
|
|
struct peer *find_peer_by_dbid(struct lightningd *ld, u64 dbid);
|
|
|
|
|
|
|
|
struct peer *new_peer(struct lightningd *ld, u64 dbid,
|
2019-04-08 11:58:32 +02:00
|
|
|
const struct node_id *id,
|
2018-10-26 08:01:26 +02:00
|
|
|
const struct wireaddr_internal *addr);
|
2017-05-22 13:24:59 +02:00
|
|
|
|
2018-08-02 08:49:55 +02:00
|
|
|
/* Last one out deletes peer. Also removes from db. */
|
|
|
|
void maybe_delete_peer(struct peer *peer);
|
2018-02-14 02:53:04 +01:00
|
|
|
|
2019-04-08 11:58:32 +02:00
|
|
|
struct peer *peer_by_id(struct lightningd *ld, const struct node_id *id);
|
2017-04-01 12:24:59 +02:00
|
|
|
struct peer *peer_from_json(struct lightningd *ld,
|
|
|
|
const char *buffer,
|
2018-07-20 03:14:02 +02:00
|
|
|
const jsmntok_t *peeridtok);
|
2017-02-24 06:52:56 +01:00
|
|
|
|
gossipd: rewrite to do the handshake internally.
Now the flow is much simpler from a lightningd POV:
1. If we want to connect to a peer, just send gossipd `gossipctl_reach_peer`.
2. Every new peer, gossipd hands up to lightningd, with global/local features
and the peer fd and a gossip fd using `gossip_peer_connected`
3. If lightningd doesn't want it, it just hands the peerfd and global/local
features back to gossipd using `gossipctl_handle_peer`
4. If a peer sends a non-gossip msg (eg `open_channel`) the gossipd sends
it up using `gossip_peer_nongossip`.
5. If lightningd wants to fund a channel, it simply calls `release_channel`.
Notes:
* There's no more "unique_id": we use the peer id.
* For the moment, we don't ask gossipd when we're told to list peers, so
connected peers without a channel don't appear in the JSON getpeers API.
* We add a `gossipctl_peer_addrhint` for the moment, so you can connect to
a specific ip/port, but using other sources is a TODO.
* We now (correctly) only give up on reaching a peer after we exchange init
messages, which changes the test_disconnect case.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-11 12:09:49 +02:00
|
|
|
void peer_connected(struct lightningd *ld, const u8 *msg,
|
2019-05-04 07:53:13 +02:00
|
|
|
int peer_fd, int gossip_fd, int gossip_store_fd);
|
gossipd: rewrite to do the handshake internally.
Now the flow is much simpler from a lightningd POV:
1. If we want to connect to a peer, just send gossipd `gossipctl_reach_peer`.
2. Every new peer, gossipd hands up to lightningd, with global/local features
and the peer fd and a gossip fd using `gossip_peer_connected`
3. If lightningd doesn't want it, it just hands the peerfd and global/local
features back to gossipd using `gossipctl_handle_peer`
4. If a peer sends a non-gossip msg (eg `open_channel`) the gossipd sends
it up using `gossip_peer_nongossip`.
5. If lightningd wants to fund a channel, it simply calls `release_channel`.
Notes:
* There's no more "unique_id": we use the peer id.
* For the moment, we don't ask gossipd when we're told to list peers, so
connected peers without a channel don't appear in the JSON getpeers API.
* We add a `gossipctl_peer_addrhint` for the moment, so you can connect to
a specific ip/port, but using other sources is a TODO.
* We now (correctly) only give up on reaching a peer after we exchange init
messages, which changes the test_disconnect case.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-11 12:09:49 +02:00
|
|
|
|
2017-06-27 04:55:01 +02:00
|
|
|
/* Could be configurable. */
|
|
|
|
#define OUR_CHANNEL_FLAGS CHANNEL_FLAGS_ANNOUNCE_CHANNEL
|
|
|
|
|
2018-02-20 21:59:09 +01:00
|
|
|
void channel_errmsg(struct channel *channel,
|
2019-06-03 20:11:25 +02:00
|
|
|
struct per_peer_state *pps,
|
2018-02-20 21:59:09 +01:00
|
|
|
const struct channel_id *channel_id,
|
|
|
|
const char *desc,
|
2019-07-26 04:11:19 +02:00
|
|
|
bool soft_error,
|
2018-02-20 21:59:09 +01:00
|
|
|
const u8 *err_for_them);
|
|
|
|
|
|
|
|
u8 *p2wpkh_for_keyidx(const tal_t *ctx, struct lightningd *ld, u64 keyidx);
|
|
|
|
|
2018-01-03 06:26:44 +01:00
|
|
|
/* We've loaded peers from database, set them going. */
|
|
|
|
void activate_peers(struct lightningd *ld);
|
|
|
|
|
2018-04-10 08:03:15 +02:00
|
|
|
void drop_to_chain(struct lightningd *ld, struct channel *channel, bool cooperative);
|
2018-02-12 11:13:04 +01:00
|
|
|
|
2018-02-20 21:59:04 +01:00
|
|
|
void channel_watch_funding(struct lightningd *ld, struct channel *channel);
|
2018-09-03 03:08:53 +02:00
|
|
|
|
2019-08-10 07:24:57 +02:00
|
|
|
/* Pull peers, channels and HTLCs from db, and wire them up.
|
|
|
|
* Returns any HTLCs we have to resubmit via htlcs_resubmit. */
|
|
|
|
struct htlc_in_map *load_channels_from_wallet(struct lightningd *ld);
|
2018-11-22 03:17:29 +01:00
|
|
|
|
|
|
|
#if DEVELOPER
|
|
|
|
void peer_dev_memleak(struct command *cmd);
|
2019-12-05 00:11:28 +01:00
|
|
|
void handle_custommsg_in(struct lightningd *ld, const struct node_id *peer_id,
|
|
|
|
const u8 *msg);
|
2018-11-22 03:17:29 +01:00
|
|
|
#endif /* DEVELOPER */
|
|
|
|
|
2019-12-26 11:19:09 +01:00
|
|
|
/* Triggered at each new block. */
|
|
|
|
void waitblockheight_notify_new_block(struct lightningd *ld,
|
|
|
|
u32 block_height);
|
|
|
|
|
2017-01-10 06:08:33 +01:00
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_PEER_CONTROL_H */
|