Skip to content

Commit

Permalink
fixed successful query detection
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumemichel authored and dennis-tra committed Feb 1, 2024
1 parent c9c4546 commit 32836e1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions discv5/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/dennis-tra/nebula-crawler/discvx"
)

const MAX_CRAWL_RETRY_AFTER_TIMEOUT = 2 // magic
const MaxCrawlRetriesAfterTimeout = 2 // magic

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

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

if errors.Is(err, discvx.ErrTimeout) {
timeouts += 1
if timeouts < MAX_CRAWL_RETRY_AFTER_TIMEOUT {
if timeouts < MaxCrawlRetriesAfterTimeout {
continue
}
}
Expand All @@ -487,7 +486,6 @@ func (c *Crawler) crawlDiscV5(ctx context.Context, pi PeerInfo) chan DiscV5Resul
err = fmt.Errorf("getting closest peer with CPL %d: %w", i, err)
break
}
success = true
timeouts = 0

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

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

Expand Down

0 comments on commit 32836e1

Please sign in to comment.