Ejemplo n.º 1
0
func ReadConfig(filename string) *FactomdConfig {
	if filename == "" {
		filename = ConfigFilename()
	}
	cfg := new(FactomdConfig)

	err := gcfg.ReadStringInto(cfg, defaultConfig)
	if err != nil {
		panic(err)
	}

	err = gcfg.ReadFileInto(cfg, filename)
	if err != nil {
		log.Printfln("Reading from '%s'", filename)
		log.Printfln("Cannot open custom config file,\nStarting with default settings.\n%v\n", err)
		err = gcfg.ReadStringInto(cfg, defaultConfig)
		if err != nil {
			panic(err)
		}
	}

	// Default to home directory if not set
	if len(cfg.App.HomeDir) < 1 {
		cfg.App.HomeDir = GetHomeDir() + "/.factom/m2/"
	} else {
		cfg.App.HomeDir = cfg.App.HomeDir + "/.factom/m2/"
	}
	return cfg
}
Ejemplo n.º 2
0
func ReadConfig(filename string) *FactomdConfig {
	if filename == "" {
		filename = ConfigFilename()
	}
	cfg := new(FactomdConfig)

	// This makes factom config file located at
	//   POSIX (Linux/BSD): ~/.factom/factom.conf
	//   Mac OS: $HOME/Library/Application Support/Factom/factom.conf
	//   Windows: %LOCALAPPDATA%\Factom\factom.conf
	//   Plan 9: $home/factom/factom.conf
	//factomHomeDir := btcutil.AppDataDir("factom", false)
	//defaultConfigFile := filepath.Join(factomHomeDir, "factomd.conf")
	//
	// eventually we need to make data dir as following
	//defaultDataDir   = filepath.Join(factomHomeDir, "data")
	//LdbPath                     = filepath.Join(defaultDataDir, "ldb9")
	//DataStorePath         = filepath.Join(defaultDataDir, "store/seed/")

	err := gcfg.ReadFileInto(cfg, filename)
	if err != nil {
		log.Printfln("Reading from '%s'", filename)
		log.Printfln("ERROR Reading config file!\nServer starting with default settings...\n%v\n", err)
		gcfg.ReadStringInto(cfg, defaultConfig)
	}

	// Default to home directory if not set
	if len(cfg.App.HomeDir) < 1 {
		cfg.App.HomeDir = GetHomeDir() + "/.factom/m2/"
	}

	// TODO: improve the paths after milestone 1
	cfg.App.LdbPath = cfg.App.HomeDir + cfg.App.LdbPath
	cfg.App.BoltDBPath = cfg.App.HomeDir + cfg.App.BoltDBPath
	cfg.App.DataStorePath = cfg.App.HomeDir + cfg.App.DataStorePath
	cfg.Log.LogPath = cfg.App.HomeDir + cfg.Log.LogPath
	cfg.Wallet.BoltDBPath = cfg.App.HomeDir + cfg.Wallet.BoltDBPath
	cfg.App.ExportDataSubpath = cfg.App.HomeDir + cfg.App.ExportDataSubpath

	return cfg
}
Ejemplo n.º 3
0
func (s *State) InitLevelDB() error {
	if s.DB != nil {
		return nil
	}

	cfg := s.Cfg.(*util.FactomdConfig)
	path := cfg.App.LdbPath + "/" + cfg.App.Network + "/" + "factoid_level.db"

	log.Printfln("Creating Database at %v", path)

	dbase, err := hybridDB.NewLevelMapHybridDB(path, false)

	if err != nil || dbase == nil {
		dbase, err = hybridDB.NewLevelMapHybridDB(path, true)
		if err != nil {
			return err
		}
	}

	s.DB = databaseOverlay.NewOverlay(dbase)
	return nil
}
Ejemplo n.º 4
0
func (s *State) Init(filename string) {

	s.ReadCfg(filename)
	// Get our factomd configuration information.
	cfg := s.GetCfg().(*util.FactomdConfig)

	wsapi.InitLogs(cfg.Log.LogPath, cfg.Log.LogLevel)

	s.Logger = logger.NewLogFromConfig(cfg.Log.LogPath, cfg.Log.LogLevel, "State")

	log.SetLevel(cfg.Log.ConsoleLogLevel)

	s.networkInMsgQueue = make(chan interfaces.IMsg, 10000)      //incoming message queue from the network messages
	s.networkInvalidMsgQueue = make(chan interfaces.IMsg, 10000) //incoming message queue from the network messages
	s.networkOutMsgQueue = make(chan interfaces.IMsg, 10000)     //Messages to be broadcast to the network
	s.inMsgQueue = make(chan interfaces.IMsg, 10000)             //incoming message queue for factom application messages
	s.leaderInMsgQueue = make(chan interfaces.IMsg, 10000)       //Leader Messages
	s.followerInMsgQueue = make(chan interfaces.IMsg, 10000)     //Follower Messages

	s.TotalServers = 1

	// Setup the FactoidState and Validation Service that holds factoid and entry credit balances
	fs := new(FactoidState)
	fs.ValidationService = NewValidationService()
	s.FactoidState = fs

	switch cfg.App.NodeMode {
	case "FULL":
		s.ServerState = 0
	case "SERVER":
		s.ServerState = 1
	default:
		panic("Bad Node Mode (must be FULL or SERVER)")
	}

	//Database
	switch cfg.App.DBType {
	case "LDB":
		if err := s.InitLevelDB(); err != nil {
			log.Printfln("Error initializing the database: %v", err)
		}
	case "Bolt":
		if err := s.InitBoltDB(); err != nil {
			log.Printfln("Error initializing the database: %v", err)
		}
	case "Map":
		if err := s.InitMapDB(); err != nil {
			log.Printfln("Error initializing the database: %v", err)
		}
	default:
		panic("No Database type specified")
	}

	if cfg.App.ExportData {
		s.DB.SetExportData(cfg.App.ExportDataSubpath)
	}

	//Network
	switch cfg.App.Network {
	case "MAIN":
		s.NetworkNumber = constants.NETWORK_MAIN
	case "TEST":
		s.NetworkNumber = constants.NETWORK_TEST
	case "LOCAL":
		s.NetworkNumber = constants.NETWORK_LOCAL
	case "CUSTOM":
		s.NetworkNumber = constants.NETWORK_CUSTOM
	default:
		panic("Bad value for Network in factomd.conf")
	}
	s.Holding = make(map[[32]byte]interfaces.IMsg)
	s.Acks = make(map[[32]byte]interfaces.IMsg)

	s.AuditServers = make([]interfaces.IServer, 0)
	s.FedServers = make([]interfaces.IServer, 0)
	s.ServerOrder = make([][]interfaces.IServer, 0)

	s.ProcessList = make([][]interfaces.IMsg, 1)
	s.PLHeight = make([]int, 1)

	s.AuditHeartBeats = make([]interfaces.IMsg, 0)
	s.FedServerFaults = make([][]interfaces.IMsg, 0)

	a, _ := anchor.InitAnchor(s)
	s.Anchor = a

	s.loadDatabase()
	s.initServerKeys()
}