Flags for ALL the things.
This commit is contained in:
parent
af55e865f8
commit
e5b6978290
25
btc-crawl.go
25
btc-crawl.go
|
@ -1,8 +1,9 @@
|
||||||
|
// TODO: Export to a reasonable format.
|
||||||
|
// TODO: Use proper logger for logging.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jessevdk/go-flags"
|
"github.com/jessevdk/go-flags"
|
||||||
"log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Taken from: https://github.com/bitcoin/bitcoin/blob/89d72f3d9b6e7ef051ad1439f266b809f348229b/src/chainparams.cpp#L143
|
// Taken from: https://github.com/bitcoin/bitcoin/blob/89d72f3d9b6e7ef051ad1439f266b809f348229b/src/chainparams.cpp#L143
|
||||||
|
@ -15,32 +16,30 @@ var defaultDnsSeeds = []string{
|
||||||
"bitseed.xf2.org",
|
"bitseed.xf2.org",
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Unhardcode these:
|
|
||||||
var userAgent string = "/btc-crawl:0.0.1"
|
|
||||||
var lastBlock int32 = 0
|
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Verbose []bool `short:"v" long:"verbose" description:"Show verbose logging."`
|
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>"`
|
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() {
|
func main() {
|
||||||
// TODO: Parse args.
|
|
||||||
options := Options{}
|
options := Options{}
|
||||||
_, err := flags.Parse(&options)
|
parser := flags.NewParser(&options, flags.Default)
|
||||||
|
|
||||||
|
_, err := parser.Parse()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
// FIXME: Print on some specific errors? Seems Parse prints in most cases.
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
seedNodes := options.Seed
|
seedNodes := options.Seed
|
||||||
|
|
||||||
// TODO: Export to a reasonable format.
|
|
||||||
// TODO: Use proper logger for logging.
|
|
||||||
if len(seedNodes) == 0 {
|
if len(seedNodes) == 0 {
|
||||||
seedNodes = GetSeedsFromDNS(defaultDnsSeeds)
|
seedNodes = GetSeedsFromDNS(defaultDnsSeeds)
|
||||||
}
|
}
|
||||||
|
|
||||||
client := NewClient(userAgent, lastBlock)
|
client := NewClient(options.UserAgent)
|
||||||
crawler := NewCrawler(client, seedNodes, 10)
|
crawler := NewCrawler(client, seedNodes, options.Concurrency)
|
||||||
crawler.Start()
|
crawler.Start()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,12 @@ type Client struct {
|
||||||
btcnet btcwire.BitcoinNet // Bitcoin Network
|
btcnet btcwire.BitcoinNet // Bitcoin Network
|
||||||
pver uint32 // Protocl Version
|
pver uint32 // Protocl Version
|
||||||
userAgent string // User Agent
|
userAgent string // User Agent
|
||||||
lastBlock int32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(userAgent string, lastBlock int32) *Client {
|
func NewClient(userAgent string) *Client {
|
||||||
return &Client{
|
return &Client{
|
||||||
btcnet: btcwire.MainNet,
|
btcnet: btcwire.MainNet,
|
||||||
pver: btcwire.ProtocolVersion,
|
pver: btcwire.ProtocolVersion,
|
||||||
userAgent: userAgent,
|
userAgent: userAgent,
|
||||||
lastBlock: lastBlock,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue