void Config::load () { if (!QUIET) Log::out() << "Loading: " << CONFIG_FILE; std::ifstream ifsConfig (CONFIG_FILE.c_str (), std::ios::in); if (!ifsConfig) { Log::out() << "Failed to open '" << CONFIG_FILE << "'."; } else { std::string strConfigFile; strConfigFile.assign ((std::istreambuf_iterator<char> (ifsConfig)), std::istreambuf_iterator<char> ()); if (ifsConfig.bad ()) { Log::out() << "Failed to read '" << CONFIG_FILE << "'."; } else { Section secConfig = ParseSection (strConfigFile, true); std::string strTemp; // XXX Leak Section::mapped_type* smtTmp; smtTmp = SectionEntries (secConfig, SECTION_VALIDATORS); if (smtTmp) { validators = *smtTmp; // SectionEntriesPrint(&validators, SECTION_VALIDATORS); } smtTmp = SectionEntries (secConfig, SECTION_CLUSTER_NODES); if (smtTmp) { CLUSTER_NODES = *smtTmp; // SectionEntriesPrint(&CLUSTER_NODES, SECTION_CLUSTER_NODES); } smtTmp = SectionEntries (secConfig, SECTION_IPS); if (smtTmp) { IPS = *smtTmp; // SectionEntriesPrint(&IPS, SECTION_IPS); } smtTmp = SectionEntries (secConfig, SECTION_SNTP); if (smtTmp) { SNTP_SERVERS = *smtTmp; } smtTmp = SectionEntries (secConfig, SECTION_RPC_STARTUP); if (smtTmp) { RPC_STARTUP = Json::arrayValue; BOOST_FOREACH (const std::string & strJson, *smtTmp) { Json::Reader jrReader; Json::Value jvCommand; if (!jrReader.parse (strJson, jvCommand)) throw std::runtime_error (boost::str (boost::format ("Couldn't parse [" SECTION_RPC_STARTUP "] command: %s") % strJson)); RPC_STARTUP.append (jvCommand); } } if (SectionSingleB (secConfig, SECTION_DATABASE_PATH, DATABASE_PATH)) DATA_DIR = DATABASE_PATH; (void) SectionSingleB (secConfig, SECTION_VALIDATORS_SITE, VALIDATORS_SITE); (void) SectionSingleB (secConfig, SECTION_PEER_IP, PEER_IP); if (SectionSingleB (secConfig, SECTION_PEER_PRIVATE, strTemp)) PEER_PRIVATE = lexicalCastThrow <bool> (strTemp); smtTmp = SectionEntries (secConfig, SECTION_RPC_ADMIN_ALLOW); if (smtTmp) { RPC_ADMIN_ALLOW = *smtTmp; } (void) SectionSingleB (secConfig, SECTION_RPC_ADMIN_PASSWORD, RPC_ADMIN_PASSWORD); (void) SectionSingleB (secConfig, SECTION_RPC_ADMIN_USER, RPC_ADMIN_USER); (void) SectionSingleB (secConfig, SECTION_RPC_IP, m_rpcIP); (void) SectionSingleB (secConfig, SECTION_RPC_PASSWORD, RPC_PASSWORD); (void) SectionSingleB (secConfig, SECTION_RPC_USER, RPC_USER); //--------------------------------------- // // VFALCO BEGIN CLEAN // nodeDatabase = parseKeyValueSection ( secConfig, ConfigSection::nodeDatabase ()); ephemeralNodeDatabase = parseKeyValueSection ( secConfig, ConfigSection::tempNodeDatabase ()); importNodeDatabase = parseKeyValueSection ( secConfig, ConfigSection::importNodeDatabase ()); if (SectionSingleB (secConfig, SECTION_PEER_PORT, strTemp)) peerListeningPort = lexicalCastThrow <int> (strTemp); if (SectionSingleB (secConfig, SECTION_PEER_PROXY_PORT, strTemp)) { peerPROXYListeningPort = lexicalCastThrow <int> (strTemp); if (peerPROXYListeningPort != 0 && peerPROXYListeningPort == peerListeningPort) FatalError ("Peer and proxy listening ports can't be the same.", __FILE__, __LINE__); } else { peerPROXYListeningPort = 0; } // // VFALCO END CLEAN // //--------------------------------------- if (SectionSingleB (secConfig, SECTION_RPC_PORT, strTemp)) m_rpcPort = lexicalCastThrow <int> (strTemp); if (SectionSingleB (secConfig, "ledger_creator" , strTemp)) LEDGER_CREATOR = lexicalCastThrow <bool> (strTemp); if (SectionSingleB (secConfig, SECTION_RPC_ALLOW_REMOTE, strTemp)) RPC_ALLOW_REMOTE = lexicalCastThrow <bool> (strTemp); if (SectionSingleB (secConfig, SECTION_NODE_SIZE, strTemp)) { if (strTemp == "tiny") NODE_SIZE = 0; else if (strTemp == "small") NODE_SIZE = 1; else if (strTemp == "medium") NODE_SIZE = 2; else if (strTemp == "large") NODE_SIZE = 3; else if (strTemp == "huge") NODE_SIZE = 4; else { NODE_SIZE = lexicalCastThrow <int> (strTemp); if (NODE_SIZE < 0) NODE_SIZE = 0; else if (NODE_SIZE > 4) NODE_SIZE = 4; } } if (SectionSingleB (secConfig, SECTION_ELB_SUPPORT, strTemp)) ELB_SUPPORT = lexicalCastThrow <bool> (strTemp); (void) SectionSingleB (secConfig, SECTION_WEBSOCKET_IP, WEBSOCKET_IP); if (SectionSingleB (secConfig, SECTION_WEBSOCKET_PORT, strTemp)) WEBSOCKET_PORT = lexicalCastThrow <int> (strTemp); (void) SectionSingleB (secConfig, SECTION_WEBSOCKET_PUBLIC_IP, WEBSOCKET_PUBLIC_IP); if (SectionSingleB (secConfig, SECTION_WEBSOCKET_PUBLIC_PORT, strTemp)) WEBSOCKET_PUBLIC_PORT = lexicalCastThrow <int> (strTemp); if (SectionSingleB (secConfig, SECTION_WEBSOCKET_SECURE, strTemp)) WEBSOCKET_SECURE = lexicalCastThrow <int> (strTemp); if (SectionSingleB (secConfig, SECTION_WEBSOCKET_PUBLIC_SECURE, strTemp)) WEBSOCKET_PUBLIC_SECURE = lexicalCastThrow <int> (strTemp); if (SectionSingleB (secConfig, SECTION_WEBSOCKET_PING_FREQ, strTemp)) WEBSOCKET_PING_FREQ = lexicalCastThrow <int> (strTemp); SectionSingleB (secConfig, SECTION_WEBSOCKET_SSL_CERT, WEBSOCKET_SSL_CERT); SectionSingleB (secConfig, SECTION_WEBSOCKET_SSL_CHAIN, WEBSOCKET_SSL_CHAIN); SectionSingleB (secConfig, SECTION_WEBSOCKET_SSL_KEY, WEBSOCKET_SSL_KEY); if (SectionSingleB (secConfig, SECTION_RPC_SECURE, strTemp)) RPC_SECURE = lexicalCastThrow <int> (strTemp); SectionSingleB (secConfig, SECTION_RPC_SSL_CERT, RPC_SSL_CERT); SectionSingleB (secConfig, SECTION_RPC_SSL_CHAIN, RPC_SSL_CHAIN); SectionSingleB (secConfig, SECTION_RPC_SSL_KEY, RPC_SSL_KEY); SectionSingleB (secConfig, SECTION_SSL_VERIFY_FILE, SSL_VERIFY_FILE); SectionSingleB (secConfig, SECTION_SSL_VERIFY_DIR, SSL_VERIFY_DIR); if (SectionSingleB (secConfig, SECTION_SSL_VERIFY, strTemp)) SSL_VERIFY = lexicalCastThrow <bool> (strTemp); if (SectionSingleB (secConfig, SECTION_VALIDATION_SEED, strTemp)) { VALIDATION_SEED.setSeedGeneric (strTemp); if (VALIDATION_SEED.isValid ()) { VALIDATION_PUB = RippleAddress::createNodePublic (VALIDATION_SEED); VALIDATION_PRIV = RippleAddress::createNodePrivate (VALIDATION_SEED); } } if (SectionSingleB (secConfig, SECTION_NODE_SEED, strTemp)) { NODE_SEED.setSeedGeneric (strTemp); if (NODE_SEED.isValid ()) { NODE_PUB = RippleAddress::createNodePublic (NODE_SEED); NODE_PRIV = RippleAddress::createNodePrivate (NODE_SEED); } } (void) SectionSingleB (secConfig, SECTION_PEER_SSL_CIPHER_LIST, PEER_SSL_CIPHER_LIST); if (SectionSingleB (secConfig, SECTION_PEER_SCAN_INTERVAL_MIN, strTemp)) // Minimum for min is 60 seconds. PEER_SCAN_INTERVAL_MIN = std::max (60, lexicalCastThrow <int> (strTemp)); if (SectionSingleB (secConfig, SECTION_PEER_START_MAX, strTemp)) PEER_START_MAX = std::max (1, lexicalCastThrow <int> (strTemp)); if (SectionSingleB (secConfig, SECTION_PEER_CONNECT_LOW_WATER, strTemp)) PEER_CONNECT_LOW_WATER = std::max (1, lexicalCastThrow <int> (strTemp)); if (SectionSingleB (secConfig, SECTION_NETWORK_QUORUM, strTemp)) NETWORK_QUORUM = std::max (0, lexicalCastThrow <int> (strTemp)); if (SectionSingleB (secConfig, SECTION_VALIDATION_QUORUM, strTemp)) VALIDATION_QUORUM = std::max (0, lexicalCastThrow <int> (strTemp)); if (SectionSingleB (secConfig, SECTION_FEE_ACCOUNT_RESERVE, strTemp)) FEE_ACCOUNT_RESERVE = lexicalCastThrow <uint64> (strTemp); if (SectionSingleB (secConfig, SECTION_FEE_OWNER_RESERVE, strTemp)) FEE_OWNER_RESERVE = lexicalCastThrow <uint64> (strTemp); if (SectionSingleB (secConfig, SECTION_FEE_NICKNAME_CREATE, strTemp)) FEE_NICKNAME_CREATE = lexicalCastThrow <int> (strTemp); if (SectionSingleB (secConfig, SECTION_FEE_OFFER, strTemp)) FEE_OFFER = lexicalCastThrow <int> (strTemp); if (SectionSingleB (secConfig, SECTION_FEE_DEFAULT, strTemp)) FEE_DEFAULT = lexicalCastThrow <int> (strTemp); if (SectionSingleB (secConfig, SECTION_FEE_OPERATION, strTemp)) FEE_CONTRACT_OPERATION = lexicalCastThrow <int> (strTemp); if (SectionSingleB (secConfig, SECTION_LEDGER_HISTORY, strTemp)) { boost::to_lower (strTemp); if (strTemp == "none") LEDGER_HISTORY = 0; else if (strTemp == "full") LEDGER_HISTORY = 1000000000u; else LEDGER_HISTORY = lexicalCastThrow <uint32> (strTemp); } if (SectionSingleB (secConfig, SECTION_PATH_SEARCH_OLD, strTemp)) PATH_SEARCH_OLD = lexicalCastThrow <int> (strTemp); if (SectionSingleB (secConfig, SECTION_PATH_SEARCH, strTemp)) PATH_SEARCH = lexicalCastThrow <int> (strTemp); if (SectionSingleB (secConfig, SECTION_PATH_SEARCH_FAST, strTemp)) PATH_SEARCH_FAST = lexicalCastThrow <int> (strTemp); if (SectionSingleB (secConfig, SECTION_PATH_SEARCH_MAX, strTemp)) PATH_SEARCH_MAX = lexicalCastThrow <int> (strTemp); if (SectionSingleB (secConfig, SECTION_ACCOUNT_PROBE_MAX, strTemp)) ACCOUNT_PROBE_MAX = lexicalCastThrow <int> (strTemp); (void) SectionSingleB (secConfig, SECTION_SMS_FROM, SMS_FROM); (void) SectionSingleB (secConfig, SECTION_SMS_KEY, SMS_KEY); (void) SectionSingleB (secConfig, SECTION_SMS_SECRET, SMS_SECRET); (void) SectionSingleB (secConfig, SECTION_SMS_TO, SMS_TO); (void) SectionSingleB (secConfig, SECTION_SMS_URL, SMS_URL); if (SectionSingleB (secConfig, SECTION_VALIDATORS_FILE, strTemp)) { VALIDATORS_FILE = strTemp; } if (SectionSingleB (secConfig, SECTION_DEBUG_LOGFILE, strTemp)) DEBUG_LOGFILE = strTemp; } } }
void Config::load () { if (!QUIET) std::cerr << "Loading: " << CONFIG_FILE << "\n"; std::ifstream ifsConfig (CONFIG_FILE.c_str (), std::ios::in); if (!ifsConfig) { std::cerr << "Failed to open '" << CONFIG_FILE << "'." << std::endl; return; } std::string fileContents; fileContents.assign ((std::istreambuf_iterator<char>(ifsConfig)), std::istreambuf_iterator<char>()); if (ifsConfig.bad ()) { std::cerr << "Failed to read '" << CONFIG_FILE << "'." << std::endl; return; } loadFromString (fileContents); }