func RunNode() { // Create & start node n := NewNode() l := p2p.NewDefaultListener("tcp", config.GetString("node_laddr"), false) n.AddListener(l) n.Start() log.Notice("Started node", "nodeInfo", n.sw.NodeInfo()) // If seedNode is provided by config, dial out. if config.GetString("seeds") != "" { n.DialSeed() } // Run the RPC server. if config.GetString("rpc_laddr") != "" { _, err := n.StartRPC() if err != nil { PanicCrisis(err) } } // Sleep forever and then... TrapSignal(func() { n.Stop() }) }
func RunNode() { // Wait until the genesis doc becomes available genDocFile := config.GetString("genesis_file") if !FileExists(genDocFile) { log.Notice(Fmt("Waiting for genesis file %v...", genDocFile)) for { time.Sleep(time.Second) if FileExists(genDocFile) { break } jsonBlob, err := ioutil.ReadFile(genDocFile) if err != nil { Exit(Fmt("Couldn't read GenesisDoc file: %v", err)) } genDoc := stypes.GenesisDocFromJSON(jsonBlob) if genDoc.ChainID == "" { PanicSanity(Fmt("Genesis doc %v must include non-empty chain_id", genDocFile)) } config.Set("chain_id", genDoc.ChainID) config.Set("genesis_doc", genDoc) } } // Create & start node n := NewNodeDefaultPrivVal() l := p2p.NewDefaultListener("tcp", config.GetString("node_laddr")) n.AddListener(l) err := n.Start() if err != nil { Exit(Fmt("Failed to start node: %v", err)) } log.Notice("Started node", "nodeInfo", n.sw.NodeInfo()) // If seedNode is provided by config, dial out. if config.GetString("seeds") != "" { n.DialSeed() } // Run the RPC server. if config.GetString("rpc_laddr") != "" { _, err := n.StartRPC() if err != nil { PanicCrisis(err) } } // Sleep forever and then... TrapSignal(func() { n.Stop() }) }
// create a new node and sleep forever func newNode(ready chan struct{}) { // Create & start node node = nm.NewNodeDefaultPrivVal() l := p2p.NewDefaultListener("tcp", config.GetString("node_laddr")) node.AddListener(l) node.Start() // Run the RPC server. node.StartRPC() ready <- struct{}{} // Sleep forever ch := make(chan struct{}) <-ch }
func RunNode() { // Wait until the genesis doc becomes available genDocFile := config.GetString("genesis_file") if !FileExists(genDocFile) { log.Notice(Fmt("Waiting for genesis file %v...", genDocFile)) for { time.Sleep(time.Second) if FileExists(genDocFile) { break } } } // Create & start node n := NewNode() l := p2p.NewDefaultListener("tcp", config.GetString("node_laddr")) n.AddListener(l) err := n.Start() if err != nil { Exit(Fmt("Failed to start node: %v", err)) } log.Notice("Started node", "nodeInfo", n.sw.NodeInfo()) // If seedNode is provided by config, dial out. if config.GetString("seeds") != "" { n.DialSeed() } // Run the RPC server. if config.GetString("rpc_laddr") != "" { _, err := n.StartRPC() if err != nil { PanicCrisis(err) } } // Sleep forever and then... TrapSignal(func() { n.Stop() }) }
func TestNodeStartStop(t *testing.T) { // Create & start node n := NewNode() l := p2p.NewDefaultListener("tcp", config.GetString("node_laddr"), false) n.AddListener(l) n.Start() log.Notice("Started node", "nodeInfo", n.sw.NodeInfo()) time.Sleep(time.Second * 2) ch := make(chan struct{}, 1) go func() { n.Stop() ch <- struct{}{} }() ticker := time.NewTicker(time.Second * 5) select { case <-ch: case <-ticker.C: t.Fatal("timed out waiting for shutdown") } }
// Private. Create a new node func startNode(nd *node.Node, ready chan struct{}, shutDown <-chan struct{}) { laddr := tmConfig.GetString("node_laddr") if laddr != "" { l := p2p.NewDefaultListener("tcp", laddr, false) nd.AddListener(l) } nd.Start() // If seedNode is provided by config, dial out. if len(tmConfig.GetString("seeds")) > 0 { nd.DialSeed() } ready <- struct{}{} // Block until everything is shut down. <-shutDown nd.Stop() }
func RunNode() { // Create & start node n := NewNode() l := p2p.NewDefaultListener("tcp", config.GetString("node_laddr"), false) n.AddListener(l) n.Start() // If seedNode is provided by config, dial out. if config.GetString("seeds") != "" { n.DialSeed() } // Run the RPC server. if config.GetString("rpc_laddr") != "" { n.StartRPC() } // Sleep forever and then... TrapSignal(func() { n.Stop() }) }