gossipd: don't use fake addrhint for non-addrhint resolutions.

Use a wireaddr_internal directly (which is what we want).

Also, don't hardcode 9735, use DEFAULT_PORT internally in
seed_resolve_addr().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-05-10 12:34:59 +09:30
parent de063edb54
commit 570283bc76

View File

@ -1960,31 +1960,31 @@ static const char *seedname(const tal_t *ctx, const struct pubkey *id)
return tal_fmt(ctx, "%s.lseed.bitcoinstats.com", bech32); return tal_fmt(ctx, "%s.lseed.bitcoinstats.com", bech32);
} }
static struct addrhint * static struct wireaddr_internal *
seed_resolve_addr(const tal_t *ctx, const struct pubkey *id, const u16 port) seed_resolve_addr(const tal_t *ctx, const struct pubkey *id)
{ {
struct addrhint *a; struct wireaddr_internal *a;
const char *addr; const char *addr;
addr = seedname(tmpctx, id); addr = seedname(tmpctx, id);
status_trace("Resolving %s", addr); status_trace("Resolving %s", addr);
a = tal(ctx, struct addrhint); a = tal(ctx, struct wireaddr_internal);
a->addr.itype = ADDR_INTERNAL_WIREADDR; a->itype = ADDR_INTERNAL_WIREADDR;
if (!wireaddr_from_hostname(&a->addr.u.wireaddr, addr, port, NULL, if (!wireaddr_from_hostname(&a->u.wireaddr, addr, DEFAULT_PORT, NULL,
NULL)) { NULL)) {
status_trace("Could not resolve %s", addr); status_trace("Could not resolve %s", addr);
return tal_free(a); return tal_free(a);
} else { } else {
status_trace("Resolved %s to %s", addr, status_trace("Resolved %s to %s", addr,
type_to_string(ctx, struct wireaddr, type_to_string(ctx, struct wireaddr,
&a->addr.u.wireaddr)); &a->u.wireaddr));
return a; return a;
} }
} }
/* Resolve using gossiped wireaddr stored in routemap. */ /* Resolve using gossiped wireaddr stored in routemap. */
static struct addrhint * static struct wireaddr_internal *
gossip_resolve_addr(const tal_t *ctx, gossip_resolve_addr(const tal_t *ctx,
struct routing_state *rstate, struct routing_state *rstate,
const struct pubkey *id) const struct pubkey *id)
@ -2001,15 +2001,15 @@ gossip_resolve_addr(const tal_t *ctx,
/* FIXME: When struct addrhint can contain more than one address, /* FIXME: When struct addrhint can contain more than one address,
* we should copy all routable addresses. */ * we should copy all routable addresses. */
for (size_t i = 0; i < tal_count(node->addresses); i++) { for (size_t i = 0; i < tal_count(node->addresses); i++) {
struct addrhint *a; struct wireaddr_internal *a;
if (!address_routable(&node->addresses[i], if (!address_routable(&node->addresses[i],
rstate->dev_allow_localhost)) rstate->dev_allow_localhost))
continue; continue;
a = tal(ctx, struct addrhint); a = tal(ctx, struct wireaddr_internal);
a->addr.itype = ADDR_INTERNAL_WIREADDR; a->itype = ADDR_INTERNAL_WIREADDR;
a->addr.u.wireaddr = node->addresses[i]; a->u.wireaddr = node->addresses[i];
return a; return a;
} }
@ -2019,7 +2019,8 @@ gossip_resolve_addr(const tal_t *ctx,
static void try_reach_peer(struct daemon *daemon, const struct pubkey *id, static void try_reach_peer(struct daemon *daemon, const struct pubkey *id,
bool master_needs_response) bool master_needs_response)
{ {
struct addrhint *a; struct wireaddr_internal *a;
struct addrhint *hint;
int fd, af; int fd, af;
struct reaching *reach; struct reaching *reach;
u8 *msg; u8 *msg;
@ -2051,7 +2052,11 @@ static void try_reach_peer(struct daemon *daemon, const struct pubkey *id,
return; return;
} }
a = find_addrhint(daemon, id); hint = find_addrhint(daemon, id);
if (hint)
a = &hint->addr;
else
a = NULL;
if (!a) if (!a)
a = gossip_resolve_addr(tmpctx, a = gossip_resolve_addr(tmpctx,
@ -2059,7 +2064,7 @@ static void try_reach_peer(struct daemon *daemon, const struct pubkey *id,
id); id);
if (!a && !daemon->use_proxy_always) if (!a && !daemon->use_proxy_always)
a = seed_resolve_addr(tmpctx, id, 9735); a = seed_resolve_addr(tmpctx, id);
if (!a) { if (!a) {
status_debug("No address known for %s, giving up", status_debug("No address known for %s, giving up",
@ -2077,7 +2082,7 @@ static void try_reach_peer(struct daemon *daemon, const struct pubkey *id,
af = -1; af = -1;
use_proxy = daemon->use_proxy_always; use_proxy = daemon->use_proxy_always;
switch (a->addr.itype) { switch (a->itype) {
case ADDR_INTERNAL_SOCKNAME: case ADDR_INTERNAL_SOCKNAME:
af = AF_LOCAL; af = AF_LOCAL;
/* Local sockets don't use tor proxy */ /* Local sockets don't use tor proxy */
@ -2090,7 +2095,7 @@ static void try_reach_peer(struct daemon *daemon, const struct pubkey *id,
status_failed(STATUS_FAIL_INTERNAL_ERROR, status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Can't reach AUTOTOR"); "Can't reach AUTOTOR");
case ADDR_INTERNAL_WIREADDR: case ADDR_INTERNAL_WIREADDR:
switch (a->addr.u.wireaddr.type) { switch (a->u.wireaddr.type) {
case ADDR_TYPE_TOR_V2: case ADDR_TYPE_TOR_V2:
case ADDR_TYPE_TOR_V3: case ADDR_TYPE_TOR_V3:
use_proxy = true; use_proxy = true;
@ -2140,7 +2145,7 @@ static void try_reach_peer(struct daemon *daemon, const struct pubkey *id,
reach = tal(daemon, struct reaching); reach = tal(daemon, struct reaching);
reach->daemon = daemon; reach->daemon = daemon;
reach->id = *id; reach->id = *id;
reach->addr = a->addr; reach->addr = *a;
reach->master_needs_response = master_needs_response; reach->master_needs_response = master_needs_response;
reach->connstate = "Connection establishment"; reach->connstate = "Connection establishment";
list_add_tail(&daemon->reaching, &reach->list); list_add_tail(&daemon->reaching, &reach->list);