Skip to content

Commit 0a94f3b

Browse files
committed
connectd: remove DNS seed lookups.
DNS seeds have been down/offline for a while, and this code (which blocks!) has been a source of trouble. We should probably use a canned set of "known nodes" if we want to bootstrap. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Changed: Protocol: we no longer use DNS seeds for peer lookup fallbacks. Fixes: #7913
1 parent c779abd commit 0a94f3b

File tree

5 files changed

+8
-98
lines changed

5 files changed

+8
-98
lines changed

connectd/connectd.c

+6-90
Original file line numberDiff line numberDiff line change
@@ -78,52 +78,12 @@ static void try_connect_one_addr(struct connecting *connect);
7878
* timer to call a higher function again, so has to be pre-declared. */
7979
static void try_connect_peer(struct daemon *daemon,
8080
const struct node_id *id,
81-
struct wireaddr_internal *addrs TAKES,
82-
bool dns_fallback);
81+
struct wireaddr_internal *addrs TAKES);
8382

8483
/* We track peers which are important, and try to reconnect (with backoff) */
8584
static void schedule_reconnect_if_important(struct daemon *daemon,
8685
const struct node_id *id);
8786

88-
/*~ Some ISP resolvers will reply with a dummy IP to queries that would otherwise
89-
* result in an NXDOMAIN reply. This just checks whether we have one such
90-
* resolver upstream and remembers its reply so we can try to filter future
91-
* dummies out.
92-
*/
93-
static bool broken_resolver(struct daemon *daemon)
94-
{
95-
struct addrinfo *addrinfo;
96-
struct addrinfo hints;
97-
const char *hostname = "nxdomain-test.doesntexist";
98-
int err;
99-
100-
/* If they told us to never do DNS queries, don't even do this one and
101-
* also not if we just say that we don't */
102-
if (!daemon->use_dns || daemon->always_use_proxy) {
103-
daemon->broken_resolver_response = NULL;
104-
return false;
105-
}
106-
107-
memset(&hints, 0, sizeof(hints));
108-
hints.ai_family = AF_UNSPEC;
109-
hints.ai_socktype = SOCK_STREAM;
110-
hints.ai_protocol = 0;
111-
hints.ai_flags = AI_ADDRCONFIG;
112-
err = getaddrinfo(hostname, tal_fmt(tmpctx, "%d", 42),
113-
&hints, &addrinfo);
114-
115-
/*~ Note the use of tal_dup here: it is a memdup for tal, but it's
116-
* type-aware so it's less error-prone. */
117-
if (err == 0) {
118-
daemon->broken_resolver_response
119-
= tal_dup(daemon, struct sockaddr, addrinfo->ai_addr);
120-
freeaddrinfo(addrinfo);
121-
} else
122-
daemon->broken_resolver_response = NULL;
123-
124-
return daemon->broken_resolver_response != NULL;
125-
}
126-
12787
/*~ Here we see our first tal destructor: in this case the 'struct connect'
12888
* simply removes itself from the table of all 'connecting' structs. */
12989
static void destroy_connecting(struct connecting *connect)
@@ -797,7 +757,7 @@ static void reconnect(struct important_id *imp)
797757
append_gossmap_addresses(&addrs, imp->daemon, &imp->id);
798758

799759
imp->reconnect_timer = NULL;
800-
try_connect_peer(imp->daemon, &imp->id, take(addrs), false);
760+
try_connect_peer(imp->daemon, &imp->id, take(addrs));
801761
}
802762

803763
static void schedule_reconnect_if_important(struct daemon *daemon,
@@ -1656,11 +1616,6 @@ static void connect_init(struct daemon *daemon, const u8 *msg)
16561616
} else
16571617
daemon->proxyaddr = NULL;
16581618

1659-
if (broken_resolver(daemon)) {
1660-
status_debug("Broken DNS resolver detected, will check for "
1661-
"dummy replies");
1662-
}
1663-
16641619
/* Figure out our addresses. */
16651620
daemon->listen_fds = setup_listeners(daemon, daemon,
16661621
proposed_wireaddr,
@@ -1798,39 +1753,6 @@ static const char **seednames(const tal_t *ctx, const struct node_id *id)
17981753
return seednames;
17991754
}
18001755

