-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
18 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...) | ||
} |