Skip to content

Commit

Permalink
Merge branch 'main' into filter-unactionable
Browse files Browse the repository at this point in the history
  • Loading branch information
2color authored Oct 7, 2024
2 parents 1dcd8b7 + a727540 commit b56dd42
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,16 @@ func (d *daemon) runCidCheck(ctx context.Context, cidKey cid.Cid, ipniURL string
queryCtx, cancelQuery := context.WithCancel(ctx)
defer cancelQuery()

// Find providers with DHT and IPNI concurrently.
provsCh := d.dht.FindProvidersAsync(queryCtx, cidKey, maxProvidersCount)
ipniProvsCh := routerClient.FindProvidersAsync(queryCtx, cidKey, maxProvidersCount)
// half of the max providers count per source
providersPerSource := maxProvidersCount >> 1
if maxProvidersCount == 1 {
// Ensure at least one provider from each source when maxProvidersCount is 1
providersPerSource = 1
}

// Find providers with DHT and IPNI concurrently (each half of the max providers count)
dhtProvsCh := d.dht.FindProvidersAsync(queryCtx, cidKey, providersPerSource)
ipniProvsCh := routerClient.FindProvidersAsync(queryCtx, cidKey, providersPerSource)

out := make([]providerOutput, 0, maxProvidersCount)
var wg sync.WaitGroup
Expand All @@ -181,9 +188,9 @@ func (d *daemon) runCidCheck(ctx context.Context, cidKey cid.Cid, ipniURL string
var source string

select {
case provider, open = <-provsCh:
case provider, open = <-dhtProvsCh:
if !open {
provsCh = nil
dhtProvsCh = nil
if ipniProvsCh == nil {
done = true
}
Expand All @@ -193,7 +200,7 @@ func (d *daemon) runCidCheck(ctx context.Context, cidKey cid.Cid, ipniURL string
case provider, open = <-ipniProvsCh:
if !open {
ipniProvsCh = nil
if provsCh == nil {
if dhtProvsCh == nil {
done = true
}
continue
Expand Down

0 comments on commit b56dd42

Please sign in to comment.