From d77af12f6769a91a14fbdeefb98e09684c00ced1 Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Fri, 25 Apr 2014 16:31:03 -0700 Subject: [PATCH] Fix stopAfter --- btc-crawl.go | 3 ++- crawler.go | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/btc-crawl.go b/btc-crawl.go index 1e4e27c..79ffdec 100644 --- a/btc-crawl.go +++ b/btc-crawl.go @@ -1,4 +1,5 @@ // TODO: Namespace packages properly (outside of `main`) +// TODO: Apply peer-age filter to results? package main import ( @@ -30,7 +31,7 @@ type Options struct { Concurrency int `short:"c" long:"concurrency" description:"Maximum number of concurrent connections to open." default:"10"` UserAgent string `short:"A" long:"user-agent" description:"Client name to advertise while crawling. Should be in format of '/name:x.y.z/'." default:"/btc-crawl:0.1.1/"` PeerAge time.Duration `long:"peer-age" description:"Ignore discovered peers older than this." default:"24h"` - StopAfter int `long:"stop-after" description:"Stop crawling after this many results."` + StopAfter int `long:"stop-after" description:"Stop crawling after this many results." default:"0"` } var logLevels = []log.Level{ diff --git a/crawler.go b/crawler.go index 3fe1141..7995826 100644 --- a/crawler.go +++ b/crawler.go @@ -120,6 +120,11 @@ func (c *Crawler) Run(numWorkers int, stopAfter int) *[]Result { results := []Result{} + if stopAfter == 0 { + // No stopping. + stopAfter = -1 + } + // This is the main "event loop". Feels like there may be a better way to // manage the number of concurrent workers but I can't think of it right now. for {