@@ -14,9 +14,8 @@ import (
14
14
"sync"
15
15
"time"
16
16
17
- "github.com/libp2p/go-libp2p/core/host"
18
17
"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 "
20
19
"github.com/waku-org/go-waku/waku/v2/protocol/store"
21
20
"go.uber.org/zap"
22
21
)
@@ -55,9 +54,8 @@ type StorenodeCycle struct {
55
54
56
55
logger * zap.Logger
57
56
58
- host host.Host
59
-
60
57
storenodeConfigProvider StorenodeConfigProvider
58
+ pinger common.Pinger
61
59
62
60
StorenodeAvailableOneshotEmitter * OneShotEmitter [struct {}]
63
61
StorenodeChangedEmitter * Emitter [peer.ID ]
@@ -71,7 +69,7 @@ type StorenodeCycle struct {
71
69
peers map [peer.ID ]peerStatus
72
70
}
73
71
74
- func NewStorenodeCycle (logger * zap.Logger ) * StorenodeCycle {
72
+ func NewStorenodeCycle (logger * zap.Logger , pinger common. Pinger ) * StorenodeCycle {
75
73
return & StorenodeCycle {
76
74
StorenodeAvailableOneshotEmitter : NewOneshotEmitter [struct {}](),
77
75
StorenodeChangedEmitter : NewEmitter [peer.ID ](),
@@ -81,9 +79,8 @@ func NewStorenodeCycle(logger *zap.Logger) *StorenodeCycle {
81
79
}
82
80
}
83
81
84
- func (m * StorenodeCycle ) Start (ctx context.Context , h host. Host ) {
82
+ func (m * StorenodeCycle ) Start (ctx context.Context ) {
85
83
m .logger .Debug ("starting storenode cycle" )
86
- m .host = h
87
84
m .failedRequests = make (map [peer.ID ]uint )
88
85
m .peers = make (map [peer.ID ]peerStatus )
89
86
@@ -194,7 +191,7 @@ func (m *StorenodeCycle) getAvailableStorenodesSortedByRTT(ctx context.Context,
194
191
ctx , cancel := context .WithTimeout (ctx , 4 * time .Second )
195
192
defer cancel ()
196
193
197
- rtt , err := m .pingPeer (ctx , peerID )
194
+ rtt , err := m .pinger . PingPeer (ctx , peerID )
198
195
if err == nil { // pinging storenodes might fail, but we don't care
199
196
availableStorenodesMutex .Lock ()
200
197
availableStorenodes [peerID ] = rtt
@@ -233,19 +230,6 @@ func (m *StorenodeCycle) getAvailableStorenodesSortedByRTT(ctx context.Context,
233
230
return result
234
231
}
235
232
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
-
249
233
func (m * StorenodeCycle ) findNewStorenode (ctx context.Context ) error {
250
234
// we have to override DNS manually because of https://github.com/status-im/status-mobile/issues/19581
251
235
if overrideDNS {
0 commit comments