@ -143,7 +143,7 @@ var discoveryNodeFlags = []cli.Flag{
func discv4Ping ( ctx * cli . Context ) error {
n := getNodeArg ( ctx )
disc := startV4 ( ctx )
disc , _ := startV4 ( ctx )
defer disc . Close ( )
start := time . Now ( )
@ -156,7 +156,7 @@ func discv4Ping(ctx *cli.Context) error {
func discv4RequestRecord ( ctx * cli . Context ) error {
n := getNodeArg ( ctx )
disc := startV4 ( ctx )
disc , _ := startV4 ( ctx )
defer disc . Close ( )
respN , err := disc . RequestENR ( n )
@ -169,7 +169,7 @@ func discv4RequestRecord(ctx *cli.Context) error {
func discv4Resolve ( ctx * cli . Context ) error {
n := getNodeArg ( ctx )
disc := startV4 ( ctx )
disc , _ := startV4 ( ctx )
defer disc . Close ( )
fmt . Println ( disc . Resolve ( n ) . String ( ) )
@ -196,10 +196,13 @@ func discv4ResolveJSON(ctx *cli.Context) error {
nodeargs = append ( nodeargs , n )
}
// Run the crawler.
disc := startV4 ( ctx )
disc , config := startV4 ( ctx )
defer disc . Close ( )
c := newCrawler ( inputSet , disc , enode . IterNodes ( nodeargs ) )
c , err := newCrawler ( inputSet , config . Bootnodes , disc , enode . IterNodes ( nodeargs ) )
if err != nil {
return err
}
c . revalidateInterval = 0
output := c . run ( 0 , 1 )
writeNodesJSON ( nodesFile , output )
@ -211,14 +214,18 @@ func discv4Crawl(ctx *cli.Context) error {
return errors . New ( "need nodes file as argument" )
}
nodesFile := ctx . Args ( ) . First ( )
var inputSet nodeSet
inputSet := make ( nodeSet )
if common . FileExist ( nodesFile ) {
inputSet = loadNodesJSON ( nodesFile )
}
disc := startV4 ( ctx )
disc , config := startV4 ( ctx )
defer disc . Close ( )
c := newCrawler ( inputSet , disc , disc . RandomNodes ( ) )
c , err := newCrawler ( inputSet , config . Bootnodes , disc , disc . RandomNodes ( ) )
if err != nil {
return err
}
c . revalidateInterval = 10 * time . Minute
output := c . run ( ctx . Duration ( crawlTimeoutFlag . Name ) , ctx . Int ( crawlParallelismFlag . Name ) )
writeNodesJSON ( nodesFile , output )
@ -238,14 +245,14 @@ func discv4Test(ctx *cli.Context) error {
}
// startV4 starts an ephemeral discovery V4 node.
func startV4 ( ctx * cli . Context ) * discover . UDPv4 {
func startV4 ( ctx * cli . Context ) ( * discover . UDPv4 , discover . Config ) {
ln , config := makeDiscoveryConfig ( ctx )
socket := listen ( ctx , ln )
disc , err := discover . ListenV4 ( socket , ln , config )
if err != nil {
exit ( err )
}
return disc
return disc , config
}
func makeDiscoveryConfig ( ctx * cli . Context ) ( * enode . LocalNode , discover . Config ) {