Allow setting fallback nodes after start

In some cases, we don't have fallback nodes when we start.
That might be due to some connectivity issues.

This commit adds a method to set the fallback nodes, and triggers a
refresh so that they are picked up.

The method is synchronous.
This commit is contained in:
Andrea Maria Piana 2022-12-09 16:02:04 +00:00
parent 2f43d5f6c7
commit 14e8ef894a
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424

View File

@ -29,12 +29,13 @@ import (
"sync"
"time"
"github.com/waku-org/go-discover/discover/v5wire"
"github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/enr"
"github.com/ethereum/go-ethereum/p2p/netutil"
"github.com/waku-org/go-discover/discover/v5wire"
)
const (
@ -846,6 +847,17 @@ func packNodes(reqid []byte, nodes []*enode.Node) []*v5wire.Nodes {
return resp
}
func (t *UDPv5) SetFallbackNodes(nodes []*enode.Node) error {
err := t.tab.setFallbackNodes(nodes)
if err != nil {
return err
}
refreshDone := make(chan struct{})
t.tab.doRefresh(refreshDone)
<-refreshDone
return nil
}
// handleTalkRequest runs the talk request handler of the requested protocol.
func (t *UDPv5) handleTalkRequest(p *v5wire.TalkRequest, fromID enode.ID, fromAddr *net.UDPAddr) {
t.trlock.Lock()