Browse Source

gossipd: provide connectd with address resolution.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
dba7f9002f
  1. 27
      connectd/connect.c
  2. 10
      connectd/connect_gossip_wire.csv
  3. 31
      gossipd/gossip.c
  4. 1
      tests/test_lightningd.py

27
connectd/connect.c

@ -1505,8 +1505,31 @@ seed_resolve_addr(const tal_t *ctx, const struct pubkey *id,
static struct wireaddr_internal *
gossip_resolve_addr(const tal_t *ctx, const struct pubkey *id)
{
/* FIXME: Ask gossipd! */
return NULL;
u8 *msg;
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,

10
connectd/connect_gossip_wire.csv

@ -1,3 +1,5 @@
#include <common/wireaddr.h>
# Communication between gossipd and connectd.
gossip_new_peer,4000
gossip_new_peer,,id,struct pubkey
@ -9,3 +11,11 @@ gossip_new_peer,,initial_routing_sync,bool
# if success: + fd.
gossip_new_peer_reply,4100
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

Can't render this file because it has a wrong number of fields in line 2.

31
gossipd/gossip.c

@ -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));
}
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,
struct daemon_conn *connectd)
{
@ -2174,8 +2199,12 @@ static struct io_plan *connectd_req(struct io_conn *conn,
case WIRE_GOSSIP_NEW_PEER:
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_GET_ADDRS_REPLY:
break;
}

1
tests/test_lightningd.py

@ -695,7 +695,6 @@ class LightningDTests(BaseLightningDTests):
l1.rpc.connect, '032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e', 'localhost', l2.port)
@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):
"""Test connecting to an unknown peer using node gossip
"""

Loading…
Cancel
Save