Skip to content

Commit

Permalink
use ping protocol instead of DHT ping
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis-tra committed Feb 5, 2023
1 parent eb6d2f7 commit 16823c3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 16823c3

Please sign in to comment.