diff --git a/cmd/barak/main.go b/cmd/barak/main.go index 5301d895e..46ee0e3fc 100644 --- a/cmd/barak/main.go +++ b/cmd/barak/main.go @@ -36,12 +36,20 @@ type Options struct { // Global instance var barak = struct { mtx sync.Mutex + pid int + nonce uint64 processes map[string]*pcm.Process validators []Validator - nonce uint64 -}{sync.Mutex{}, make(map[string]*pcm.Process), nil, 0} +}{ + mtx: sync.Mutex{}, + pid: os.Getpid(), + nonce: 0, + processes: make(map[string]*pcm.Process), + validators: nil, +} func main() { + fmt.Printf("New Debora Process (PID: %d)\n", os.Getpid()) // read options from stdin. var err error @@ -77,11 +85,13 @@ func main() { func Status() (*ResponseStatus, error) { barak.mtx.Lock() + pid := barak.pid nonce := barak.nonce validators := barak.validators barak.mtx.Unlock() return &ResponseStatus{ + Pid: pid, Nonce: nonce, Validators: validators, }, nil diff --git a/cmd/barak/types/responses.go b/cmd/barak/types/responses.go index cb3b71fe3..aae299253 100644 --- a/cmd/barak/types/responses.go +++ b/cmd/barak/types/responses.go @@ -5,6 +5,7 @@ import ( ) type ResponseStatus struct { + Pid int Nonce uint64 Validators []Validator } diff --git a/cmd/debora/README.md b/cmd/debora/README.md new file mode 100644 index 000000000..a9cdb80a3 --- /dev/null +++ b/cmd/debora/README.md @@ -0,0 +1,10 @@ +### Example + +```bash +# Upgrade barak. +# We need to give it a new seed to prevent port conflicts. +./build/debora --privkey-file build/privkey run --input "`cat cmd/barak/seed2`" -- barak2 ./build/barak + +# Build tendermint from source +./build/debora --privkey-file build/privkey run -- build_tendermint bash -c "cd $GOPATH/src/github.com/tendermint/tendermint; make" +``` diff --git a/cmd/debora/commands.go b/cmd/debora/commands.go index 8929e85f8..7e6199d3b 100644 --- a/cmd/debora/commands.go +++ b/cmd/debora/commands.go @@ -49,13 +49,16 @@ func ListProcesses(privKey acm.PrivKey, remote string, command btypes.CommandLis // Utility method to get nonce from the remote. // The next command should include the returned nonce+1 as nonce. func GetNonce(remote string) (uint64, error) { - var err error - response := btypes.ResponseStatus{} + response, err := GetStatus(remote) + return response.Nonce, err +} + +func GetStatus(remote string) (response btypes.ResponseStatus, err error) { _, err = rpc.Call(remote, "status", Arr(), &response) if err != nil { - return 0, fmt.Errorf("Error fetching nonce from remote %v:\n %v", remote, err) + return response, fmt.Errorf("Error fetching nonce from remote %v:\n %v", remote, err) } - return response.Nonce, nil + return response, nil } // Each developer runs this diff --git a/cmd/debora/main.go b/cmd/debora/main.go index ef9d56409..f61743d9e 100644 --- a/cmd/debora/main.go +++ b/cmd/debora/main.go @@ -53,6 +53,11 @@ func main() { return nil } app.Commands = []cli.Command{ + cli.Command{ + Name: "status", + Usage: "shows remote status", + Action: cliGetStatus, + }, cli.Command{ Name: "run", Usage: "run process", @@ -100,6 +105,21 @@ func ParseFlags(c *cli.Context) (remotes []string, privKey acm.PrivKey) { return remotes, privKey } +func cliGetStatus(c *cli.Context) { + args := c.Args() + if len(args) != 0 { + fmt.Println("BTW, status takes no arguments.") + } + for _, remote := range remotes { + response, err := GetStatus(remote) + if err != nil { + fmt.Printf("%v failure. %v\n", remote, err) + } else { + fmt.Printf("%v success. %v\n", remote, response) + } + } +} + func cliRunProcess(c *cli.Context) { args := c.Args() if len(args) < 2 {