1801-
/*~ As a last resort, we do a DNS lookup to the lightning DNS seed to
1802-
* resolve a node name when they say to connect to it. This is synchronous,
1803-
* so connectd blocks, but it's not very common so we haven't fixed it.
1804-
*
1805-
* This "seed by DNS" approach is similar to what bitcoind uses, and in fact
1806-
* has the nice property that DNS is cached, and the seed only sees a request
1807-
* from the ISP, not directly from the user. */
1808-
static void add_seed_addrs(struct wireaddr_internal **addrs,
1809-
const struct node_id *id,
1810-
struct sockaddr *broken_reply)
1811-
{
1812-
struct wireaddr *new_addrs;
1813-
const char **hostnames = seednames(tmpctx, id);
1814-
1815-
for (size_t i = 0; i < tal_count(hostnames); i++) {
1816-
status_peer_debug(id, "Resolving %s", hostnames[i]);
1817-
new_addrs = wireaddr_from_hostname(tmpctx, hostnames[i], chainparams_get_ln_port(chainparams),
1818-
NULL, broken_reply, NULL);
1819-
if (new_addrs) {
1820-
for (size_t j = 0; j < tal_count(new_addrs); j++) {
1821-
if (new_addrs[j].type == ADDR_TYPE_DNS)
1822-
continue;
1823-
status_peer_debug(id, "Resolved %s to %s", hostnames[i],
1824-
fmt_wireaddr(tmpctx, &new_addrs[j]));
1825-
append_addr(addrs, &new_addrs[j]);
1826-
}
1827-
/* Other seeds will likely have the same information. */
1828-
return;
1829-
} else
1830-
status_peer_debug(id, "Could not resolve %s", hostnames[i]);
1831-
}
1832-
}
1833-
18341756
static bool addr_in(const struct wireaddr_internal *needle,
18351757
const struct wireaddr_internal haystack[])
18361758
{
@@ -1844,8 +1766,7 @@ static bool addr_in(const struct wireaddr_internal *needle,
18441766
/*~ Try to connect to a single peer, given some addresses (in order) */
18451767
static void try_connect_peer(struct daemon *daemon,
18461768
const struct node_id *id,
1847-
struct wireaddr_internal *addrs TAKES,
1848-
bool dns_fallback)
1769+
struct wireaddr_internal *addrs TAKES)
18491770
{
18501771
bool use_proxy = daemon->always_use_proxy;
18511772
struct connecting *connect;
@@ -1886,14 +1807,11 @@ static void try_connect_peer(struct daemon *daemon,
18861807
chainparams_get_ln_port(chainparams));
18871808
tal_arr_expand(&addrs, unresolved);
18881809
}
1889-
} else if (daemon->use_dns && dns_fallback) {
1890-
add_seed_addrs(&addrs, id,
1891-
daemon->broken_resolver_response);
18921810
}
18931811
}
18941812

1895-
/* Still no address? Fail immediately. Lightningd can still choose
1896-
* to retry; an address may get gossiped or appear on the DNS seed. */
1813+
/* Still no address? Fail immediately. Important ones get
1814+
* retried; an address may get gossiped. */
18971815
if (tal_count(addrs) == 0) {
18981816
connect_failed(daemon, id,
18991817
CONNECT_NO_KNOWN_ADDRESS,
@@ -1937,13 +1855,11 @@ static void connect_to_peer(struct daemon *daemon, const u8 *msg)
19371855
{
19381856
struct node_id id;
19391857
struct wireaddr_internal *addrs;
1940-
bool dns_fallback;
19411858
bool transient;
19421859
struct important_id *imp;
19431860

19441861
if (!fromwire_connectd_connect_to_peer(tmpctx, msg,
19451862
&id, &addrs,
1946-
&dns_fallback,
19471863
&transient))
19481864
master_badmsg(WIRE_CONNECTD_CONNECT_TO_PEER, msg);
19491865

@@ -1983,7 +1899,7 @@ static void connect_to_peer(struct daemon *daemon, const u8 *msg)
19831899
/* Do gossmap lookup to find any addresses from there, and append. */
19841900
append_gossmap_addresses(&addrs, daemon, &id);
19851901

1986-
try_connect_peer(daemon, &id, addrs, dns_fallback);
1902+
try_connect_peer(daemon, &id, addrs);
19871903
}
19881904

19891905
/* lightningd tells us a peer should be disconnected. */

connectd/connectd.h

-4
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,6 @@ struct daemon {
296296
* resort, but doing so leaks our address so can be disabled. */
297297
bool use_dns;
298298

299-
/* The address that the broken response returns instead of
300-
* NXDOMAIN. NULL if we have not detected a broken resolver. */
301-
struct sockaddr *broken_resolver_response;
302-
303299
/* File descriptors to listen on once we're activated. */
304300
const struct listen_fd **listen_fds;
305301

connectd/connectd_wire.csv

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ msgtype,connectd_connect_to_peer,2001
6565
msgdata,connectd_connect_to_peer,id,node_id,
6666
msgdata,connectd_connect_to_peer,len,u32,
6767
msgdata,connectd_connect_to_peer,addrs,wireaddr_internal,len
68-
msgdata,connectd_connect_to_peer,dns_fallback,bool,
6968
msgdata,connectd_connect_to_peer,transient,bool,
7069

7170
# Connectd->master: connect failed.

lightningd/connect_control.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ static struct command_result *json_connect(struct command *cmd,
237237
}
238238

239239
subd_send_msg(cmd->ld->connectd,
240-
take(towire_connectd_connect_to_peer(NULL, &id_addr.id, addr, true, true)));
240+
take(towire_connectd_connect_to_peer(NULL, &id_addr.id, addr, true)));
241241

242242
/* Leave this here for peer_connected, connect_failed or peer_disconnect_done. */
243243
new_connect(cmd->ld, &id_addr.id, cmd);
@@ -436,7 +436,7 @@ void connectd_connect_to_peer(struct lightningd *ld,
436436
}
437437
subd_send_msg(peer->ld->connectd,
438438
take(towire_connectd_connect_to_peer(NULL, &peer->id,
439-
waddr, true,
439+
waddr,
440440
!is_important)));
441441
}
442442

lightningd/gossip_control.c

-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ static void handle_connect_to_peer(struct subd *gossip, const u8 *msg)
188188
connectmsg = towire_connectd_connect_to_peer(NULL,
189189
&id,
190190
NULL, //addrhint,
191-
false, //dns_fallback
192191
true); //transient
193192
subd_send_msg(gossip->ld->connectd, take(connectmsg));
194193
}

0 commit comments

Comments
 (0)