-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathdns.go
More file actions
43 lines (36 loc) · 1.33 KB
/
dns.go
File metadata and controls
43 lines (36 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package node
import (
"math"
"net"
"time"
"github.com/ipfs/boxo/gateway"
config "github.com/ipfs/kubo/config"
"github.com/ipfs/kubo/core/node/libp2p"
doh "github.com/libp2p/go-doh-resolver"
madns "github.com/multiformats/go-multiaddr-dns"
"go.uber.org/fx"
)
func DNSResolver(cfg *config.Config) (*madns.Resolver, error) {
var dohOpts []doh.Option
if !cfg.DNS.MaxCacheTTL.IsDefault() {
dohOpts = append(dohOpts, doh.WithMaxCacheTTL(cfg.DNS.MaxCacheTTL.WithDefault(time.Duration(math.MaxUint32)*time.Second)))
}
// Replace "auto" DNS resolver placeholders with autoconf values
resolvers := cfg.DNSResolversWithAutoConf()
return gateway.NewDNSResolver(resolvers, dohOpts...)
}
// OverrideDefaultResolver replaces net.DefaultResolver with one that uses
// the provided madns.Resolver. This ensures all Go code in the daemon
// (including third-party libraries like p2p-forge/client) respects the
// DNS.Resolvers configuration.
func OverrideDefaultResolver(resolver *madns.Resolver) {
net.DefaultResolver = libp2p.NewNetResolverFromMadns(resolver)
}
// maybeOverrideDefaultResolver returns an fx.Option that conditionally
// invokes OverrideDefaultResolver based on the DNS.OverrideSystem config flag.
func maybeOverrideDefaultResolver(enabled bool) fx.Option {
if enabled {
return fx.Invoke(OverrideDefaultResolver)
}
return fx.Options()
}