chore: bump go-waku to disconnect peers if keep alive loop wasnt executed recently

This commit is contained in:
Richard Ramos 2022-12-05 15:36:29 -04:00 committed by RichΛrd
parent 8fc7d921a7
commit b50a134b48
4 changed files with 24 additions and 5 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.20221129201435-94d20ab12276
github.com/waku-org/go-waku v0.2.3-0.20221205192014-05e33105c43f
)
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.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-waku v0.2.3-0.20221205192014-05e33105c43f h1:MGWZyvAizQs9BoNDh/GUbzJykBJKETXRvwbd8/VwglA=
github.com/waku-org/go-waku v0.2.3-0.20221205192014-05e33105c43f/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

@ -23,9 +23,26 @@ func (w *WakuNode) startKeepAlive(t time.Duration) {
w.log.Info("setting up ping protocol", zap.Duration("duration", t))
ticker := time.NewTicker(t)
defer ticker.Stop()
lastTimeExecuted := <-ticker.C
sleepDetectionInterval := int64(t) * 3
for {
select {
case <-ticker.C:
difference := time.Now().UnixNano() - lastTimeExecuted.UnixNano()
if difference > sleepDetectionInterval {
w.log.Warn("keep alive hasnt been executed recently. Killing all connections to peers")
for _, p := range w.host.Network().Peers() {
err := w.host.Network().ClosePeer(p)
if err != nil {
w.log.Warn("while disconnecting peer", zap.Error(err))
}
}
lastTimeExecuted = time.Now()
continue
}
// Network's peers collection,
// contains only currently active peers
for _, p := range w.host.Network().Peers() {
@ -34,6 +51,8 @@ func (w *WakuNode) startKeepAlive(t time.Duration) {
go w.pingPeer(p)
}
}
lastTimeExecuted = time.Now()
case <-w.quit:
return
}
@ -58,7 +77,7 @@ func (w *WakuNode) pingPeer(peer peer.ID) {
w.keepAliveFails[peer]++
logger.Debug("could not ping", zap.Error(res.Error))
} else {
w.keepAliveFails[peer] = 0
delete(w.keepAliveFails, peer)
}
case <-ctx.Done():
w.keepAliveFails[peer]++

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.20221129201435-94d20ab12276
# github.com/waku-org/go-waku v0.2.3-0.20221205192014-05e33105c43f
## explicit; go 1.18
github.com/waku-org/go-waku/logging
github.com/waku-org/go-waku/waku/persistence