mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
gossipd: provide connectd with address resolution.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -1505,8 +1505,31 @@ seed_resolve_addr(const tal_t *ctx, const struct pubkey *id,
|
|||||||
static struct wireaddr_internal *
|
static struct wireaddr_internal *
|
||||||
gossip_resolve_addr(const tal_t *ctx, const struct pubkey *id)
|
gossip_resolve_addr(const tal_t *ctx, const struct pubkey *id)
|
||||||
{
|
{
|
||||||
/* FIXME: Ask gossipd! */
|
u8 *msg;
|
||||||
return NULL;
|
struct wireaddr *addrs;
|
||||||
|
struct wireaddr_internal *addr;
|
||||||
|
|
||||||
|
msg = towire_gossip_get_addrs(NULL, id);
|
||||||
|
if (!wire_sync_write(GOSSIPCTL_FD, take(msg)))
|
||||||
|
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||||
|
"Failed writing to gossipctl: %s",
|
||||||
|
strerror(errno));
|
||||||
|
|
||||||
|
msg = wire_sync_read(tmpctx, GOSSIPCTL_FD);
|
||||||
|
if (!fromwire_gossip_get_addrs_reply(tmpctx, msg, &addrs))
|
||||||
|
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||||
|
"Failed parsing get_addrs_reply gossipctl: %s",
|
||||||
|
tal_hex(tmpctx, msg));
|
||||||
|
|
||||||
|
if (!addrs)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
/* FIXME: Don't just take first address! */
|
||||||
|
addr = tal(ctx, struct wireaddr_internal);
|
||||||
|
addr->itype = ADDR_INTERNAL_WIREADDR;
|
||||||
|
addr->u.wireaddr = addrs[0];
|
||||||
|
|
||||||
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void try_reach_peer(struct daemon *daemon, const struct pubkey *id,
|
static void try_reach_peer(struct daemon *daemon, const struct pubkey *id,
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include <common/wireaddr.h>
|
||||||
|
|
||||||
# Communication between gossipd and connectd.
|
# Communication between gossipd and connectd.
|
||||||
gossip_new_peer,4000
|
gossip_new_peer,4000
|
||||||
gossip_new_peer,,id,struct pubkey
|
gossip_new_peer,,id,struct pubkey
|
||||||
@@ -9,3 +11,11 @@ gossip_new_peer,,initial_routing_sync,bool
|
|||||||
# if success: + fd.
|
# if success: + fd.
|
||||||
gossip_new_peer_reply,4100
|
gossip_new_peer_reply,4100
|
||||||
gossip_new_peer_reply,,success,bool
|
gossip_new_peer_reply,,success,bool
|
||||||
|
|
||||||
|
# Connectd asks gossipd for any known addresses for that node.
|
||||||
|
gossip_get_addrs,4001
|
||||||
|
gossip_get_addrs,,id,struct pubkey
|
||||||
|
|
||||||
|
gossip_get_addrs_reply,4101
|
||||||
|
gossip_get_addrs_reply,,num,u16
|
||||||
|
gossip_get_addrs_reply,,addrs,num*struct wireaddr
|
||||||
|
|||||||
|
@@ -2164,6 +2164,31 @@ static struct io_plan *recv_req(struct io_conn *conn, struct daemon_conn *master
|
|||||||
t, tal_hex(tmpctx, master->msg_in));
|
t, tal_hex(tmpctx, master->msg_in));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct io_plan *connectd_get_address(struct io_conn *conn,
|
||||||
|
struct daemon *daemon,
|
||||||
|
const u8 *msg)
|
||||||
|
{
|
||||||
|
struct pubkey id;
|
||||||
|
struct node *node;
|
||||||
|
const struct wireaddr *addrs;
|
||||||
|
|
||||||
|
if (!fromwire_gossip_get_addrs(msg, &id)) {
|
||||||
|
status_broken("Bad gossip_get_addrs msg from connectd: %s",
|
||||||
|
tal_hex(tmpctx, msg));
|
||||||
|
return io_close(conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
node = get_node(daemon->rstate, &id);
|
||||||
|
if (node)
|
||||||
|
addrs = node->addresses;
|
||||||
|
else
|
||||||
|
addrs = NULL;
|
||||||
|
|
||||||
|
daemon_conn_send(&daemon->connectd,
|
||||||
|
take(towire_gossip_get_addrs_reply(NULL, addrs)));
|
||||||
|
return daemon_conn_read_next(conn, &daemon->connectd);
|
||||||
|
}
|
||||||
|
|
||||||
static struct io_plan *connectd_req(struct io_conn *conn,
|
static struct io_plan *connectd_req(struct io_conn *conn,
|
||||||
struct daemon_conn *connectd)
|
struct daemon_conn *connectd)
|
||||||
{
|
{
|
||||||
@@ -2174,8 +2199,12 @@ static struct io_plan *connectd_req(struct io_conn *conn,
|
|||||||
case WIRE_GOSSIP_NEW_PEER:
|
case WIRE_GOSSIP_NEW_PEER:
|
||||||
return connectd_new_peer(conn, daemon, connectd->msg_in);
|
return connectd_new_peer(conn, daemon, connectd->msg_in);
|
||||||
|
|
||||||
/* We send this, don't receive it. */
|
case WIRE_GOSSIP_GET_ADDRS:
|
||||||
|
return connectd_get_address(conn, daemon, connectd->msg_in);
|
||||||
|
|
||||||
|
/* We send these, don't receive them. */
|
||||||
case WIRE_GOSSIP_NEW_PEER_REPLY:
|
case WIRE_GOSSIP_NEW_PEER_REPLY:
|
||||||
|
case WIRE_GOSSIP_GET_ADDRS_REPLY:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -695,7 +695,6 @@ class LightningDTests(BaseLightningDTests):
|
|||||||
l1.rpc.connect, '032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e', 'localhost', l2.port)
|
l1.rpc.connect, '032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e', 'localhost', l2.port)
|
||||||
|
|
||||||
@unittest.skipIf(not DEVELOPER, "needs --dev-allow-localhost")
|
@unittest.skipIf(not DEVELOPER, "needs --dev-allow-localhost")
|
||||||
@unittest.skip("FIXME: Re-enable once gossipd gives out addresses to connectd")
|
|
||||||
def test_connect_by_gossip(self):
|
def test_connect_by_gossip(self):
|
||||||
"""Test connecting to an unknown peer using node gossip
|
"""Test connecting to an unknown peer using node gossip
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user