Browse Source

Intermediate... working on debora

pull/52/head
Jae Kwon 10 years ago
parent
commit
a09051438c
7 changed files with 68 additions and 26 deletions
  1. +3
    -1
      binary/reflect.go
  2. +22
    -0
      common/os.go
  3. +1
    -15
      node/node.go
  4. +11
    -0
      p2p/switch.go
  5. +28
    -9
      process/process.go
  6. +1
    -1
      rpc/core_client/client.go
  7. +2
    -0
      rpc/core_client/client_methods.go

+ 3
- 1
binary/reflect.go View File

@ -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
- 0
common/os.go View 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 {}
}

+ 1
- 15
node/node.go View File

@ -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 {}
}

+ 11
- 0
p2p/switch.go View File

@ -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) {}
//-----------------------------------------------------------------------------
/*


+ 28
- 9
process/process.go View File

@ -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{
Cmd: cmd,
Output: out,
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)
}
}

+ 1
- 1
rpc/core_client/client.go View File

@ -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 {


+ 2
- 0
rpc/core_client/client_methods.go View File

@ -1,3 +1,5 @@
// File generated by github.com/ebuchman/rpc-gen
package core_client
import (


Loading…
Cancel
Save