From f0223c0d12745fbb22a7e6c5a10664f6fa051f3d Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 4 Apr 2024 17:29:49 +0200 Subject: [PATCH] fix: check if cid is in dht --- daemon.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/daemon.go b/daemon.go index 4a2be25..30f1f10 100644 --- a/daemon.go +++ b/daemon.go @@ -126,7 +126,7 @@ func (d *daemon) runCheck(query url.Values) (*output, error) { connectionFailed := false - out.CidInDHT = providerRecordInDHT(ctx, d.dht, c, ai.ID) + out.CidInDHT = providerRecordInDHT(ctx, d.dht, c) addrMap, peerAddrDHTErr := peerAddrsInDHT(ctx, d.dht, d.dhtMessenger, ai.ID) out.PeerFoundInDHT = addrMap @@ -250,19 +250,18 @@ func peerAddrsInDHT(ctx context.Context, d kademlia, messenger *dhtpb.ProtocolMe return addrMap, nil } -func providerRecordInDHT(ctx context.Context, d kademlia, c cid.Cid, p peer.ID) bool { +func providerRecordInDHT(ctx context.Context, d kademlia, c cid.Cid) bool { queryCtx, cancel := context.WithCancel(ctx) defer cancel() + provsCh := d.FindProvidersAsync(queryCtx, c, 0) for { select { - case prov, ok := <-provsCh: + case _, ok := <-provsCh: if !ok { return false } - if prov.ID == p { - return true - } + return true case <-ctx.Done(): return false }