Browse Source

Generate PrivValidator file when it doesn't exist already

pull/55/head
Jae Kwon 9 years ago
parent
commit
5e45a849ab
4 changed files with 74 additions and 23 deletions
  1. +23
    -17
      cmd/debora/main.go
  2. +8
    -2
      config/config.go
  3. +34
    -0
      node/id.go
  4. +9
    -4
      node/node.go

+ 23
- 17
cmd/debora/main.go View File

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


+ 8
- 2
config/config.go View File

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


+ 34
- 0
node/id.go View File

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

+ 9
- 4
node/node.go View File

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


Loading…
Cancel
Save