Skip to content

Commit

Permalink
fix: check if cid is in dht
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Apr 4, 2024
1 parent ee73ab6 commit f0223c0
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit f0223c0

Please sign in to comment.