Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var SensorCmd = &cobra.Command{ Use: "sensor [nodes file]", Short: "devp2p sensor that does peer discovery and block/transaction propagation.", Long: `Starts a devp2p sensor that discovers other peers and will receive blocks and transactions. If no nodes.json file exists, run echo "{}" >> nodes.json to get started.`, Args: cobra.MinimumNArgs(1), PreRunE: func(cmd *cobra.Command, args []string) (err error) { inputSensorParams.NodesFile = args[0] if inputSensorParams.NetworkID == 0 { return errors.New("network ID must be greater than zero") } inputSensorParams.revalidationInterval, err = time.ParseDuration(inputSensorParams.RevalidationInterval) if err != nil { return err } if inputSensorParams.ShouldRunPprof { go func() { if err := http.ListenAndServe(fmt.Sprintf("localhost:%v", inputSensorParams.PprofPort), nil); err != nil { log.Error().Err(err).Msg("Failed to start pprof") } }() } return nil }, RunE: func(cmd *cobra.Command, args []string) error { inputSet, err := p2p.LoadNodesJSON(inputSensorParams.NodesFile) if err != nil { return err } var cfg discover.Config cfg.PrivateKey, _ = crypto.GenerateKey() bn, err := p2p.ParseBootnodes(inputSensorParams.Bootnodes) if err != nil { return fmt.Errorf("unable to parse bootnodes: %w", err) } cfg.Bootnodes = bn db, err := enode.OpenDB(inputSensorParams.Database) if err != nil { return err } ln := enode.NewLocalNode(db, cfg.PrivateKey) socket, err := p2p.Listen(ln) if err != nil { return err } disc, err := discover.ListenV4(socket, ln, cfg) if err != nil { return err } defer disc.Close() c := newSensor(inputSet, disc, disc.RandomNodes()) c.revalidateInterval = inputSensorParams.revalidationInterval log.Info().Msg("Starting sensor") c.run(inputSensorParams.Threads) return nil }, }
SensorCmd represents the sensor command. This is responsible for starting a sensor and transmitting blocks and transactions to a database.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.