From b84804009adc110f635f8486707a4572b2cb64eb Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 23 Apr 2018 16:36:16 +0200 Subject: [PATCH] gossip: Use the DNS seeds to look up nodes if we don't have an addr Signed-off-by: Christian Decker --- gossipd/gossip.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/gossipd/gossip.c b/gossipd/gossip.c index be4fa587d..d795da262 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include #include @@ -1630,6 +1632,32 @@ static struct io_plan *conn_init(struct io_conn *conn, struct reaching *reach) return io_connect(conn, &ai, connection_out, reach); } +static struct addrhint * +seed_resolve_addr(const tal_t *ctx, const struct pubkey *id, const u16 port) +{ + struct addrhint *a; + char bech32[100], *addr; + u8 der[PUBKEY_DER_LEN]; + u5 *data = tal_arr(ctx, u5, 0); + + pubkey_to_der(der, id); + bech32_push_bits(&data, der, PUBKEY_DER_LEN*8); + bech32_encode(bech32, "ln", data, tal_count(data), sizeof(bech32)); + addr = tal_fmt(ctx, "%s.lseed.bitcoinstats.com", bech32); + + status_trace("Resolving %s", addr); + + a = tal(ctx, struct addrhint); + if (!wireaddr_from_hostname(&a->addr, addr, port, NULL)) { + status_trace("Could not resolve %s", addr); + return tal_free(a); + } else { + status_trace("Resolved %s to %s", addr, + type_to_string(ctx, struct wireaddr, &a->addr)); + return a; + } +} + static void try_connect(struct reaching *reach) { struct addrhint *a; @@ -1644,8 +1672,11 @@ static void try_connect(struct reaching *reach) } a = find_addrhint(reach->daemon, &reach->id); + + if (!a) + a = seed_resolve_addr(reach, &reach->id, 9735); + if (!a) { - /* FIXME: now try node table, dns lookups... */ status_info("No address known for %s, giving up", type_to_string(tmpctx, struct pubkey, &reach->id)); daemon_conn_send(