Skip to content

Commit 16823c3

Browse files
committed
use ping protocol instead of DHT ping
1 parent eb6d2f7 commit 16823c3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

dht.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/libp2p/go-libp2p-kbucket/peerdiversity"
2727
record "github.com/libp2p/go-libp2p-record"
2828
recpb "github.com/libp2p/go-libp2p-record/pb"
29+
"github.com/libp2p/go-libp2p/p2p/protocol/ping"
2930

3031
"github.com/gogo/protobuf/proto"
3132
ds "github.com/ipfs/go-datastore"
@@ -366,7 +367,19 @@ func makeRtRefreshManager(dht *IpfsDHT, cfg dhtcfg.Config, maxLastSuccessfulOutb
366367
}
367368

368369
pingFnc := func(ctx context.Context, p peer.ID) error {
369-
return dht.protoMessenger.Ping(ctx, p)
370+
timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
371+
defer cancel()
372+
373+
// Just wait for a single ping
374+
select {
375+
case res, more := <-ping.Ping(timeoutCtx, dht.host, p):
376+
if !more {
377+
return timeoutCtx.Err()
378+
}
379+
return res.Error
380+
case <-timeoutCtx.Done():
381+
return timeoutCtx.Err()
382+
}
370383
}
371384

372385
r, err := rtrefresh.NewRtRefreshManager(

0 commit comments

Comments
 (0)