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", Usage: "Enable DNS discovery",
Destination: &options.DNSDiscovery.Enable, Destination: &options.DNSDiscovery.Enable,
}, },
&cli.StringFlag{ &cli.StringSliceFlag{
Name: "dns-discovery-url", Name: "dns-discovery-url",
Usage: "URL for DNS node list in format 'enrtree://<key>@<fqdn>'", Usage: "URL for DNS node list in format 'enrtree://<key>@<fqdn>'",
Destination: &options.DNSDiscovery.URL, Destination: &options.DNSDiscovery.URLs,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "dns-discovery-name-server", Name: "dns-discovery-name-server",

View File

@ -226,18 +226,20 @@ func Execute(options Options) {
var discoveredNodes []dnsdisc.DiscoveredNode var discoveredNodes []dnsdisc.DiscoveredNode
if options.DNSDiscovery.Enable { if options.DNSDiscovery.Enable {
if options.DNSDiscovery.URL != "" { if len(options.DNSDiscovery.URLs.Value()) != 0 {
logger.Info("attempting DNS discovery with ", zap.String("URL", options.DNSDiscovery.URL)) for _, url := range options.DNSDiscovery.URLs.Value() {
nodes, err := dnsdisc.RetrieveNodes(ctx, options.DNSDiscovery.URL, dnsdisc.WithNameserver(options.DNSDiscovery.Nameserver)) logger.Info("attempting DNS discovery with ", zap.String("URL", url))
if err != nil { nodes, err := dnsdisc.RetrieveNodes(ctx, url, dnsdisc.WithNameserver(options.DNSDiscovery.Nameserver))
logger.Warn("dns discovery error ", zap.Error(err)) if err != nil {
} else { logger.Warn("dns discovery error ", zap.Error(err))
var discAddresses []multiaddr.Multiaddr } else {
for _, n := range nodes { var discAddresses []multiaddr.Multiaddr
discAddresses = append(discAddresses, n.Addresses...) 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 { } else {
logger.Fatal("DNS discovery URL is required") 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. // information for nodes. It's very useful for bootstrapping a p2p network.
type DNSDiscoveryOptions struct { type DNSDiscoveryOptions struct {
Enable bool Enable bool
URL string URLs cli.StringSlice
Nameserver string Nameserver string
} }