mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 17:47:30 +01:00
gossipd: tell the master the peer's address.
This will let us remove peer->netaddr. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
33bfc2326a
commit
dfd60a2047
5 changed files with 43 additions and 17 deletions
|
@ -194,6 +194,7 @@ static struct addrhint *find_addrhint(struct daemon *daemon,
|
|||
static struct peer *new_peer(const tal_t *ctx,
|
||||
struct daemon *daemon,
|
||||
const struct pubkey *their_id,
|
||||
const struct ipaddr *addr,
|
||||
const struct crypto_state *cs)
|
||||
{
|
||||
struct peer *peer = tal(ctx, struct peer);
|
||||
|
@ -201,6 +202,7 @@ static struct peer *new_peer(const tal_t *ctx,
|
|||
init_peer_crypto_state(peer, &peer->pcs);
|
||||
peer->pcs.cs = *cs;
|
||||
peer->id = *their_id;
|
||||
peer->addr = *addr;
|
||||
peer->daemon = daemon;
|
||||
peer->local = true;
|
||||
peer->reach_again = false;
|
||||
|
@ -310,7 +312,8 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
|
|||
peer_finalized(peer);
|
||||
|
||||
/* We will not have anything queued, since we're not duplex. */
|
||||
msg = towire_gossip_peer_connected(peer, &peer->id, &peer->pcs.cs,
|
||||
msg = towire_gossip_peer_connected(peer, &peer->id, &peer->addr,
|
||||
&peer->pcs.cs,
|
||||
peer->gfeatures, peer->lfeatures);
|
||||
if (!send_peer_with_fds(peer, msg))
|
||||
return io_close(conn);
|
||||
|
@ -343,11 +346,10 @@ static struct io_plan *init_new_peer(struct io_conn *conn,
|
|||
const struct crypto_state *cs,
|
||||
struct daemon *daemon)
|
||||
{
|
||||
struct peer *peer = new_peer(conn, daemon, their_id, cs);
|
||||
struct peer *peer = new_peer(conn, daemon, their_id, addr, cs);
|
||||
u8 *initmsg;
|
||||
|
||||
peer->fd = io_conn_fd(conn);
|
||||
peer->addr = *addr;
|
||||
|
||||
/* BOLT #1:
|
||||
*
|
||||
|
@ -429,12 +431,14 @@ static struct io_plan *ready_for_master(struct io_conn *conn, struct peer *peer)
|
|||
u8 *msg;
|
||||
if (peer->nongossip_msg)
|
||||
msg = towire_gossip_peer_nongossip(peer, &peer->id,
|
||||
&peer->addr,
|
||||
&peer->pcs.cs,
|
||||
peer->gfeatures,
|
||||
peer->lfeatures,
|
||||
peer->nongossip_msg);
|
||||
else
|
||||
msg = towire_gossipctl_release_peer_reply(peer,
|
||||
&peer->addr,
|
||||
&peer->pcs.cs,
|
||||
peer->gfeatures,
|
||||
peer->lfeatures);
|
||||
|
@ -714,10 +718,11 @@ static struct io_plan *handle_peer(struct io_conn *conn, struct daemon *daemon,
|
|||
struct peer *peer;
|
||||
struct crypto_state cs;
|
||||
struct pubkey id;
|
||||
struct ipaddr addr;
|
||||
u8 *gfeatures, *lfeatures;
|
||||
u8 *inner_msg;
|
||||
|
||||
if (!fromwire_gossipctl_handle_peer(msg, msg, NULL, &id, &cs,
|
||||
if (!fromwire_gossipctl_handle_peer(msg, msg, NULL, &id, &addr, &cs,
|
||||
&gfeatures, &lfeatures, &inner_msg))
|
||||
master_badmsg(WIRE_GOSSIPCTL_HANDLE_PEER, msg);
|
||||
|
||||
|
@ -738,7 +743,7 @@ static struct io_plan *handle_peer(struct io_conn *conn, struct daemon *daemon,
|
|||
|
||||
status_trace("handle_peer %s: new peer",
|
||||
type_to_string(trc, struct pubkey, &id));
|
||||
peer = new_peer(daemon, daemon, &id, &cs);
|
||||
peer = new_peer(daemon, daemon, &id, &addr, &cs);
|
||||
peer->gfeatures = tal_steal(peer, gfeatures);
|
||||
peer->lfeatures = tal_steal(peer, lfeatures);
|
||||
peer_finalized(peer);
|
||||
|
|
|
@ -24,6 +24,7 @@ gossipctl_reach_peer,,id,struct pubkey
|
|||
# Gossipd -> master: we got a peer. Two fds: peer and gossip
|
||||
gossip_peer_connected,3002
|
||||
gossip_peer_connected,,id,struct pubkey
|
||||
gossip_peer_connected,,addr,struct ipaddr
|
||||
gossip_peer_connected,,crypto_state,struct crypto_state
|
||||
gossip_peer_connected,,gflen,u16
|
||||
gossip_peer_connected,,gfeatures,gflen*u8
|
||||
|
@ -33,6 +34,7 @@ gossip_peer_connected,,lfeatures,lflen*u8
|
|||
# Gossipd -> master: peer sent non-gossip packet. Two fds: peer and gossip
|
||||
gossip_peer_nongossip,3003
|
||||
gossip_peer_nongossip,,id,struct pubkey
|
||||
gossip_peer_nongossip,,addr,struct ipaddr
|
||||
gossip_peer_nongossip,,crypto_state,struct crypto_state
|
||||
gossip_peer_nongossip,,gflen,u16
|
||||
gossip_peer_nongossip,,gfeatures,gflen*u8
|
||||
|
@ -47,6 +49,7 @@ gossipctl_release_peer,,id,struct pubkey
|
|||
|
||||
# Gossipd -> master: reply to gossip_release_peer. Two fds: peer and gossip.
|
||||
gossipctl_release_peer_reply,3104
|
||||
gossipctl_release_peer_reply,,addr,struct ipaddr
|
||||
gossipctl_release_peer_reply,,crypto_state,struct crypto_state
|
||||
gossipctl_release_peer_reply,,gflen,u16
|
||||
gossipctl_release_peer_reply,,gfeatures,gflen*u8
|
||||
|
@ -59,6 +62,7 @@ gossipctl_release_peer_replyfail,3204
|
|||
# Gossipd -> master: take over peer, with optional msg. (+peer fd)
|
||||
gossipctl_handle_peer,3013
|
||||
gossipctl_handle_peer,,id,struct pubkey
|
||||
gossipctl_handle_peer,,addr,struct ipaddr
|
||||
gossipctl_handle_peer,,crypto_state,struct crypto_state
|
||||
gossipctl_handle_peer,,gflen,u16
|
||||
gossipctl_handle_peer,,gfeatures,gflen*u8
|
||||
|
|
|
|
@ -24,10 +24,11 @@ static void peer_nongossip(struct subd *gossip, const u8 *msg,
|
|||
{
|
||||
struct pubkey id;
|
||||
struct crypto_state cs;
|
||||
struct ipaddr addr;
|
||||
u8 *gfeatures, *lfeatures, *in_pkt;
|
||||
|
||||
if (!fromwire_gossip_peer_nongossip(msg, msg, NULL,
|
||||
&id, &cs,
|
||||
&id, &addr, &cs,
|
||||
&gfeatures,
|
||||
&lfeatures,
|
||||
&in_pkt))
|
||||
|
@ -45,7 +46,7 @@ static void peer_nongossip(struct subd *gossip, const u8 *msg,
|
|||
return;
|
||||
}
|
||||
|
||||
peer_sent_nongossip(gossip->ld, &id, &cs, gfeatures, lfeatures,
|
||||
peer_sent_nongossip(gossip->ld, &id, &addr, &cs, gfeatures, lfeatures,
|
||||
peer_fd, gossip_fd, in_pkt);
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ struct connect {
|
|||
struct funding_channel;
|
||||
static void peer_offer_channel(struct lightningd *ld,
|
||||
struct funding_channel *fc,
|
||||
const struct ipaddr *addr,
|
||||
const struct crypto_state *cs,
|
||||
const u8 *gfeatures, const u8 *lfeatures,
|
||||
int peer_fd, int gossip_fd);
|
||||
|
@ -70,6 +71,7 @@ static void peer_start_closingd(struct peer *peer,
|
|||
bool reconnected);
|
||||
static void peer_accept_channel(struct lightningd *ld,
|
||||
const struct pubkey *peer_id,
|
||||
const struct ipaddr *addr,
|
||||
const struct crypto_state *cs,
|
||||
const u8 *gfeatures, const u8 *lfeatures,
|
||||
int peer_fd, int gossip_fd,
|
||||
|
@ -305,6 +307,7 @@ static void connect_failed(struct lightningd *ld, const struct pubkey *id,
|
|||
|
||||
static struct peer *new_peer(struct lightningd *ld,
|
||||
const struct pubkey *id,
|
||||
const struct ipaddr *addr,
|
||||
const u8 *gfeatures, const u8 *lfeatures,
|
||||
int peer_fd)
|
||||
{
|
||||
|
@ -314,6 +317,7 @@ static struct peer *new_peer(struct lightningd *ld,
|
|||
peer = talz(ld, struct peer);
|
||||
peer->error = NULL;
|
||||
peer->id = *id;
|
||||
peer->addr = *addr;
|
||||
peer->funding_txid = NULL;
|
||||
peer->remote_funding_locked = false;
|
||||
peer->scid = NULL;
|
||||
|
@ -506,9 +510,11 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
|
|||
u8 *gfeatures, *lfeatures;
|
||||
u8 *error;
|
||||
struct peer *peer;
|
||||
struct ipaddr addr;
|
||||
|
||||
if (!fromwire_gossip_peer_connected(msg, msg, NULL,
|
||||
&id, &cs, &gfeatures, &lfeatures))
|
||||
&id, &addr, &cs,
|
||||
&gfeatures, &lfeatures))
|
||||
fatal("Gossip gave bad GOSSIP_PEER_CONNECTED message %s",
|
||||
tal_hex(msg, msg));
|
||||
|
||||
|
@ -567,6 +573,7 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
|
|||
* on this peer. */
|
||||
peer_set_owner(peer, NULL);
|
||||
|
||||
peer->addr = addr;
|
||||
peer_start_channeld(peer, &cs, peer_fd, gossip_fd, NULL,
|
||||
true);
|
||||
return;
|
||||
|
@ -577,6 +584,7 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
|
|||
* on this peer. */
|
||||
peer_set_owner(peer, NULL);
|
||||
|
||||
peer->addr = addr;
|
||||
peer_start_closingd(peer, &cs, peer_fd, gossip_fd,
|
||||
true);
|
||||
return;
|
||||
|
@ -586,7 +594,7 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
|
|||
|
||||
return_to_gossipd:
|
||||
/* Otherwise, we hand back to gossipd, to continue. */
|
||||
msg = towire_gossipctl_handle_peer(msg, &id, &cs,
|
||||
msg = towire_gossipctl_handle_peer(msg, &id, &addr, &cs,
|
||||
gfeatures, lfeatures, NULL);
|
||||
subd_send_msg(ld->gossip, take(msg));
|
||||
subd_send_fd(ld->gossip, peer_fd);
|
||||
|
@ -599,7 +607,7 @@ return_to_gossipd:
|
|||
send_error:
|
||||
/* Hand back to gossipd, with an error packet. */
|
||||
connect_failed(ld, &id, sanitize_error(msg, error, NULL));
|
||||
msg = towire_gossipctl_handle_peer(msg, &id, &cs,
|
||||
msg = towire_gossipctl_handle_peer(msg, &id, &addr, &cs,
|
||||
gfeatures, lfeatures, error);
|
||||
subd_send_msg(ld->gossip, take(msg));
|
||||
subd_send_fd(ld->gossip, peer_fd);
|
||||
|
@ -608,6 +616,7 @@ send_error:
|
|||
|
||||
void peer_sent_nongossip(struct lightningd *ld,
|
||||
const struct pubkey *id,
|
||||
const struct ipaddr *addr,
|
||||
const struct crypto_state *cs,
|
||||
const u8 *gfeatures,
|
||||
const u8 *lfeatures,
|
||||
|
@ -636,7 +645,7 @@ void peer_sent_nongossip(struct lightningd *ld,
|
|||
|
||||
/* Open request? */
|
||||
if (fromwire_peektype(in_msg) == WIRE_OPEN_CHANNEL) {
|
||||
peer_accept_channel(ld, id, cs, gfeatures, lfeatures,
|
||||
peer_accept_channel(ld, id, addr, cs, gfeatures, lfeatures,
|
||||
peer_fd, gossip_fd, in_msg);
|
||||
return;
|
||||
}
|
||||
|
@ -649,7 +658,7 @@ void peer_sent_nongossip(struct lightningd *ld,
|
|||
send_error:
|
||||
/* Hand back to gossipd, with an error packet. */
|
||||
connect_failed(ld, id, sanitize_error(error, error, NULL));
|
||||
msg = towire_gossipctl_handle_peer(error, id, cs,
|
||||
msg = towire_gossipctl_handle_peer(error, id, addr, cs,
|
||||
gfeatures, lfeatures, error);
|
||||
subd_send_msg(ld->gossip, take(msg));
|
||||
subd_send_fd(ld->gossip, peer_fd);
|
||||
|
@ -2204,6 +2213,7 @@ static void opening_fundee_finished(struct subd *opening,
|
|||
/* Peer has spontaneously exited from gossip due to open msg */
|
||||
static void peer_accept_channel(struct lightningd *ld,
|
||||
const struct pubkey *peer_id,
|
||||
const struct ipaddr *addr,
|
||||
const struct crypto_state *cs,
|
||||
const u8 *gfeatures, const u8 *lfeatures,
|
||||
int peer_fd, int gossip_fd,
|
||||
|
@ -2218,7 +2228,7 @@ static void peer_accept_channel(struct lightningd *ld,
|
|||
assert(fromwire_peektype(open_msg) == WIRE_OPEN_CHANNEL);
|
||||
|
||||
/* We make a new peer. */
|
||||
peer = new_peer(ld, peer_id, gfeatures, lfeatures, peer_fd);
|
||||
peer = new_peer(ld, peer_id, addr, gfeatures, lfeatures, peer_fd);
|
||||
|
||||
/* FIXME: Only happens due to netaddr fail. */
|
||||
if (!peer) {
|
||||
|
@ -2279,7 +2289,7 @@ static void peer_accept_channel(struct lightningd *ld,
|
|||
|
||||
peer_to_gossipd:
|
||||
/* Return to gossipd, with optional error msg to send. */
|
||||
msg = towire_gossipctl_handle_peer(ld, peer_id, cs,
|
||||
msg = towire_gossipctl_handle_peer(ld, peer_id, addr, cs,
|
||||
gfeatures, lfeatures, errmsg);
|
||||
subd_send_msg(ld->gossip, take(msg));
|
||||
subd_send_fd(ld->gossip, peer_fd);
|
||||
|
@ -2290,6 +2300,7 @@ peer_to_gossipd:
|
|||
|
||||
static void peer_offer_channel(struct lightningd *ld,
|
||||
struct funding_channel *fc,
|
||||
const struct ipaddr *addr,
|
||||
const struct crypto_state *cs,
|
||||
const u8 *gfeatures, const u8 *lfeatures,
|
||||
int peer_fd, int gossip_fd)
|
||||
|
@ -2300,7 +2311,8 @@ static void peer_offer_channel(struct lightningd *ld,
|
|||
struct utxo *utxos;
|
||||
|
||||
/* We make a new peer. */
|
||||
fc->peer = new_peer(ld, &fc->peerid, gfeatures, lfeatures, peer_fd);
|
||||
fc->peer = new_peer(ld, &fc->peerid, addr,
|
||||
gfeatures, lfeatures, peer_fd);
|
||||
|
||||
/* FIXME: Only happens due to netaddr fail. */
|
||||
if (!fc->peer) {
|
||||
|
@ -2389,11 +2401,12 @@ static void gossip_peer_released(struct subd *gossip,
|
|||
struct lightningd *ld = gossip->ld;
|
||||
struct crypto_state cs;
|
||||
u8 *gfeatures, *lfeatures;
|
||||
struct ipaddr addr;
|
||||
|
||||
/* We could have raced with peer doing something else. */
|
||||
fc->peer = peer_by_id(ld, &fc->peerid);
|
||||
|
||||
if (!fromwire_gossipctl_release_peer_reply(fc, resp, NULL, &cs,
|
||||
if (!fromwire_gossipctl_release_peer_reply(fc, resp, NULL, &addr, &cs,
|
||||
&gfeatures, &lfeatures)) {
|
||||
if (!fromwire_gossipctl_release_peer_replyfail(resp, NULL)) {
|
||||
fatal("Gossip daemon gave invalid reply %s",
|
||||
|
@ -2419,7 +2432,8 @@ static void gossip_peer_released(struct subd *gossip,
|
|||
}
|
||||
|
||||
/* OK, offer peer a channel. */
|
||||
peer_offer_channel(ld, fc, &cs, gfeatures, lfeatures, fds[0], fds[1]);
|
||||
peer_offer_channel(ld, fc, &addr, &cs, gfeatures, lfeatures,
|
||||
fds[0], fds[1]);
|
||||
}
|
||||
|
||||
static void json_fund_channel(struct command *cmd,
|
||||
|
|
|
@ -56,6 +56,7 @@ struct peer {
|
|||
|
||||
/* Where we connected to, or it connected from. */
|
||||
struct netaddr netaddr;
|
||||
struct ipaddr addr;
|
||||
|
||||
/* Our channel config. */
|
||||
struct channel_config our_config;
|
||||
|
@ -168,6 +169,7 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
|
|||
|
||||
void peer_sent_nongossip(struct lightningd *ld,
|
||||
const struct pubkey *id,
|
||||
const struct ipaddr *addr,
|
||||
const struct crypto_state *cs,
|
||||
const u8 *gfeatures,
|
||||
const u8 *lfeatures,
|
||||
|
|
Loading…
Add table
Reference in a new issue