mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-21 08:51:32 +00:00
Intermediate... working on debora
This commit is contained in:
@ -178,7 +178,9 @@ func RegisterType(info *TypeInfo) *TypeInfo {
|
||||
continue
|
||||
}
|
||||
jsonName := field.Tag.Get("json")
|
||||
if jsonName == "" {
|
||||
if jsonName == "-" {
|
||||
continue
|
||||
} else if jsonName == "" {
|
||||
jsonName = field.Name
|
||||
}
|
||||
structFields = append(structFields, StructFieldInfo{
|
||||
|
22
common/os.go
Normal file
22
common/os.go
Normal file
@ -0,0 +1,22 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
)
|
||||
|
||||
func TrapSignal(cb func()) {
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
go func() {
|
||||
for sig := range c {
|
||||
fmt.Printf("captured %v, exiting...\n", sig)
|
||||
if cb != nil {
|
||||
cb()
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
select {}
|
||||
}
|
16
node/node.go
16
node/node.go
@ -2,7 +2,6 @@ package node
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
bc "github.com/tendermint/tendermint/blockchain"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
@ -166,20 +165,7 @@ func RunNode() {
|
||||
}
|
||||
|
||||
// Sleep forever and then...
|
||||
trapSignal(func() {
|
||||
TrapSignal(func() {
|
||||
n.Stop()
|
||||
})
|
||||
}
|
||||
|
||||
func trapSignal(cb func()) {
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
go func() {
|
||||
for sig := range c {
|
||||
log.Info(Fmt("captured %v, exiting..", sig))
|
||||
cb()
|
||||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
select {}
|
||||
}
|
||||
|
@ -19,6 +19,17 @@ type Reactor interface {
|
||||
Receive(chId byte, peer *Peer, msgBytes []byte)
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
|
||||
type BaseReactor struct{}
|
||||
|
||||
func (_ BaseReactor) Start(sw *Switch) {}
|
||||
func (_ BaseReactor) Stop() {}
|
||||
func (_ BaseReactor) GetChannels() []*ChannelDescriptor { return nil }
|
||||
func (_ BaseReactor) AddPeer(peer *Peer) {}
|
||||
func (_ BaseReactor) RemovePeer(peer *Peer, reason interface{}) {}
|
||||
func (_ BaseReactor) Receive(chId byte, peer *Peer, msgBytes []byte) {}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
|
@ -19,8 +19,12 @@ func makeFile(prefix string) *os.File {
|
||||
}
|
||||
|
||||
type Process struct {
|
||||
Cmd *exec.Cmd
|
||||
Output *os.File
|
||||
Label string
|
||||
ExecPath string
|
||||
StartTime time.Time
|
||||
Cmd *exec.Cmd `json:"-"`
|
||||
Output *os.File `json:"-"`
|
||||
ExitState *os.ProcessState `json:"-"`
|
||||
}
|
||||
|
||||
const (
|
||||
@ -28,9 +32,11 @@ const (
|
||||
ProcessModeDaemon
|
||||
)
|
||||
|
||||
func CreateProcess(mode int, name string, args ...string) *Process {
|
||||
out := makeFile(name)
|
||||
cmd := exec.Command(name, args...)
|
||||
// execPath: command name
|
||||
// args: args to command. (should not include name)
|
||||
func Create(mode int, label string, execPath string, args ...string) *Process {
|
||||
out := makeFile(label)
|
||||
cmd := exec.Command(execPath, args...)
|
||||
switch mode {
|
||||
case ProcessModeStd:
|
||||
cmd.Stdout = io.MultiWriter(os.Stdout, out)
|
||||
@ -48,14 +54,27 @@ func CreateProcess(mode int, name string, args ...string) *Process {
|
||||
fmt.Printf("Success!")
|
||||
}
|
||||
return &Process{
|
||||
Label: label,
|
||||
ExecPath: execPath,
|
||||
StartTime: time.Now(),
|
||||
Cmd: cmd,
|
||||
Output: out,
|
||||
}
|
||||
}
|
||||
|
||||
func Watch(proc *Process) {
|
||||
func Wait(proc *Process) error {
|
||||
exitErr := proc.Cmd.Wait()
|
||||
if exitErr != nil {
|
||||
fmt.Println("%v", exitErr)
|
||||
fmt.Printf("Process exit: %v\n", exitErr)
|
||||
proc.ExitState = exitErr.(*exec.ExitError).ProcessState
|
||||
}
|
||||
return exitErr
|
||||
}
|
||||
|
||||
func Stop(proc *Process, kill bool) error {
|
||||
if kill {
|
||||
return proc.Cmd.Process.Kill()
|
||||
} else {
|
||||
return proc.Cmd.Process.Signal(os.Interrupt)
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
"net/url"
|
||||
"reflect"
|
||||
// Uncomment to use go:generate
|
||||
// _ "github.com/ebuchman/go-rpc-gen"
|
||||
// _ "github.com/tendermint/go-rpc-gen"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
|
@ -1,3 +1,5 @@
|
||||
// File generated by github.com/ebuchman/rpc-gen
|
||||
|
||||
package core_client
|
||||
|
||||
import (
|
||||
|
Reference in New Issue
Block a user