chore(waku2): bump go-waku

This commit is contained in:
Richard Ramos 2022-11-29 15:44:12 -04:00 committed by RichΛrd
parent 23d45d8707
commit 5b69985b18
5 changed files with 44 additions and 35 deletions

2
go.mod
View File

@ -80,7 +80,7 @@ require github.com/fogleman/gg v1.3.0
require (
github.com/gorilla/sessions v1.2.1
github.com/meirf/gopart v0.0.0-20180520194036-37e9492a85a8
github.com/waku-org/go-waku v0.2.3-0.20221126210912-041c7be67dfb
github.com/waku-org/go-waku v0.2.3-0.20221129201435-94d20ab12276
)
require (

4
go.sum
View File

@ -2065,8 +2065,8 @@ github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/waku-org/go-discover v0.0.0-20221027130446-2f43d5f6c73f h1:YHIrSqs8Aot1exhwx0+uwdshCp3RfZu5OY6Hvt3Hk8g=
github.com/waku-org/go-discover v0.0.0-20221027130446-2f43d5f6c73f/go.mod h1:eBHgM6T4EG0RZzxpxKy+rGz/6Dw2Nd8DWxS0lm9ESDw=
github.com/waku-org/go-waku v0.2.3-0.20221126210912-041c7be67dfb h1:d/ZP7cofn3xdkGBWCuqtbIC6JlG+ytxscyeau3czQ5Y=
github.com/waku-org/go-waku v0.2.3-0.20221126210912-041c7be67dfb/go.mod h1:tJGCjHrNc8JjOX0df15Uv4YiLQMNhWrotKHJeeVl3AE=
github.com/waku-org/go-waku v0.2.3-0.20221129201435-94d20ab12276 h1:ZysP5YONX3uGhkDGceDLhPRiVfXYjk6MuHtFgW+LjCA=
github.com/waku-org/go-waku v0.2.3-0.20221129201435-94d20ab12276/go.mod h1:tJGCjHrNc8JjOX0df15Uv4YiLQMNhWrotKHJeeVl3AE=
github.com/waku-org/go-zerokit-rln v0.1.7-wakuorg h1:2vVIBCtBih2w1K9ll8YnToTDZvbxcgbsClsPlJS/kkg=
github.com/waku-org/go-zerokit-rln v0.1.7-wakuorg/go.mod h1:GlyaVeEWNEBxVJrWC6jFTvb4LNb9d9qnjdS6EiWVUvk=
github.com/waku-org/noise v1.0.2 h1:7WmlhpJ0eliBzwzKz6SoTqQznaEU2IuebHF3oCekqqs=

View File

@ -26,6 +26,7 @@ type DiscoveryV5 struct {
discovery.Discovery
params *discV5Parameters
ctx context.Context
host host.Host
config discover.Config
udpAddr *net.UDPAddr
@ -39,7 +40,9 @@ type DiscoveryV5 struct {
wg *sync.WaitGroup
peerCache peerCache
peerCache peerCache
discoverCtx context.Context
discoverCancelFunc context.CancelFunc
}
type peerCache struct {
@ -95,7 +98,9 @@ func DefaultOptions() []DiscoveryV5Option {
}
}
func NewDiscoveryV5(host host.Host, priv *ecdsa.PrivateKey, localnode *enode.LocalNode, log *zap.Logger, opts ...DiscoveryV5Option) (*DiscoveryV5, error) {
const MaxPeersToDiscover = 600
func NewDiscoveryV5(ctx context.Context, host host.Host, priv *ecdsa.PrivateKey, localnode *enode.LocalNode, log *zap.Logger, opts ...DiscoveryV5Option) (*DiscoveryV5, error) {
params := new(discV5Parameters)
optList := DefaultOptions()
optList = append(optList, opts...)
@ -111,6 +116,7 @@ func NewDiscoveryV5(host host.Host, priv *ecdsa.PrivateKey, localnode *enode.Loc
}
return &DiscoveryV5{
ctx: ctx,
host: host,
params: params,
NAT: NAT,
@ -194,6 +200,10 @@ func (d *DiscoveryV5) Start() error {
return err
}
// create cancellable
d.discoverCtx, d.discoverCancelFunc = context.WithCancel(d.ctx)
go d.runDiscoveryV5Loop()
return nil
}
@ -206,6 +216,7 @@ func (d *DiscoveryV5) Stop() {
}
close(d.quit)
d.discoverCancelFunc()
d.listener.Close()
d.listener = nil
@ -279,7 +290,7 @@ func (d *DiscoveryV5) Advertise(ctx context.Context, ns string, opts ...discover
return 20 * time.Minute, nil
}
func (d *DiscoveryV5) iterate(ctx context.Context, iterator enode.Iterator, limit int, doneCh chan struct{}) {
func (d *DiscoveryV5) iterate(iterator enode.Iterator, limit int, doneCh chan struct{}) {
defer d.wg.Done()
for {
@ -287,7 +298,7 @@ func (d *DiscoveryV5) iterate(ctx context.Context, iterator enode.Iterator, limi
break
}
if ctx.Err() != nil {
if d.discoverCtx.Err() != nil {
break
}
@ -308,6 +319,7 @@ func (d *DiscoveryV5) iterate(ctx context.Context, iterator enode.Iterator, limi
continue
}
d.peerCache.Lock()
for _, p := range peerAddrs {
d.peerCache.recs[p.ID] = PeerRecord{
expire: time.Now().Unix() + 3600, // Expires in 1hr
@ -315,7 +327,7 @@ func (d *DiscoveryV5) iterate(ctx context.Context, iterator enode.Iterator, limi
Node: *iterator.Node(),
}
}
d.peerCache.Unlock()
}
close(doneCh)
@ -337,6 +349,25 @@ func (d *DiscoveryV5) removeExpiredPeers() int {
return newCacheSize
}
func (d *DiscoveryV5) runDiscoveryV5Loop() {
iterator := d.listener.RandomNodes()
iterator = enode.Filter(iterator, evaluateNode)
defer iterator.Close()
doneCh := make(chan struct{})
d.wg.Add(1)
go d.iterate(iterator, MaxPeersToDiscover, doneCh)
select {
case <-d.discoverCtx.Done():
case <-doneCh:
}
d.log.Warn("Discv5 loop stopped")
}
func (d *DiscoveryV5) FindNodes(ctx context.Context, topic string, opts ...discovery.Option) ([]PeerRecord, error) {
// Get options
var options discovery.Options
@ -345,10 +376,9 @@ func (d *DiscoveryV5) FindNodes(ctx context.Context, topic string, opts ...disco
return nil, err
}
const maxLimit = 600
limit := options.Limit
if limit == 0 || limit > maxLimit {
limit = maxLimit
if limit == 0 || limit > MaxPeersToDiscover {
limit = MaxPeersToDiscover
}
// We are ignoring the topic. Future versions might use a map[string]*peerCache instead where the string represents the pubsub topic
@ -356,28 +386,7 @@ func (d *DiscoveryV5) FindNodes(ctx context.Context, topic string, opts ...disco
d.peerCache.Lock()
defer d.peerCache.Unlock()
cacheSize := d.removeExpiredPeers()
// Discover new records if we don't have enough
if cacheSize < limit && d.listener != nil {
d.Lock()
iterator := d.listener.RandomNodes()
iterator = enode.Filter(iterator, evaluateNode)
defer iterator.Close()
doneCh := make(chan struct{})
d.wg.Add(1)
go d.iterate(ctx, iterator, limit, doneCh)
select {
case <-ctx.Done():
case <-doneCh:
}
d.Unlock()
}
d.removeExpiredPeers()
// Randomize and fill channel with available records
count := len(d.peerCache.recs)

View File

@ -489,7 +489,7 @@ func (w *WakuNode) mountDiscV5() error {
}
var err error
w.discoveryV5, err = discv5.NewDiscoveryV5(w.Host(), w.opts.privKey, w.localNode, w.log, discV5Options...)
w.discoveryV5, err = discv5.NewDiscoveryV5(w.ctx, w.Host(), w.opts.privKey, w.localNode, w.log, discV5Options...)
return err
}

2
vendor/modules.txt vendored
View File

@ -990,7 +990,7 @@ github.com/vacp2p/mvds/transport
github.com/waku-org/go-discover/discover
github.com/waku-org/go-discover/discover/v4wire
github.com/waku-org/go-discover/discover/v5wire
# github.com/waku-org/go-waku v0.2.3-0.20221126210912-041c7be67dfb
# github.com/waku-org/go-waku v0.2.3-0.20221129201435-94d20ab12276
## explicit; go 1.18
github.com/waku-org/go-waku/logging
github.com/waku-org/go-waku/waku/persistence