예제 #1
0
파일: config.go 프로젝트: jaekwon/GuppyCamp
func GetConfig(rootDir string) cfg.Config {
	rootDir = getTMRoot(rootDir)
	initTMRoot(rootDir)

	var mapConfig = cfg.MapConfig(make(map[string]interface{}))
	configFilePath := path.Join(rootDir, "config.toml")
	configFileBytes := MustReadFile(configFilePath)
	err := toml.Unmarshal(configFileBytes, mapConfig)
	if err != nil {
		Exit(Fmt("Could not read config: %v", err))
	}

	// Set defaults or panic
	if !mapConfig.IsSet("network") {
		Exit("Must set 'network'")
	}
	if mapConfig.IsSet("version") {
		Exit("Cannot set 'version' via config.toml")
	}
	// mapConfig.SetDefault("network", "tendermint_testnet0")
	mapConfig.SetDefault("version", "0.2.1")
	mapConfig.SetDefault("genesis_file", rootDir+"/genesis.json")
	mapConfig.SetDefault("moniker", "anonymous")
	mapConfig.SetDefault("node_laddr", "0.0.0.0:46656")
	// mapConfig.SetDefault("seeds", "goldenalchemist.chaintest.net:46656")
	mapConfig.SetDefault("fast_sync", true)
	mapConfig.SetDefault("addrbook_file", rootDir+"/addrbook.json")
	mapConfig.SetDefault("priv_validator_file", rootDir+"/priv_validator.json")
	mapConfig.SetDefault("db_backend", "leveldb")
	mapConfig.SetDefault("db_dir", rootDir+"/data")
	mapConfig.SetDefault("log_level", "info")
	mapConfig.SetDefault("rpc_laddr", "0.0.0.0:46657")
	return mapConfig
}
예제 #2
0
func GetConfig(rootDir string) cfg.Config {
	rootDir = getTMRoot(rootDir)
	initTMRoot(rootDir)

	var mapConfig = cfg.MapConfig(make(map[string]interface{}))
	configFilePath := path.Join(rootDir, "config.toml")
	configFileBytes := MustReadFile(configFilePath)
	err := toml.Unmarshal(configFileBytes, mapConfig)
	if err != nil {
		Exit(Fmt("Could not read config: %v", err))
	}

	// Set defaults or panic
	if mapConfig.IsSet("chain_id") {
		Exit("Cannot set 'chain_id' via config.toml")
	}
	mapConfig.SetDefault("chain_id", "tendermint_test")
	mapConfig.SetDefault("genesis_file", rootDir+"/genesis.json")
	mapConfig.SetDefault("moniker", "anonymous")
	mapConfig.SetDefault("node_laddr", "0.0.0.0:36656")
	mapConfig.SetDefault("fast_sync", false)
	mapConfig.SetDefault("skip_upnp", true)
	mapConfig.SetDefault("addrbook_file", rootDir+"/addrbook.json")
	mapConfig.SetDefault("priv_validator_file", rootDir+"/priv_validator.json")
	mapConfig.SetDefault("db_backend", "memdb")
	mapConfig.SetDefault("db_dir", rootDir+"/data")
	mapConfig.SetDefault("log_level", "debug")
	mapConfig.SetDefault("vm_log", true)
	mapConfig.SetDefault("rpc_laddr", "0.0.0.0:36657")
	mapConfig.SetDefault("prof_laddr", "")
	mapConfig.SetDefault("revision_file", rootDir+"/revision")
	mapConfig.SetDefault("local_routing", false)
	return mapConfig
}
예제 #3
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")
	})
}
예제 #4
0
파일: config.go 프로젝트: jsp282/tendermint
func GetConfig(rootDir string) cfg.Config {
	rootDir = getTMRoot(rootDir)
	initTMRoot(rootDir)

	var mapConfig = cfg.MapConfig(make(map[string]interface{}))
	configFilePath := path.Join(rootDir, "config.toml")
	configFileBytes := MustReadFile(configFilePath)
	err := toml.Unmarshal(configFileBytes, mapConfig)
	if err != nil {
		Exit(Fmt("Could not read config: %v", err))
	}

	// Set defaults or panic
	if mapConfig.IsSet("chain_id") {
		Exit("Cannot set 'chain_id' via config.toml")
	}
	if mapConfig.IsSet("version") {
		Exit("Cannot set 'version' via config.toml")
	}
	mapConfig.SetDefault("chain_id", "tendermint_testnet_10")
	// Major: alpha
	// Minor: encrypted p2p!
	// Revision: ripemd for NewContractAddress
	mapConfig.SetDefault("version", "0.5.1")
	mapConfig.SetDefault("genesis_file", rootDir+"/genesis.json")
	mapConfig.SetDefault("moniker", "anonymous")
	mapConfig.SetDefault("node_laddr", "0.0.0.0:46656")
	// mapConfig.SetDefault("seeds", "goldenalchemist.chaintest.net:46656")
	mapConfig.SetDefault("fast_sync", true)
	mapConfig.SetDefault("skip_upnp", false)
	mapConfig.SetDefault("addrbook_file", rootDir+"/addrbook.json")
	mapConfig.SetDefault("priv_validator_file", rootDir+"/priv_validator.json")
	mapConfig.SetDefault("db_backend", "leveldb")
	mapConfig.SetDefault("db_dir", rootDir+"/data")
	mapConfig.SetDefault("log_level", "info")
	mapConfig.SetDefault("rpc_laddr", "0.0.0.0:46657")
	mapConfig.SetDefault("revisions_file", rootDir+"/revisions")
	return mapConfig
}
예제 #5
0
파일: main.go 프로젝트: jsp282/tendermint
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)
}
예제 #6
0
파일: main.go 프로젝트: jaekwon/GuppyCamp
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")
	})
}