mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-21 17:01:35 +00:00
Intermediate... working on debora
This commit is contained in:
@ -178,7 +178,9 @@ func RegisterType(info *TypeInfo) *TypeInfo {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
jsonName := field.Tag.Get("json")
|
jsonName := field.Tag.Get("json")
|
||||||
if jsonName == "" {
|
if jsonName == "-" {
|
||||||
|
continue
|
||||||
|
} else if jsonName == "" {
|
||||||
jsonName = field.Name
|
jsonName = field.Name
|
||||||
}
|
}
|
||||||
structFields = append(structFields, StructFieldInfo{
|
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 (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
|
||||||
|
|
||||||
bc "github.com/tendermint/tendermint/blockchain"
|
bc "github.com/tendermint/tendermint/blockchain"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
@ -166,20 +165,7 @@ func RunNode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sleep forever and then...
|
// Sleep forever and then...
|
||||||
trapSignal(func() {
|
TrapSignal(func() {
|
||||||
n.Stop()
|
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)
|
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 {
|
type Process struct {
|
||||||
Cmd *exec.Cmd
|
Label string
|
||||||
Output *os.File
|
ExecPath string
|
||||||
|
StartTime time.Time
|
||||||
|
Cmd *exec.Cmd `json:"-"`
|
||||||
|
Output *os.File `json:"-"`
|
||||||
|
ExitState *os.ProcessState `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -28,9 +32,11 @@ const (
|
|||||||
ProcessModeDaemon
|
ProcessModeDaemon
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateProcess(mode int, name string, args ...string) *Process {
|
// execPath: command name
|
||||||
out := makeFile(name)
|
// args: args to command. (should not include name)
|
||||||
cmd := exec.Command(name, args...)
|
func Create(mode int, label string, execPath string, args ...string) *Process {
|
||||||
|
out := makeFile(label)
|
||||||
|
cmd := exec.Command(execPath, args...)
|
||||||
switch mode {
|
switch mode {
|
||||||
case ProcessModeStd:
|
case ProcessModeStd:
|
||||||
cmd.Stdout = io.MultiWriter(os.Stdout, out)
|
cmd.Stdout = io.MultiWriter(os.Stdout, out)
|
||||||
@ -48,14 +54,27 @@ func CreateProcess(mode int, name string, args ...string) *Process {
|
|||||||
fmt.Printf("Success!")
|
fmt.Printf("Success!")
|
||||||
}
|
}
|
||||||
return &Process{
|
return &Process{
|
||||||
|
Label: label,
|
||||||
|
ExecPath: execPath,
|
||||||
|
StartTime: time.Now(),
|
||||||
Cmd: cmd,
|
Cmd: cmd,
|
||||||
Output: out,
|
Output: out,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Watch(proc *Process) {
|
func Wait(proc *Process) error {
|
||||||
exitErr := proc.Cmd.Wait()
|
exitErr := proc.Cmd.Wait()
|
||||||
if exitErr != nil {
|
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"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
// Uncomment to use go:generate
|
// Uncomment to use go:generate
|
||||||
// _ "github.com/ebuchman/go-rpc-gen"
|
// _ "github.com/tendermint/go-rpc-gen"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// File generated by github.com/ebuchman/rpc-gen
|
||||||
|
|
||||||
package core_client
|
package core_client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
Reference in New Issue
Block a user