Skip to content

Commit 32836e1

Browse files
guillaumemicheldennis-tra
authored andcommitted
fixed successful query detection
1 parent c9c4546 commit 32836e1

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

discv5/crawler.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/dennis-tra/nebula-crawler/discvx"
2626
)
2727

28-
const MAX_CRAWL_RETRY_AFTER_TIMEOUT = 2 // magic
28+
const MaxCrawlRetriesAfterTimeout = 2 // magic
2929

3030
type CrawlerConfig struct {
3131
DialTimeout time.Duration
@@ -466,7 +466,6 @@ func (c *Crawler) crawlDiscV5(ctx context.Context, pi PeerInfo) chan DiscV5Resul
466466
result.RespondedAt = &now
467467
}
468468

469-
success := false
470469
// loop through the buckets sequentially because discv5 is also doing that
471470
// internally, so we won't gain much by spawning multiple parallel go
472471
// routines here. Stop the process as soon as we have received a timeout and
@@ -478,7 +477,7 @@ func (c *Crawler) crawlDiscV5(ctx context.Context, pi PeerInfo) chan DiscV5Resul
478477

479478
if errors.Is(err, discvx.ErrTimeout) {
480479
timeouts += 1
481-
if timeouts < MAX_CRAWL_RETRY_AFTER_TIMEOUT {
480+
if timeouts < MaxCrawlRetriesAfterTimeout {
482481
continue
483482
}
484483
}
@@ -487,7 +486,6 @@ func (c *Crawler) crawlDiscV5(ctx context.Context, pi PeerInfo) chan DiscV5Resul
487486
err = fmt.Errorf("getting closest peer with CPL %d: %w", i, err)
488487
break
489488
}
490-
success = true
491489
timeouts = 0
492490

493491
if result.RespondedAt == nil {
@@ -520,7 +518,9 @@ func (c *Crawler) crawlDiscV5(ctx context.Context, pi PeerInfo) chan DiscV5Resul
520518
}
521519

522520
// if we have at least a successful result, delete error
523-
if success && result.Error != nil {
521+
// bitwise operation checks whether errorBits is a power of 2 minus 1,
522+
// if not, then there was at least one successful result
523+
if result.Error != nil && (result.RoutingTable.ErrorBits&(result.RoutingTable.ErrorBits+1)) == 0 {
524524
result.Error = nil
525525
}
526526

0 commit comments

Comments
 (0)