Ejemplo n.º 1
0
// readKeyPair will read both private and public files
// and returns a keypair containing the respective private and public keys
func readKeyFile(keyFile string) (config.KeyPair, string) {
	sec, err := cliutils.ReadPrivKey(suite, namePriv(keyFile))
	if err != nil {
		dbg.Fatal("Could not read private key:", err)
	}
	pub, addr, err := cliutils.ReadPubKey(suite, namePub(keyFile))
	if err != nil {
		dbg.Fatal("Could not read public key:", err)
	}
	return config.KeyPair{
		Suite:  suite,
		Secret: sec,
		Public: pub,
	}, addr
}
Ejemplo n.º 2
0
func createPeer(conf *app.ConfigConode, id int) *conode.Peer {
	// Read the private / public keys + binded address
	keybase := "testdata/key" + strconv.Itoa(id)
	address := ""
	if sec, err := cliutils.ReadPrivKey(suite, keybase+".priv"); err != nil {
		dbg.Fatal("Error reading private key file  :", err)
	} else {
		conf.Secret = sec
	}
	if pub, addr, err := cliutils.ReadPubKey(suite, keybase+".pub"); err != nil {
		dbg.Fatal("Error reading public key file :", err)
	} else {
		conf.Public = pub
		address = addr
	}
	return conode.NewPeer(address, conf)
}
Ejemplo n.º 3
0
// Run will launch the conode server. It takes a config file and a key file
// First parse the key + config file and then run the actual server
func Run(configFile, key string) {
	var address string
	// Read the global config
	conf := &app.ConfigConode{}
	if err := app.ReadTomlConfig(conf, configFile); err != nil {
		dbg.Fatal("Could not read toml config:", err)
	}
	dbg.Lvl1("Configuration file read")
	// Read the private / public keys + binded address
	if sec, err := cliutils.ReadPrivKey(suite, namePriv(key)); err != nil {
		dbg.Fatal("Error reading private key file:", err)
	} else {
		conf.Secret = sec
	}
	if pub, addr, err := cliutils.ReadPubKey(suite, namePub(key)); err != nil {
		dbg.Fatal("Error reading public key file:", err)
	} else {
		conf.Public = pub
		address = addr
	}
	peer := conode.NewPeer(address, conf)
	peer.LoopRounds(RoundStatsType, maxRounds)
}