Skip to content

Commit

Permalink
create custom resolvers from config
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Apr 12, 2021
1 parent 7d23b5c commit 40cbf8b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions core/node/dns.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
package node

import (
"fmt"
"strings"

config "github.com/ipfs/go-ipfs-config"
doh "github.com/libp2p/go-doh-resolver"
madns "github.com/multiformats/go-multiaddr-dns"
)

func DNSResolver(cfg *config.Config) (*madns.Resolver, error) {
// TODO custom resolvers from config
return madns.DefaultResolver, nil
var opts []madns.Option
if url := cfg.DNS.DefaultResolver; url != "" {
if !strings.HasPrefix(url, "https://") {
return nil, fmt.Errorf("invalid default resolver url: %s", url)
}
opts = append(opts, madns.WithDefaultResolver(doh.NewResolver(url)))
}
for domain, url := range cfg.DNS.CustomResolvers {
if !strings.HasPrefix(url, "https://") {
return nil, fmt.Errorf("invalid domain resolver url for %s: %s", domain, url)
}
opts = append(opts, madns.WithDomainResolver(domain, doh.NewResolver(url)))
}
return madns.NewResolver(opts...)
}

0 comments on commit 40cbf8b

Please sign in to comment.