Flags for ALL the things.

This commit is contained in:
Andrey Petrov 2014-04-23 16:03:34 -07:00
parent af55e865f8
commit e5b6978290
2 changed files with 14 additions and 17 deletions

View File

@ -1,8 +1,9 @@
// TODO: Export to a reasonable format.
// TODO: Use proper logger for logging.
package main
import (
"github.com/jessevdk/go-flags"
"log"
)
// Taken from: https://github.com/bitcoin/bitcoin/blob/89d72f3d9b6e7ef051ad1439f266b809f348229b/src/chainparams.cpp#L143
@ -15,32 +16,30 @@ var defaultDnsSeeds = []string{
"bitseed.xf2.org",
}
// TODO: Unhardcode these:
var userAgent string = "/btc-crawl:0.0.1"
var lastBlock int32 = 0
type Options struct {
Verbose []bool `short:"v" long:"verbose" description:"Show verbose logging."`
Seed []string `short:"s" long:"seed" description:"Override which seeds to use." default-mask:"<bitcoind DNS seeds>"`
Verbose []bool `short:"v" long:"verbose" description:"Show verbose logging."`
Seed []string `short:"s" long:"seed" description:"Override which seeds to use." default-mask:"<bitcoin-core DNS seeds>"`
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/"`
}
func main() {
// TODO: Parse args.
options := Options{}
_, err := flags.Parse(&options)
parser := flags.NewParser(&options, flags.Default)
_, err := parser.Parse()
if err != nil {
log.Fatal(err)
// FIXME: Print on some specific errors? Seems Parse prints in most cases.
return
}
seedNodes := options.Seed
// TODO: Export to a reasonable format.
// TODO: Use proper logger for logging.
if len(seedNodes) == 0 {
seedNodes = GetSeedsFromDNS(defaultDnsSeeds)
}
client := NewClient(userAgent, lastBlock)
crawler := NewCrawler(client, seedNodes, 10)
client := NewClient(options.UserAgent)
crawler := NewCrawler(client, seedNodes, options.Concurrency)
crawler.Start()
}

View File

@ -8,14 +8,12 @@ type Client struct {
btcnet btcwire.BitcoinNet // Bitcoin Network
pver uint32 // Protocl Version
userAgent string // User Agent
lastBlock int32
}
func NewClient(userAgent string, lastBlock int32) *Client {
func NewClient(userAgent string) *Client {
return &Client{
btcnet: btcwire.MainNet,
pver: btcwire.ProtocolVersion,
userAgent: userAgent,
lastBlock: lastBlock,
}
}