refactoring barak
This commit is contained in:
parent
89e05168d5
commit
dcdf74ccc2
|
@ -14,7 +14,6 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
. "github.com/tendermint/tendermint/cmd/barak/types"
|
. "github.com/tendermint/tendermint/cmd/barak/types"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
|
@ -23,7 +22,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var Routes = map[string]*rpc.RPCFunc{
|
var Routes = map[string]*rpc.RPCFunc{
|
||||||
"run_auth_command": rpc.NewRPCFunc(Run, []string{"auth_command"}),
|
"run": rpc.NewRPCFunc(Run, []string{"auth_command"}),
|
||||||
// NOTE: also, two special non-JSONRPC routes called "download" and "upload"
|
// NOTE: also, two special non-JSONRPC routes called "download" and "upload"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,48 +127,10 @@ func parseValidateCommand(authCommand AuthCommand) (Command, error) {
|
||||||
return command.Command, nil
|
return command.Command, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuthCommand struct {
|
|
||||||
CommandJSONStr string
|
|
||||||
Signatures []acm.Signature
|
|
||||||
}
|
|
||||||
|
|
||||||
type NoncedCommand struct {
|
|
||||||
Nonce uint64
|
|
||||||
Command
|
|
||||||
}
|
|
||||||
|
|
||||||
type Command interface{}
|
|
||||||
|
|
||||||
// for binary.readReflect
|
|
||||||
var _ = binary.RegisterInterface(
|
|
||||||
struct{ Command }{},
|
|
||||||
binary.ConcreteType{CommandRunProcess{}},
|
|
||||||
binary.ConcreteType{CommandStopProcess{}},
|
|
||||||
binary.ConcreteType{CommandListProcesses{}},
|
|
||||||
binary.ConcreteType{CommandServeFile{}},
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
typeByteRunProcess = 0x01
|
|
||||||
typeByteStopProcess = 0x02
|
|
||||||
typeByteListProcesses = 0x03
|
|
||||||
typeByteServeFile = 0x04
|
|
||||||
)
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// RPC base commands
|
// RPC base commands
|
||||||
// WARNING Not validated, do not export to routes.
|
// WARNING Not validated, do not export to routes.
|
||||||
|
|
||||||
type CommandRunProcess struct {
|
|
||||||
Wait bool
|
|
||||||
Label string
|
|
||||||
ExecPath string
|
|
||||||
Args []string
|
|
||||||
Input string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_ CommandRunProcess) TypeByte() byte { return typeByteRunProcess }
|
|
||||||
|
|
||||||
func RunProcess(wait bool, label string, execPath string, args []string, input string) (*ResponseRunProcess, error) {
|
func RunProcess(wait bool, label string, execPath string, args []string, input string) (*ResponseRunProcess, error) {
|
||||||
barak.mtx.Lock()
|
barak.mtx.Lock()
|
||||||
|
|
||||||
|
@ -193,15 +154,6 @@ func RunProcess(wait bool, label string, execPath string, args []string, input s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------
|
|
||||||
|
|
||||||
type CommandStopProcess struct {
|
|
||||||
Label string
|
|
||||||
Kill bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_ CommandStopProcess) TypeByte() byte { return typeByteStopProcess }
|
|
||||||
|
|
||||||
func StopProcess(label string, kill bool) (*ResponseStopProcess, error) {
|
func StopProcess(label string, kill bool) (*ResponseStopProcess, error) {
|
||||||
barak.mtx.Lock()
|
barak.mtx.Lock()
|
||||||
proc := barak.processes[label]
|
proc := barak.processes[label]
|
||||||
|
@ -215,12 +167,6 @@ func StopProcess(label string, kill bool) (*ResponseStopProcess, error) {
|
||||||
return &ResponseStopProcess{}, err
|
return &ResponseStopProcess{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------
|
|
||||||
|
|
||||||
type CommandListProcesses struct{}
|
|
||||||
|
|
||||||
func (_ CommandListProcesses) TypeByte() byte { return typeByteListProcesses }
|
|
||||||
|
|
||||||
func ListProcesses() (*ResponseListProcesses, error) {
|
func ListProcesses() (*ResponseListProcesses, error) {
|
||||||
var procs = []*pcm.Process{}
|
var procs = []*pcm.Process{}
|
||||||
barak.mtx.Lock()
|
barak.mtx.Lock()
|
||||||
|
@ -234,14 +180,6 @@ func ListProcesses() (*ResponseListProcesses, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
type CommandServeFile struct {
|
|
||||||
Path string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_ CommandServeFile) TypeByte() byte { return typeByteServeFile }
|
|
||||||
|
|
||||||
func ServeFile(w http.ResponseWriter, req *http.Request) {
|
func ServeFile(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
authCommandStr := req.FormValue("auth_command")
|
authCommandStr := req.FormValue("auth_command")
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
acm "github.com/tendermint/tendermint/account"
|
||||||
|
"github.com/tendermint/tendermint/binary"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AuthCommand struct {
|
||||||
|
CommandJSONStr string
|
||||||
|
Signatures []acm.Signature
|
||||||
|
}
|
||||||
|
|
||||||
|
type NoncedCommand struct {
|
||||||
|
Nonce uint64
|
||||||
|
Command
|
||||||
|
}
|
||||||
|
|
||||||
|
type Command interface{}
|
||||||
|
|
||||||
|
// for binary.readReflect
|
||||||
|
var _ = binary.RegisterInterface(
|
||||||
|
struct{ Command }{},
|
||||||
|
binary.ConcreteType{CommandRunProcess{}},
|
||||||
|
binary.ConcreteType{CommandStopProcess{}},
|
||||||
|
binary.ConcreteType{CommandListProcesses{}},
|
||||||
|
binary.ConcreteType{CommandServeFile{}},
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
typeByteRunProcess = 0x01
|
||||||
|
typeByteStopProcess = 0x02
|
||||||
|
typeByteListProcesses = 0x03
|
||||||
|
typeByteServeFile = 0x04
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO: This is actually not cleaner than a method call.
|
||||||
|
// In fact, this is stupid.
|
||||||
|
func (_ CommandRunProcess) TypeByte() byte { return typeByteRunProcess }
|
||||||
|
func (_ CommandStopProcess) TypeByte() byte { return typeByteStopProcess }
|
||||||
|
func (_ CommandListProcesses) TypeByte() byte { return typeByteListProcesses }
|
||||||
|
func (_ CommandServeFile) TypeByte() byte { return typeByteServeFile }
|
||||||
|
|
||||||
|
type CommandRunProcess struct {
|
||||||
|
Wait bool
|
||||||
|
Label string
|
||||||
|
ExecPath string
|
||||||
|
Args []string
|
||||||
|
Input string
|
||||||
|
}
|
||||||
|
|
||||||
|
type CommandStopProcess struct {
|
||||||
|
Label string
|
||||||
|
Kill bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type CommandListProcesses struct{}
|
||||||
|
|
||||||
|
type CommandServeFile struct {
|
||||||
|
Path string
|
||||||
|
}
|
|
@ -9,6 +9,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// XXX Need to get PrivAccount somehow to sign the request.
|
||||||
|
// XXX Actually, more like, how do I even sign these?
|
||||||
|
// XXX Let's just sign it janky for now and modify later.
|
||||||
|
|
||||||
response := []btypes.ResponseListProcesses{}
|
response := []btypes.ResponseListProcesses{}
|
||||||
response2, err := rpc.Call("http://127.0.0.1:8082", "list_processes", Arr(), &response)
|
response2, err := rpc.Call("http://127.0.0.1:8082", "list_processes", Arr(), &response)
|
||||||
fmt.Printf("%v\n", response)
|
fmt.Printf("%v\n", response)
|
||||||
|
|
Loading…
Reference in New Issue