From 5e45a849abb2ce8efb7dcb026d38c1866b0542ad Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Sat, 18 Apr 2015 14:46:44 -0700 Subject: [PATCH] Generate PrivValidator file when it doesn't exist already --- cmd/debora/main.go | 40 +++++++++++++++++++++++----------------- config/config.go | 10 ++++++++-- node/id.go | 34 ++++++++++++++++++++++++++++++++++ node/node.go | 13 +++++++++---- 4 files changed, 74 insertions(+), 23 deletions(-) create mode 100644 node/id.go diff --git a/cmd/debora/main.go b/cmd/debora/main.go index 9c634ffcd..47d0fe4b1 100644 --- a/cmd/debora/main.go +++ b/cmd/debora/main.go @@ -17,25 +17,31 @@ var Config = struct { PrivKey acm.PrivKey }{} -var ( - configFlag = cli.StringFlag{ - Name: "config-file", - Value: ".debora/config.json", - Usage: "config file", - } - waitFlag = cli.BoolFlag{ - Name: "wait", - Usage: "whether to wait for termination", - } - inputFlag = cli.StringFlag{ - Name: "input", - Value: "", - Usage: "input to the program (e.g. stdin)", - } -) - func main() { fmt.Printf("New Debora Process (PID: %d)\n", os.Getpid()) + + rootDir := os.Getenv("DEBROOT") + if rootDir == "" { + rootDir = os.Getenv("HOME") + "/.debora" + } + + var ( + configFlag = cli.StringFlag{ + Name: "config-file", + Value: rootDir + "/config.json", + Usage: "config file", + } + waitFlag = cli.BoolFlag{ + Name: "wait", + Usage: "whether to wait for termination", + } + inputFlag = cli.StringFlag{ + Name: "input", + Value: "", + Usage: "input to the program (e.g. stdin)", + } + ) + app := cli.NewApp() app.Name = "debora" app.Usage = "summons commands to barak" diff --git a/config/config.go b/config/config.go index 23ed290b5..50a7292f5 100644 --- a/config/config.go +++ b/config/config.go @@ -20,7 +20,7 @@ func App() *confer.Config { appMtx.Lock() defer appMtx.Unlock() if app == nil { - Init(".tendermint") + Init("") } return app } @@ -104,7 +104,13 @@ func initDefaults(rootDir string) { func Init(rootDir string) { - // Get RootDir + // Get rootdir + if rootDir == "" { + rootDir = os.Getenv("TMROOT") + } + if rootDir == "" { + rootDir = os.Getenv("HOME") + "/.tendermint" + } configFile := path.Join(rootDir, "config.toml") genesisFile := path.Join(rootDir, "genesis.json") diff --git a/node/id.go b/node/id.go new file mode 100644 index 000000000..b65ea4ac1 --- /dev/null +++ b/node/id.go @@ -0,0 +1,34 @@ +package node + +import ( + acm "github.com/tendermint/tendermint/account" + "time" +) + +type NodeID struct { + Name string + PubKey acm.PubKey +} + +type PrivNodeID struct { + NodeID + PrivKey acm.PrivKey +} + +type NodeGreeting struct { + NodeID + Version string + Network string + Message string + Time time.Time +} + +type SignedNodeGreeting struct { + NodeGreeting + Signature acm.Signature +} + +func (pnid *PrivNodeID) SignGreeting() *SignedNodeGreeting { + //greeting := NodeGreeting{} + return nil +} diff --git a/node/node.go b/node/node.go index a4071752a..df5bd5a26 100644 --- a/node/node.go +++ b/node/node.go @@ -45,11 +45,16 @@ func NewNode() *Node { // Get PrivValidator var privValidator *sm.PrivValidator - if _, err := os.Stat(config.App().GetString("PrivValidatorFile")); err == nil { - privValidator = sm.LoadPrivValidator(config.App().GetString("PrivValidatorFile")) - log.Info("Loaded PrivValidator", "file", config.App().GetString("PrivValidatorFile"), "privValidator", privValidator) + privValidatorFile := config.App().GetString("PrivValidatorFile") + if _, err := os.Stat(privValidatorFile); err == nil { + privValidator = sm.LoadPrivValidator(privValidatorFile) + log.Info("Loaded PrivValidator", + "file", privValidatorFile, "privValidator", privValidator) } else { - log.Info("No PrivValidator found", "file", config.App().GetString("PrivValidatorFile")) + privValidator = sm.GenPrivValidator() + privValidator.SetFile(privValidatorFile) + privValidator.Save() + log.Info("Generated PrivValidator", "file", privValidatorFile) } eventSwitch := new(events.EventSwitch)