feat: support multiple DNS discovery URLs (#309)

This commit is contained in:
Richard Ramos 2022-09-14 15:19:11 -04:00 committed by GitHub
parent 8d42febe18
commit c39c4d535c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 14 deletions

View File

@ -354,10 +354,10 @@ func main() {
Usage: "Enable DNS discovery",
Destination: &options.DNSDiscovery.Enable,
},
&cli.StringFlag{
&cli.StringSliceFlag{
Name: "dns-discovery-url",
Usage: "URL for DNS node list in format 'enrtree://<key>@<fqdn>'",
Destination: &options.DNSDiscovery.URL,
Destination: &options.DNSDiscovery.URLs,
},
&cli.StringFlag{
Name: "dns-discovery-name-server",

View File

@ -226,18 +226,20 @@ func Execute(options Options) {
var discoveredNodes []dnsdisc.DiscoveredNode
if options.DNSDiscovery.Enable {
if options.DNSDiscovery.URL != "" {
logger.Info("attempting DNS discovery with ", zap.String("URL", options.DNSDiscovery.URL))
nodes, err := dnsdisc.RetrieveNodes(ctx, options.DNSDiscovery.URL, dnsdisc.WithNameserver(options.DNSDiscovery.Nameserver))
if err != nil {
logger.Warn("dns discovery error ", zap.Error(err))
} else {
var discAddresses []multiaddr.Multiaddr
for _, n := range nodes {
discAddresses = append(discAddresses, n.Addresses...)
if len(options.DNSDiscovery.URLs.Value()) != 0 {
for _, url := range options.DNSDiscovery.URLs.Value() {
logger.Info("attempting DNS discovery with ", zap.String("URL", url))
nodes, err := dnsdisc.RetrieveNodes(ctx, url, dnsdisc.WithNameserver(options.DNSDiscovery.Nameserver))
if err != nil {
logger.Warn("dns discovery error ", zap.Error(err))
} else {
var discAddresses []multiaddr.Multiaddr
for _, n := range nodes {
discAddresses = append(discAddresses, n.Addresses...)
}
logger.Info("found dns entries ", logging.MultiAddrs("nodes", discAddresses...))
discoveredNodes = nodes
}
logger.Info("found dns entries ", logging.MultiAddrs("nodes", discAddresses...))
discoveredNodes = nodes
}
} else {
logger.Fatal("DNS discovery URL is required")

View File

@ -103,7 +103,7 @@ type SwapOptions struct {
// information for nodes. It's very useful for bootstrapping a p2p network.
type DNSDiscoveryOptions struct {
Enable bool
URL string
URLs cli.StringSlice
Nameserver string
}