mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-28 04:01:40 +00:00
upgrades to debora/barak to allow shutting down barak
This commit is contained in:
@ -22,6 +22,8 @@ import (
|
||||
"github.com/tendermint/tendermint/rpc/server"
|
||||
)
|
||||
|
||||
const BarakVersion = "0.0.1"
|
||||
|
||||
var Routes map[string]*rpcserver.RPCFunc
|
||||
|
||||
func init() {
|
||||
@ -72,6 +74,7 @@ func Status() (*ResponseStatus, error) {
|
||||
barak_.mtx.Unlock()
|
||||
|
||||
return &ResponseStatus{
|
||||
Version: BarakVersion,
|
||||
Pid: pid,
|
||||
Nonce: nonce,
|
||||
Validators: validators,
|
||||
@ -96,6 +99,8 @@ func Run(authCommand AuthCommand) (interface{}, error) {
|
||||
return OpenListener(c.Addr)
|
||||
case CommandCloseListener:
|
||||
return CloseListener(c.Addr)
|
||||
case CommandQuit:
|
||||
return Quit()
|
||||
default:
|
||||
return nil, errors.New("Invalid endpoint for command")
|
||||
}
|
||||
@ -204,6 +209,15 @@ func CloseListener(addr string) (*ResponseCloseListener, error) {
|
||||
return &ResponseCloseListener{}, nil
|
||||
}
|
||||
|
||||
func Quit() (*ResponseQuit, error) {
|
||||
fmt.Println("Barak shutting down due to Quit()")
|
||||
go func() {
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(0)
|
||||
}()
|
||||
return &ResponseQuit{}, nil
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
// Another barak instance registering its external
|
||||
|
@ -24,6 +24,7 @@ const (
|
||||
commandTypeServeFile = 0x04
|
||||
commandTypeOpenListener = 0x05
|
||||
commandTypeCloseListener = 0x06
|
||||
commandTypeQuit = 0x07
|
||||
)
|
||||
|
||||
// for binary.readReflect
|
||||
@ -35,6 +36,7 @@ var _ = binary.RegisterInterface(
|
||||
binary.ConcreteType{CommandServeFile{}, commandTypeServeFile},
|
||||
binary.ConcreteType{CommandOpenListener{}, commandTypeOpenListener},
|
||||
binary.ConcreteType{CommandCloseListener{}, commandTypeCloseListener},
|
||||
binary.ConcreteType{CommandQuit{}, commandTypeQuit},
|
||||
)
|
||||
|
||||
type CommandStartProcess struct {
|
||||
@ -63,3 +65,5 @@ type CommandOpenListener struct {
|
||||
type CommandCloseListener struct {
|
||||
Addr string
|
||||
}
|
||||
|
||||
type CommandQuit struct{}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
)
|
||||
|
||||
type ResponseStatus struct {
|
||||
Version string
|
||||
Pid int
|
||||
Nonce int64
|
||||
Validators []Validator
|
||||
@ -31,3 +32,6 @@ type ResponseOpenListener struct {
|
||||
|
||||
type ResponseCloseListener struct {
|
||||
}
|
||||
|
||||
type ResponseQuit struct {
|
||||
}
|
||||
|
@ -100,6 +100,16 @@ func DownloadFile(privKey acm.PrivKey, remote string, command btypes.CommandServ
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func Quit(privKey acm.PrivKey, remote string, command btypes.CommandQuit) (response btypes.ResponseQuit, err error) {
|
||||
nonce, err := GetNonce(remote)
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
commandBytes, signature := SignCommand(privKey, nonce+1, command)
|
||||
_, err = RunAuthCommand(remote, commandBytes, []acm.Signature{signature}, &response)
|
||||
return response, err
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Utility method to get nonce from the remote.
|
||||
|
@ -106,12 +106,12 @@ func main() {
|
||||
},
|
||||
cli.Command{
|
||||
Name: "open",
|
||||
Usage: "open listener",
|
||||
Usage: "open barak listener",
|
||||
Action: cliOpenListener,
|
||||
},
|
||||
cli.Command{
|
||||
Name: "close",
|
||||
Usage: "close listener",
|
||||
Usage: "close barka listener",
|
||||
Action: cliCloseListener,
|
||||
},
|
||||
cli.Command{
|
||||
@ -119,6 +119,11 @@ func main() {
|
||||
Usage: "download file <remote-path> <local-path-prefix>",
|
||||
Action: cliDownloadFile,
|
||||
},
|
||||
cli.Command{
|
||||
Name: "quit",
|
||||
Usage: "quit barak",
|
||||
Action: cliQuit,
|
||||
},
|
||||
}
|
||||
app.Run(os.Args)
|
||||
}
|
||||
@ -330,3 +335,21 @@ func cliDownloadFile(c *cli.Context) {
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func cliQuit(c *cli.Context) {
|
||||
command := btypes.CommandQuit{}
|
||||
wg := sync.WaitGroup{}
|
||||
for _, remote := range Config.Remotes {
|
||||
wg.Add(1)
|
||||
go func(remote string) {
|
||||
defer wg.Done()
|
||||
response, err := Quit(Config.PrivKey, remote, command)
|
||||
if err != nil {
|
||||
fmt.Printf("%v failure. %v\n", remote, err)
|
||||
} else {
|
||||
fmt.Printf("%v success. %v\n", remote, response)
|
||||
}
|
||||
}(remote)
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
Reference in New Issue
Block a user