From 268767262b60b5193d8dc49a53ec7ce214d4fbb9 Mon Sep 17 00:00:00 2001 From: Vitaliy Vlasov Date: Mon, 1 Nov 2021 19:33:58 +0200 Subject: [PATCH] Iterate through Peerstore in startKeepAlive() (#102) --- waku/v2/node/wakunode2.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/waku/v2/node/wakunode2.go b/waku/v2/node/wakunode2.go index 70bb4813..c9105099 100644 --- a/waku/v2/node/wakunode2.go +++ b/waku/v2/node/wakunode2.go @@ -118,6 +118,7 @@ func New(ctx context.Context, opts ...WakuNodeOption) (*WakuNode, error) { w.connectionNotif = NewConnectionNotifier(ctx, host) w.host.Network().Notify(w.connectionNotif) + go w.connectednessListener() if w.opts.keepAliveInterval > time.Duration(0) { @@ -540,7 +541,13 @@ func (w *WakuNode) startKeepAlive(t time.Duration) { for { select { case <-ticker.C: - for _, p := range w.host.Network().Peers() { + // Compared to Network's peers collection, + // Peerstore contains all peers ever connected to, + // thus if a host goes down and back again, + // pinging a peer will trigger identification process, + // which is not possible when iterating + // through Network's peer collection, as it will be empty + for _, p := range w.host.Peerstore().Peers() { go pingPeer(w.ctx, w.ping, p) } case <-w.quit: