diff --git a/cmd/barak/main.go b/cmd/barak/main.go index a7bf3a2ce..bfdb66d63 100644 --- a/cmd/barak/main.go +++ b/cmd/barak/main.go @@ -14,7 +14,6 @@ import ( "reflect" "sync" - acm "github.com/tendermint/tendermint/account" "github.com/tendermint/tendermint/binary" . "github.com/tendermint/tendermint/cmd/barak/types" . "github.com/tendermint/tendermint/common" @@ -23,7 +22,7 @@ import ( ) 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" } @@ -128,48 +127,10 @@ func parseValidateCommand(authCommand AuthCommand) (Command, error) { 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 // 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) { 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) { barak.mtx.Lock() proc := barak.processes[label] @@ -215,12 +167,6 @@ func StopProcess(label string, kill bool) (*ResponseStopProcess, error) { return &ResponseStopProcess{}, err } -//-------------------------------------- - -type CommandListProcesses struct{} - -func (_ CommandListProcesses) TypeByte() byte { return typeByteListProcesses } - func ListProcesses() (*ResponseListProcesses, error) { var procs = []*pcm.Process{} barak.mtx.Lock() @@ -234,14 +180,6 @@ func ListProcesses() (*ResponseListProcesses, error) { }, nil } -//------------------------------------------------------------------------------ - -type CommandServeFile struct { - Path string -} - -func (_ CommandServeFile) TypeByte() byte { return typeByteServeFile } - func ServeFile(w http.ResponseWriter, req *http.Request) { authCommandStr := req.FormValue("auth_command") diff --git a/cmd/barak/types/command.go b/cmd/barak/types/command.go new file mode 100644 index 000000000..ff32702b5 --- /dev/null +++ b/cmd/barak/types/command.go @@ -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 +} diff --git a/cmd/barak/auth.go b/cmd/barak/validate.go similarity index 100% rename from cmd/barak/auth.go rename to cmd/barak/validate.go diff --git a/cmd/debora/main.go b/cmd/debora/main.go index 1c265d62f..bc436b862 100644 --- a/cmd/debora/main.go +++ b/cmd/debora/main.go @@ -9,6 +9,10 @@ import ( ) 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{} response2, err := rpc.Call("http://127.0.0.1:8082", "list_processes", Arr(), &response) fmt.Printf("%v\n", response)