fix: set nameserver via config

This commit is contained in:
Richard Ramos 2023-01-03 10:14:59 -04:00 committed by RichΛrd
parent dc87d6bb0f
commit 09723e3b9a
4 changed files with 18 additions and 2 deletions

View File

@ -294,6 +294,7 @@ func (b *StatusNode) wakuV2Service(nodeConfig *params.NodeConfig) (*wakuv2.Waku,
StoreSeconds: nodeConfig.WakuV2Config.StoreSeconds,
DiscoveryLimit: nodeConfig.WakuV2Config.DiscoveryLimit,
DiscV5BootstrapNodes: nodeConfig.ClusterConfig.DiscV5BootstrapNodes,
Nameserver: nodeConfig.WakuV2Config.Nameserver,
EnableDiscV5: nodeConfig.WakuV2Config.EnableDiscV5,
UDPPort: nodeConfig.WakuV2Config.UDPPort,
AutoUpdate: nodeConfig.WakuV2Config.AutoUpdate,

View File

@ -192,6 +192,9 @@ type WakuV2Config struct {
// PeerExchange determines whether WakuV2 Peer Exchange is enabled or not
PeerExchange bool
// Nameserver determines which nameserver will be used for dns discovery
Nameserver string
// EnableDiscV5 indicates if DiscoveryV5 is enabled or not
EnableDiscV5 bool

View File

@ -34,6 +34,7 @@ type Config struct {
WakuNodes []string `toml:",omitempty"`
Rendezvous bool `toml:",omitempty"`
DiscV5BootstrapNodes []string `toml:",omitempty"`
Nameserver string `toml:",omitempty"`
EnableDiscV5 bool `toml:",omitempty"`
DiscoveryLimit int `toml:",omitempty"`
AutoUpdate bool `toml:",omitempty"`

View File

@ -89,6 +89,7 @@ type settings struct {
EnableConfirmations bool // Enable sending message confirmations
PeerExchange bool // Enable peer exchange
DiscoveryLimit int // Indicates the number of nodes to discover
Nameserver string // Optional nameserver to use for dns discovery
}
// Waku represents a dark communication interface through the Ethereum
@ -197,6 +198,7 @@ func New(nodeKey string, fleet string, cfg *Config, logger *zap.Logger, appDB *s
MinPeersForRelay: cfg.MinPeersForRelay,
PeerExchange: cfg.PeerExchange,
DiscoveryLimit: cfg.DiscoveryLimit,
Nameserver: cfg.Nameserver,
}
waku.filters = common.NewFilters()
@ -400,8 +402,16 @@ func (w *Waku) dnsDiscover(ctx context.Context, enrtreeAddress string, apply fnA
discNodes, ok := w.dnsAddressCache[enrtreeAddress]
if !ok {
// NOTE: Temporary fix for DNS resolution on android/ios, as gomobile does not support it
discoveredNodes, err := dnsdisc.RetrieveNodes(ctx, enrtreeAddress, dnsdisc.WithNameserver("1.1.1.1"))
w.settingsMu.RLock()
nameserver := w.settings.Nameserver
w.settingsMu.RUnlock()
var opts []dnsdisc.DnsDiscoveryOption
if nameserver != "" {
opts = append(opts, dnsdisc.WithNameserver(nameserver))
}
discoveredNodes, err := dnsdisc.RetrieveNodes(ctx, enrtreeAddress, opts...)
if err != nil {
w.logger.Warn("dns discovery error ", zap.Error(err))
return
@ -434,6 +444,7 @@ func (w *Waku) addWakuV2Peers(ctx context.Context, cfg *Config) error {
identifyWg := &sync.WaitGroup{}
identifyWg.Add(len(cfg.WakuNodes))
for _, addrString := range cfg.WakuNodes {
addrString := addrString
if strings.HasPrefix(addrString, "enrtree://") {
// Use DNS Discovery
go func() {