Browse Source

refactoring barak

pull/55/head
Jae Kwon 10 years ago
parent
commit
dcdf74ccc2
4 changed files with 65 additions and 63 deletions
  1. +1
    -63
      cmd/barak/main.go
  2. +60
    -0
      cmd/barak/types/command.go
  3. +0
    -0
      cmd/barak/validate.go
  4. +4
    -0
      cmd/debora/main.go

+ 1
- 63
cmd/barak/main.go View File

@ -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")


+ 60
- 0
cmd/barak/types/command.go View File

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

cmd/barak/auth.go → cmd/barak/validate.go View File


+ 4
- 0
cmd/debora/main.go View File

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


Loading…
Cancel
Save