Skip to content

Commit 3c8e367

Browse files
debdutdebggazzo
andauthored
chore: allow using v4 over v6 for resolved dns results (#237)
Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz>
1 parent 5d5e8f5 commit 3c8e367

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/federation-sdk/src/server-discovery/_resolver.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import type { LookupAllOptions } from 'node:dns';
12
import { Resolver, lookup } from 'node:dns/promises';
23

34
// no caching, depends on system
45
class _Resolver extends Resolver {
6+
private lookupOrder: LookupAllOptions['order'] = 'ipv6first';
7+
58
constructor() {
69
super();
710

@@ -12,6 +15,18 @@ class _Resolver extends Resolver {
1215

1316
this.setServers(servers);
1417
}
18+
19+
// spec says v6 first, but there shouldn't be a case where a and aaaa records point to different services. if does, not an application problem.
20+
// for systems with no v6 support this still lets allow a fallback to v4 first. without needing to add system level dns filter.
21+
// as long as the name has an a record, should be able to communicate.
22+
const order = process.env.HOMESERVER_CONFIG_DNS_LOOKUP_ORDER;
23+
if (
24+
order === 'ipv4first' ||
25+
order === 'ipv6first' ||
26+
order === 'verbatim'
27+
) {
28+
this.lookupOrder = order;
29+
}
1530
}
1631

1732
// The implementation uses an operating system facility that can associate names with addresses and vice versa
@@ -20,7 +35,7 @@ class _Resolver extends Resolver {
2035
const result = await lookup(hostname, {
2136
all: true,
2237
family: 0,
23-
order: 'ipv6first',
38+
order: this.lookupOrder,
2439
});
2540

2641
return result.map((r) => r.address);

0 commit comments

Comments
 (0)