From 16823c3a5818ce23c577b2b0c889cd91857f9366 Mon Sep 17 00:00:00 2001 From: Dennis Trautwein Date: Sun, 5 Feb 2023 11:08:34 +0100 Subject: [PATCH] use ping protocol instead of DHT ping --- dht.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/dht.go b/dht.go index 1bb75dfb0..fed07a5b9 100644 --- a/dht.go +++ b/dht.go @@ -26,6 +26,7 @@ import ( "github.com/libp2p/go-libp2p-kbucket/peerdiversity" record "github.com/libp2p/go-libp2p-record" recpb "github.com/libp2p/go-libp2p-record/pb" + "github.com/libp2p/go-libp2p/p2p/protocol/ping" "github.com/gogo/protobuf/proto" ds "github.com/ipfs/go-datastore" @@ -366,7 +367,19 @@ func makeRtRefreshManager(dht *IpfsDHT, cfg dhtcfg.Config, maxLastSuccessfulOutb } pingFnc := func(ctx context.Context, p peer.ID) error { - return dht.protoMessenger.Ping(ctx, p) + timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + // Just wait for a single ping + select { + case res, more := <-ping.Ping(timeoutCtx, dht.host, p): + if !more { + return timeoutCtx.Err() + } + return res.Error + case <-timeoutCtx.Done(): + return timeoutCtx.Err() + } } r, err := rtrefresh.NewRtRefreshManager(