Exemplo n.º 1
0
func main() {

	args := os.Args[1:]
	if len(args) == 0 {
		fmt.Println(`Tendermint

Commands:
    node            Run the tendermint node
    show_validator  Show this node's validator info
    gen_account     Generate new account keypair
    gen_validator   Generate new validator keypair
    get_account     Get account balance
    send_tx         Sign and publish a SendTx
    probe_upnp      Test UPnP functionality
    version         Show version info
`)
		return
	}

	// Get configuration
	config := tmcfg.GetConfig("")
	parseFlags(config, args[1:]) // Command line overrides
	cfg.ApplyConfig(config)      // Notify modules of new config

	switch args[0] {
	case "node":
		node.RunNode()
	case "show_validator":
		show_validator()
	case "gen_account":
		gen_account()
	case "gen_validator":
		gen_validator()
	case "get_account":
		get_account()
	case "send_tx":
		send_tx()
	case "probe_upnp":
		probe_upnp()
	case "unsafe_reset_priv_validator":
		reset_priv_validator()
	case "version":
		fmt.Println(node.Version)
	default:
		Exit(Fmt("Unknown command %v\n", args[0]))
	}
}
Exemplo n.º 2
0
func main() {
	fmt.Printf("New Barak Process (PID: %d)\n", os.Getpid())

	// Apply bare tendermint/* configuration.
	cfg.ApplyConfig(cfg.MapConfig(map[string]interface{}{"log_level": "info"}))

	// Read options
	optionsFile := parseFlags()
	options := ReadBarakOptions(optionsFile)

	// Init barak
	barak_ = NewBarakFromOptions(options)
	barak_.StartRegisterRoutine()
	barak_.WritePidFile() // This should be last, before TrapSignal().
	TrapSignal(func() {
		fmt.Println("Barak shutting down")
	})
}
Exemplo n.º 3
0
func main() {

	args := os.Args[1:]
	if len(args) == 0 {
		fmt.Println(`Tendermint

Commands:
    node          Run the tendermint node 
    gen_account   Generate new account keypair
    gen_validator Generate new validator keypair
    gen_tx        Generate new transaction
    probe_upnp    Test UPnP functionality
`)
		return
	}

	// Get configuration
	config := tmcfg.GetConfig("")
	parseFlags(config, args[1:]) // Command line overrides
	cfg.ApplyConfig(config)      // Notify modules of new config

	switch args[0] {
	case "node":
		node.RunNode()
	case "gen_account":
		gen_account()
	case "gen_validator":
		gen_validator()
	case "gen_tx":
		gen_tx()
	case "probe_upnp":
		probe_upnp()
	case "unsafe_reset_priv_validator":
		reset_priv_validator()
	default:
		fmt.Printf("Unknown command %v\n", args[0])
	}
}
Exemplo n.º 4
0
func main() {
	fmt.Printf("New Debora Process (PID: %d)\n", os.Getpid())

	// Apply bare tendermint/* configuration.
	cfg.ApplyConfig(cfg.MapConfig(map[string]interface{}{"log_level": "notice"}))

	rootDir := os.Getenv("DEBROOT")
	if rootDir == "" {
		rootDir = os.Getenv("HOME") + "/.debora"
	}

	var (
		groupFlag = cli.StringFlag{
			Name:  "group",
			Value: "default",
			Usage: "uses ~/.debora/<group>.cfg",
		}
		labelFlag = cli.StringFlag{
			Name:  "label",
			Value: "_",
			Usage: "label of the process, or _ by default",
		}
		bgFlag = cli.BoolFlag{
			Name:  "bg",
			Usage: "if set, runs as a background daemon",
		}
		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"
	app.Version = "0.0.1"
	app.Email = "[email protected],[email protected]"
	app.Flags = []cli.Flag{
		groupFlag,
	}
	app.Before = func(c *cli.Context) error {
		configFile := rootDir + "/" + c.String("group") + ".cfg"
		fmt.Printf("Using configuration from %v\n", configFile)
		ReadConfig(configFile)
		return nil
	}
	app.Commands = []cli.Command{
		cli.Command{
			Name:   "status",
			Usage:  "shows remote status",
			Action: cliGetStatus,
		},
		cli.Command{
			Name:   "run",
			Usage:  "run process",
			Action: cliStartProcess,
			Flags: []cli.Flag{
				labelFlag,
				bgFlag,
				inputFlag,
			},
		},
		cli.Command{
			Name:   "stop",
			Usage:  "stop process",
			Action: cliStopProcess,
		},
		cli.Command{
			Name:   "list",
			Usage:  "list processes",
			Action: cliListProcesses,
		},
		cli.Command{
			Name:   "open",
			Usage:  "open barak listener",
			Action: cliOpenListener,
		},
		cli.Command{
			Name:   "close",
			Usage:  "close barka listener",
			Action: cliCloseListener,
		},
		cli.Command{
			Name:   "download",
			Usage:  "download file <remote-path> <local-path-prefix>",
			Action: cliDownloadFile,
		},
		cli.Command{
			Name:   "quit",
			Usage:  "quit barak",
			Action: cliQuit,
		},
	}
	app.Run(os.Args)
}
Exemplo n.º 5
0
func init() {
	// Creates ~/.tendermint_test/*
	config := GetConfig("")
	cfg.ApplyConfig(config)
}
Exemplo n.º 6
0
func main() {
	fmt.Printf("New Barak Process (PID: %d)\n", os.Getpid())

	// Apply bare tendermint/* configuration.
	cfg.ApplyConfig(cfg.MapConfig(map[string]interface{}{"log_level": "info"}))

	// read flags to change options file.
	var optionsBytes []byte
	var optionsFile string
	var err error
	flag.StringVar(&optionsFile, "options-file", "", "Read options from file instead of stdin")
	flag.Parse()
	if optionsFile != "" {
		optionsBytes, err = ioutil.ReadFile(optionsFile)
	} else {
		optionsBytes, err = ioutil.ReadAll(os.Stdin)
	}
	if err != nil {
		panic(Fmt("Error reading input: %v", err))
	}
	options := binary.ReadJSON(&Options{}, optionsBytes, &err).(*Options)
	if err != nil {
		panic(Fmt("Error parsing input: %v", err))
	}
	barak.nonce = options.StartNonce
	barak.validators = options.Validators
	barak.rootDir = os.Getenv("BRKROOT")
	if barak.rootDir == "" {
		barak.rootDir = os.Getenv("HOME") + "/.barak"
	}
	err = EnsureDir(barak.rootDir)
	if err != nil {
		panic(Fmt("Error creating barak rootDir: %v", err))
	}
	barak.registries = options.Registries

	// Debug.
	fmt.Printf("Options: %v\n", options)
	fmt.Printf("Barak: %v\n", barak)

	// Start rpc server.
	mux := http.NewServeMux()
	mux.HandleFunc("/download", ServeFile)
	mux.HandleFunc("/register", Register)
	// TODO: mux.HandleFunc("/upload", UploadFile)
	rpcserver.RegisterRPCFuncs(mux, Routes)
	rpcserver.StartHTTPServer(options.ListenAddress, mux)

	// Register this barak with central listener
	for _, registry := range barak.registries {
		go func(registry string) {
			for {
				resp, err := http.Get(registry + "/register")
				if err != nil {
					fmt.Printf("Error registering to registry %v:\n  %v\n", registry, err)
					time.Sleep(1 * time.Hour)
					continue
				}
				body, _ := ioutil.ReadAll(resp.Body)
				fmt.Printf("Successfully registered with registry %v\n  %v\n", registry, string(body))
				return
			}
		}(registry)
	}

	// Write pid to file.  This should be the last thing before TrapSignal.
	err = WriteFileAtomic(barak.rootDir+"/pidfile", []byte(Fmt("%v", barak.pid)))
	if err != nil {
		panic(Fmt("Error writing pidfile: %v", err))
	}

	TrapSignal(func() {
		fmt.Println("Barak shutting down")
	})
}