mirror of https://github.com/status-im/go-waku.git
feat: add dns discovery in lib (#884)
This commit is contained in:
parent
b6d9e3d4be
commit
73bcb2e78a
|
@ -19,12 +19,12 @@ import (
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
dbutils "github.com/waku-org/go-waku/waku/persistence/utils"
|
dbutils "github.com/waku-org/go-waku/waku/persistence/utils"
|
||||||
|
"github.com/waku-org/go-waku/waku/v2/dnsdisc"
|
||||||
wakupeerstore "github.com/waku-org/go-waku/waku/v2/peerstore"
|
wakupeerstore "github.com/waku-org/go-waku/waku/v2/peerstore"
|
||||||
"github.com/waku-org/go-waku/waku/v2/rendezvous"
|
"github.com/waku-org/go-waku/waku/v2/rendezvous"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
|
||||||
dssql "github.com/ipfs/go-ds-sql"
|
dssql "github.com/ipfs/go-ds-sql"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"go.uber.org/zap/zapcore"
|
"go.uber.org/zap/zapcore"
|
||||||
|
@ -44,7 +44,6 @@ import (
|
||||||
"github.com/waku-org/go-waku/logging"
|
"github.com/waku-org/go-waku/logging"
|
||||||
"github.com/waku-org/go-waku/waku/metrics"
|
"github.com/waku-org/go-waku/waku/metrics"
|
||||||
"github.com/waku-org/go-waku/waku/persistence"
|
"github.com/waku-org/go-waku/waku/persistence"
|
||||||
"github.com/waku-org/go-waku/waku/v2/dnsdisc"
|
|
||||||
"github.com/waku-org/go-waku/waku/v2/node"
|
"github.com/waku-org/go-waku/waku/v2/node"
|
||||||
wprotocol "github.com/waku-org/go-waku/waku/v2/protocol"
|
wprotocol "github.com/waku-org/go-waku/waku/v2/protocol"
|
||||||
"github.com/waku-org/go-waku/waku/v2/protocol/filter"
|
"github.com/waku-org/go-waku/waku/v2/protocol/filter"
|
||||||
|
@ -279,47 +278,6 @@ func Execute(options NodeOptions) error {
|
||||||
nodeOpts = append(nodeOpts, node.WithLightPush())
|
nodeOpts = append(nodeOpts, node.WithLightPush())
|
||||||
}
|
}
|
||||||
|
|
||||||
var discoveredNodes []dnsdisc.DiscoveredNode
|
|
||||||
if options.DNSDiscovery.Enable {
|
|
||||||
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 discPeerInfo []peer.AddrInfo
|
|
||||||
for _, n := range nodes {
|
|
||||||
discPeerInfo = append(discPeerInfo, n.PeerInfo)
|
|
||||||
}
|
|
||||||
logger.Info("found dns entries ", zap.Any("nodes", discPeerInfo))
|
|
||||||
discoveredNodes = append(discoveredNodes, nodes...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return nonRecoverErrorMsg("DNS discovery URL is required")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if options.DiscV5.Enable {
|
|
||||||
var bootnodes []*enode.Node
|
|
||||||
for _, addr := range options.DiscV5.Nodes.Value() {
|
|
||||||
bootnode, err := enode.Parse(enode.ValidSchemes, addr)
|
|
||||||
if err != nil {
|
|
||||||
logger.Fatal("parsing ENR", zap.Error(err))
|
|
||||||
}
|
|
||||||
bootnodes = append(bootnodes, bootnode)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, n := range discoveredNodes {
|
|
||||||
if n.ENR != nil {
|
|
||||||
bootnodes = append(bootnodes, n.ENR)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeOpts = append(nodeOpts, node.WithDiscoveryV5(options.DiscV5.Port, bootnodes, options.DiscV5.AutoUpdate))
|
|
||||||
}
|
|
||||||
|
|
||||||
if options.PeerExchange.Enable {
|
if options.PeerExchange.Enable {
|
||||||
nodeOpts = append(nodeOpts, node.WithPeerExchange())
|
nodeOpts = append(nodeOpts, node.WithPeerExchange())
|
||||||
}
|
}
|
||||||
|
@ -357,6 +315,21 @@ func Execute(options NodeOptions) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var discoveredNodes []dnsdisc.DiscoveredNode
|
||||||
|
if options.DNSDiscovery.Enable {
|
||||||
|
if len(options.DNSDiscovery.URLs.Value()) == 0 {
|
||||||
|
return nonRecoverErrorMsg("DNS discovery URL is required")
|
||||||
|
}
|
||||||
|
discoveredNodes = node.GetNodesFromDNSDiscovery(logger, ctx, options.DNSDiscovery.Nameserver, options.DNSDiscovery.URLs.Value())
|
||||||
|
}
|
||||||
|
if options.DiscV5.Enable {
|
||||||
|
discv5Opts, err := node.GetDiscv5Option(discoveredNodes, options.DiscV5.Nodes.Value(), options.DiscV5.Port, options.DiscV5.AutoUpdate)
|
||||||
|
if err != nil {
|
||||||
|
logger.Fatal("parsing ENR", zap.Error(err))
|
||||||
|
}
|
||||||
|
nodeOpts = append(nodeOpts, discv5Opts)
|
||||||
|
}
|
||||||
|
|
||||||
if err = wakuNode.Start(ctx); err != nil {
|
if err = wakuNode.Start(ctx); err != nil {
|
||||||
return nonRecoverError(err)
|
return nonRecoverError(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ require (
|
||||||
github.com/ethereum/go-ethereum v1.10.26
|
github.com/ethereum/go-ethereum v1.10.26
|
||||||
github.com/waku-org/go-waku v0.2.3-0.20221109195301-b2a5a68d28ba
|
github.com/waku-org/go-waku v0.2.3-0.20221109195301-b2a5a68d28ba
|
||||||
go.uber.org/zap v1.24.0
|
go.uber.org/zap v1.24.0
|
||||||
|
google.golang.org/protobuf v1.31.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
@ -123,8 +124,8 @@ require (
|
||||||
golang.org/x/sync v0.3.0 // indirect
|
golang.org/x/sync v0.3.0 // indirect
|
||||||
golang.org/x/sys v0.11.0 // indirect
|
golang.org/x/sys v0.11.0 // indirect
|
||||||
golang.org/x/text v0.12.0 // indirect
|
golang.org/x/text v0.12.0 // indirect
|
||||||
|
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
|
||||||
golang.org/x/tools v0.12.1-0.20230818130535-1517d1a3ba60 // indirect
|
golang.org/x/tools v0.12.1-0.20230818130535-1517d1a3ba60 // indirect
|
||||||
google.golang.org/protobuf v1.31.0 // indirect
|
|
||||||
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
|
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
|
||||||
lukechampine.com/blake3 v1.2.1 // indirect
|
lukechampine.com/blake3 v1.2.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
@ -866,6 +866,7 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb
|
||||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af h1:Yx9k8YCG3dvF87UAn2tu2HQLf2dt/eR1bXxpLMWeH+Y=
|
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af h1:Yx9k8YCG3dvF87UAn2tu2HQLf2dt/eR1bXxpLMWeH+Y=
|
||||||
|
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
|
|
@ -10,6 +10,7 @@ require (
|
||||||
github.com/ethereum/go-ethereum v1.10.26
|
github.com/ethereum/go-ethereum v1.10.26
|
||||||
github.com/ipfs/go-log/v2 v2.5.1
|
github.com/ipfs/go-log/v2 v2.5.1
|
||||||
github.com/waku-org/go-waku v0.2.3-0.20221109195301-b2a5a68d28ba
|
github.com/waku-org/go-waku v0.2.3-0.20221109195301-b2a5a68d28ba
|
||||||
|
google.golang.org/protobuf v1.31.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
@ -123,8 +124,8 @@ require (
|
||||||
golang.org/x/sync v0.3.0 // indirect
|
golang.org/x/sync v0.3.0 // indirect
|
||||||
golang.org/x/sys v0.11.0 // indirect
|
golang.org/x/sys v0.11.0 // indirect
|
||||||
golang.org/x/text v0.12.0 // indirect
|
golang.org/x/text v0.12.0 // indirect
|
||||||
|
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
|
||||||
golang.org/x/tools v0.12.1-0.20230818130535-1517d1a3ba60 // indirect
|
golang.org/x/tools v0.12.1-0.20230818130535-1517d1a3ba60 // indirect
|
||||||
google.golang.org/protobuf v1.31.0 // indirect
|
|
||||||
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
|
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
|
||||||
lukechampine.com/blake3 v1.2.1 // indirect
|
lukechampine.com/blake3 v1.2.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
@ -866,6 +866,7 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb
|
||||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af h1:Yx9k8YCG3dvF87UAn2tu2HQLf2dt/eR1bXxpLMWeH+Y=
|
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af h1:Yx9k8YCG3dvF87UAn2tu2HQLf2dt/eR1bXxpLMWeH+Y=
|
||||||
|
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
|
|
@ -10,6 +10,7 @@ require (
|
||||||
github.com/ethereum/go-ethereum v1.10.26
|
github.com/ethereum/go-ethereum v1.10.26
|
||||||
github.com/waku-org/go-waku v0.2.3-0.20221109195301-b2a5a68d28ba
|
github.com/waku-org/go-waku v0.2.3-0.20221109195301-b2a5a68d28ba
|
||||||
go.uber.org/zap v1.24.0
|
go.uber.org/zap v1.24.0
|
||||||
|
google.golang.org/protobuf v1.31.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
@ -123,8 +124,8 @@ require (
|
||||||
golang.org/x/sync v0.3.0 // indirect
|
golang.org/x/sync v0.3.0 // indirect
|
||||||
golang.org/x/sys v0.11.0 // indirect
|
golang.org/x/sys v0.11.0 // indirect
|
||||||
golang.org/x/text v0.12.0 // indirect
|
golang.org/x/text v0.12.0 // indirect
|
||||||
|
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
|
||||||
golang.org/x/tools v0.12.1-0.20230818130535-1517d1a3ba60 // indirect
|
golang.org/x/tools v0.12.1-0.20230818130535-1517d1a3ba60 // indirect
|
||||||
google.golang.org/protobuf v1.31.0 // indirect
|
|
||||||
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
|
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
|
||||||
lukechampine.com/blake3 v1.2.1 // indirect
|
lukechampine.com/blake3 v1.2.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
@ -866,6 +866,7 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb
|
||||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af h1:Yx9k8YCG3dvF87UAn2tu2HQLf2dt/eR1bXxpLMWeH+Y=
|
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af h1:Yx9k8YCG3dvF87UAn2tu2HQLf2dt/eR1bXxpLMWeH+Y=
|
||||||
|
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
|
|
@ -21,6 +21,8 @@ type WakuConfig struct {
|
||||||
GossipSubParams *GossipSubParams `json:"gossipsubParams,omitempty"`
|
GossipSubParams *GossipSubParams `json:"gossipsubParams,omitempty"`
|
||||||
EnableLegacyFilter *bool `json:"legacyFilter,omitempty"`
|
EnableLegacyFilter *bool `json:"legacyFilter,omitempty"`
|
||||||
MinPeersToPublish *int `json:"minPeersToPublish,omitempty"`
|
MinPeersToPublish *int `json:"minPeersToPublish,omitempty"`
|
||||||
|
DNSDiscoveryURLs []string `json:"dnsDiscoveryURLs,omitempty"`
|
||||||
|
DNSDiscoveryNameServer string `json:"dnsDiscoveryNameServer,omitempty"`
|
||||||
EnableDiscV5 *bool `json:"discV5,omitempty"`
|
EnableDiscV5 *bool `json:"discV5,omitempty"`
|
||||||
DiscV5BootstrapNodes []string `json:"discV5BootstrapNodes,omitempty"`
|
DiscV5BootstrapNodes []string `json:"discV5BootstrapNodes,omitempty"`
|
||||||
DiscV5UDPPort *uint `json:"discV5UDPPort,omitempty"`
|
DiscV5UDPPort *uint `json:"discV5UDPPort,omitempty"`
|
||||||
|
|
|
@ -15,7 +15,6 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
|
||||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||||
"github.com/libp2p/go-libp2p/core/peer"
|
"github.com/libp2p/go-libp2p/core/peer"
|
||||||
libp2pProtocol "github.com/libp2p/go-libp2p/core/protocol"
|
libp2pProtocol "github.com/libp2p/go-libp2p/core/protocol"
|
||||||
|
@ -145,15 +144,12 @@ func NewNode(configJSON string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if *config.EnableDiscV5 {
|
if *config.EnableDiscV5 {
|
||||||
var bootnodes []*enode.Node
|
discoveredNodes := node.GetNodesFromDNSDiscovery(utils.Logger(), context.TODO(), config.DNSDiscoveryNameServer, config.DNSDiscoveryURLs)
|
||||||
for _, addr := range config.DiscV5BootstrapNodes {
|
discv5Opts, err := node.GetDiscv5Option(discoveredNodes, config.DiscV5BootstrapNodes, *config.DiscV5UDPPort, true)
|
||||||
bootnode, err := enode.Parse(enode.ValidSchemes, addr)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
bootnodes = append(bootnodes, bootnode)
|
opts = append(opts, discv5Opts)
|
||||||
}
|
|
||||||
opts = append(opts, node.WithDiscoveryV5(*config.DiscV5UDPPort, bootnodes, true))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wakuState.relayTopics = config.RelayTopics
|
wakuState.relayTopics = config.RelayTopics
|
||||||
|
|
|
@ -30,6 +30,7 @@ import (
|
||||||
|
|
||||||
"github.com/waku-org/go-waku/logging"
|
"github.com/waku-org/go-waku/logging"
|
||||||
"github.com/waku-org/go-waku/waku/v2/discv5"
|
"github.com/waku-org/go-waku/waku/v2/discv5"
|
||||||
|
"github.com/waku-org/go-waku/waku/v2/dnsdisc"
|
||||||
"github.com/waku-org/go-waku/waku/v2/peermanager"
|
"github.com/waku-org/go-waku/waku/v2/peermanager"
|
||||||
wps "github.com/waku-org/go-waku/waku/v2/peerstore"
|
wps "github.com/waku-org/go-waku/waku/v2/peerstore"
|
||||||
wakuprotocol "github.com/waku-org/go-waku/waku/v2/protocol"
|
wakuprotocol "github.com/waku-org/go-waku/waku/v2/protocol"
|
||||||
|
@ -928,3 +929,41 @@ func (w *WakuNode) findRelayNodes(ctx context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetNodesFromDNSDiscovery(logger *zap.Logger, ctx context.Context, nameServer string, discoveryURLs []string) []dnsdisc.DiscoveredNode {
|
||||||
|
var discoveredNodes []dnsdisc.DiscoveredNode
|
||||||
|
for _, url := range discoveryURLs {
|
||||||
|
logger.Info("attempting DNS discovery with ", zap.String("URL", url))
|
||||||
|
nodes, err := dnsdisc.RetrieveNodes(ctx, url, dnsdisc.WithNameserver(nameServer))
|
||||||
|
if err != nil {
|
||||||
|
logger.Warn("dns discovery error ", zap.Error(err))
|
||||||
|
} else {
|
||||||
|
var discPeerInfo []peer.AddrInfo
|
||||||
|
for _, n := range nodes {
|
||||||
|
discPeerInfo = append(discPeerInfo, n.PeerInfo)
|
||||||
|
}
|
||||||
|
logger.Info("found dns entries ", zap.Any("nodes", discPeerInfo))
|
||||||
|
discoveredNodes = append(discoveredNodes, nodes...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return discoveredNodes
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDiscv5Option(dnsDiscoveredNodes []dnsdisc.DiscoveredNode, discv5Nodes []string, port uint, autoUpdate bool) (WakuNodeOption, error) {
|
||||||
|
var bootnodes []*enode.Node
|
||||||
|
for _, addr := range discv5Nodes {
|
||||||
|
bootnode, err := enode.Parse(enode.ValidSchemes, addr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
bootnodes = append(bootnodes, bootnode)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, n := range dnsDiscoveredNodes {
|
||||||
|
if n.ENR != nil {
|
||||||
|
bootnodes = append(bootnodes, n.ENR)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return WithDiscoveryV5(port, bootnodes, autoUpdate), nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue