@@ -14,9 +14,8 @@ import (
1414 "sync"
1515 "time"
1616
17- "github.com/libp2p/go-libp2p/core/host"
1817 "github.com/libp2p/go-libp2p/core/peer"
19- "github.com/libp2p /go-libp2p/p2p/protocol/ping "
18+ "github.com/waku-org /go-waku/waku/v2/api/common "
2019 "github.com/waku-org/go-waku/waku/v2/protocol/store"
2120 "go.uber.org/zap"
2221)
@@ -55,9 +54,8 @@ type StorenodeCycle struct {
5554
5655 logger * zap.Logger
5756
58- host host.Host
59-
6057 storenodeConfigProvider StorenodeConfigProvider
58+ pinger common.Pinger
6159
6260 StorenodeAvailableOneshotEmitter * OneShotEmitter [struct {}]
6361 StorenodeChangedEmitter * Emitter [peer.ID ]
@@ -71,7 +69,7 @@ type StorenodeCycle struct {
7169 peers map [peer.ID ]peerStatus
7270}
7371
74- func NewStorenodeCycle (logger * zap.Logger ) * StorenodeCycle {
72+ func NewStorenodeCycle (logger * zap.Logger , pinger common. Pinger ) * StorenodeCycle {
7573 return & StorenodeCycle {
7674 StorenodeAvailableOneshotEmitter : NewOneshotEmitter [struct {}](),
7775 StorenodeChangedEmitter : NewEmitter [peer.ID ](),
@@ -81,9 +79,8 @@ func NewStorenodeCycle(logger *zap.Logger) *StorenodeCycle {
8179 }
8280}
8381
84- func (m * StorenodeCycle ) Start (ctx context.Context , h host. Host ) {
82+ func (m * StorenodeCycle ) Start (ctx context.Context ) {
8583 m .logger .Debug ("starting storenode cycle" )
86- m .host = h
8784 m .failedRequests = make (map [peer.ID ]uint )
8885 m .peers = make (map [peer.ID ]peerStatus )
8986
@@ -194,7 +191,7 @@ func (m *StorenodeCycle) getAvailableStorenodesSortedByRTT(ctx context.Context,
194191 ctx , cancel := context .WithTimeout (ctx , 4 * time .Second )
195192 defer cancel ()
196193
197- rtt , err := m .pingPeer (ctx , peerID )
194+ rtt , err := m .pinger . PingPeer (ctx , peerID )
198195 if err == nil { // pinging storenodes might fail, but we don't care
199196 availableStorenodesMutex .Lock ()
200197 availableStorenodes [peerID ] = rtt
@@ -233,19 +230,6 @@ func (m *StorenodeCycle) getAvailableStorenodesSortedByRTT(ctx context.Context,
233230 return result
234231}
235232
236- func (m * StorenodeCycle ) pingPeer (ctx context.Context , peerID peer.ID ) (time.Duration , error ) {
237- pingResultCh := ping .Ping (ctx , m .host , peerID )
238- select {
239- case <- ctx .Done ():
240- return 0 , ctx .Err ()
241- case r := <- pingResultCh :
242- if r .Error != nil {
243- return 0 , r .Error
244- }
245- return r .RTT , nil
246- }
247- }
248-
249233func (m * StorenodeCycle ) findNewStorenode (ctx context.Context ) error {
250234 // we have to override DNS manually because of https://github.com/status-im/status-mobile/issues/19581
251235 if overrideDNS {
0 commit comments