Iterate through Peerstore in startKeepAlive() (#102)

This commit is contained in:
Vitaliy Vlasov 2021-11-01 19:33:58 +02:00 committed by GitHub
parent b63efd6561
commit 268767262b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -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: