Improve configuration handling.

- Make VALIDATORS_SITE configurable.
- At bootstrap load validators.txt with out a unl_default entry.
- Always merge in unl_default at start if available.
This commit is contained in:
Arthur Britto
2012-06-18 11:37:09 -07:00
parent 11241b9077
commit ec008fe76d
6 changed files with 45 additions and 21 deletions

View File

@@ -31,6 +31,12 @@
# Note: $XDG_CONFIG_HOME defaults to $HOME/.config # Note: $XDG_CONFIG_HOME defaults to $HOME/.config
# $XDG_DATA_HOME defaults to $HOME/.local/share # $XDG_DATA_HOME defaults to $HOME/.local/share
# #
# [validators_site]:
# Specifies where to find validators.txt for UNL boostrapping and RPC command unl_network.
# During alpha testing, this defaults to: redstem.com
#
# Example: newcoin.org
#
# [unl_default]: # [unl_default]:
# Specifies how to bootstrap the UNL list. The UNL list is based on a # Specifies how to bootstrap the UNL list. The UNL list is based on a
# validators.txt file and is maintained in the databases. When newcoind # validators.txt file and is maintained in the databases. When newcoind

View File

@@ -28,6 +28,7 @@
#define SECTION_VALIDATION_SEED "validation_seed" #define SECTION_VALIDATION_SEED "validation_seed"
#define SECTION_WEBSOCKET_IP "websocket_ip" #define SECTION_WEBSOCKET_IP "websocket_ip"
#define SECTION_WEBSOCKET_PORT "websocket_port" #define SECTION_WEBSOCKET_PORT "websocket_port"
#define SECTION_VALIDATORS_SITE "validators_site"
// Fees are in XNB. // Fees are in XNB.
#define DEFAULT_FEE_ACCOUNT_CREATE 1000 #define DEFAULT_FEE_ACCOUNT_CREATE 1000
@@ -143,6 +144,8 @@ void Config::setup(const std::string& strConf)
ACCOUNT_PROBE_MAX = 10; ACCOUNT_PROBE_MAX = 10;
VALIDATORS_SITE = DEFAULT_VALIDATORS_SITE;
load(); load();
} }
@@ -170,6 +173,8 @@ void Config::load()
section secConfig = ParseSection(strConfigFile, true); section secConfig = ParseSection(strConfigFile, true);
std::string strTemp; std::string strTemp;
(void) sectionSingleB(secConfig, SECTION_VALIDATORS_SITE, VALIDATORS_SITE);
(void) sectionSingleB(secConfig, SECTION_PEER_IP, PEER_IP); (void) sectionSingleB(secConfig, SECTION_PEER_IP, PEER_IP);
if (sectionSingleB(secConfig, SECTION_PEER_PORT, strTemp)) if (sectionSingleB(secConfig, SECTION_PEER_PORT, strTemp))

View File

@@ -9,7 +9,6 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#define SYSTEM_NAME "newcoin" #define SYSTEM_NAME "newcoin"
#define VALIDATORS_SITE "redstem.com"
#define SYSTEM_CURRENCY_CODE "XNS" #define SYSTEM_CURRENCY_CODE "XNS"
#define SYSTEM_CURRENCY_PRECISION 6 #define SYSTEM_CURRENCY_PRECISION 6
@@ -18,6 +17,7 @@
#define SYSTEM_CURRENCY_PARTS 1000000ull // 10^SYSTEM_CURRENCY_PRECISION #define SYSTEM_CURRENCY_PARTS 1000000ull // 10^SYSTEM_CURRENCY_PRECISION
#define SYSTEM_CURRENCY_START (SYSTEM_CURRENCY_GIFT*SYSTEM_CURRENCY_USERS*SYSTEM_CURRENCY_PARTS) #define SYSTEM_CURRENCY_START (SYSTEM_CURRENCY_GIFT*SYSTEM_CURRENCY_USERS*SYSTEM_CURRENCY_PARTS)
#define DEFAULT_VALIDATORS_SITE "redstem.com"
#define VALIDATORS_FILE_NAME "validators.txt" #define VALIDATORS_FILE_NAME "validators.txt"
const int SYSTEM_PEER_PORT = 6561; const int SYSTEM_PEER_PORT = 6561;
@@ -46,6 +46,9 @@ public:
boost::filesystem::path DATA_DIR; boost::filesystem::path DATA_DIR;
boost::filesystem::path UNL_DEFAULT; boost::filesystem::path UNL_DEFAULT;
// Where to find validators.txt on the Internet.
std::string VALIDATORS_SITE;
// Network parameters // Network parameters
int NETWORK_START_TIME; // The Unix time we start ledger 0 int NETWORK_START_TIME; // The Unix time we start ledger 0
int TRANSACTION_FEE_BASE; int TRANSACTION_FEE_BASE;

View File

@@ -1926,7 +1926,7 @@ Json::Value RPCServer::doUnlList(Json::Value& params)
// Populate the UNL from a local validators.txt file. // Populate the UNL from a local validators.txt file.
Json::Value RPCServer::doUnlLoad(Json::Value& params) Json::Value RPCServer::doUnlLoad(Json::Value& params)
{ {
if (!theApp->getUNL().nodeLoad()) if (theConfig.UNL_DEFAULT.empty() || !theApp->getUNL().nodeLoad(theConfig.UNL_DEFAULT))
{ {
return RPCError(rpcLOAD_FAILED); return RPCError(rpcLOAD_FAILED);
} }

View File

@@ -1485,34 +1485,34 @@ Json::Value UniqueNodeList::getUnlJson()
return ret; return ret;
} }
bool UniqueNodeList::nodeLoad() bool UniqueNodeList::nodeLoad(boost::filesystem::path pConfig)
{ {
if (theConfig.UNL_DEFAULT.empty()) if (pConfig.empty())
{ {
std::cerr << "UNL_DEFAULT not specified." << std::endl; std::cerr << VALIDATORS_FILE_NAME " path not specified." << std::endl;
return false; return false;
} }
if (!boost::filesystem::exists(theConfig.UNL_DEFAULT)) if (!boost::filesystem::exists(pConfig))
{ {
std::cerr << str(boost::format("UNL_DEFAULT not found: %s") % theConfig.UNL_DEFAULT) << std::endl; std::cerr << str(boost::format(VALIDATORS_FILE_NAME " not found: %s") % pConfig) << std::endl;
return false; return false;
} }
if (!boost::filesystem::is_regular_file(theConfig.UNL_DEFAULT)) if (!boost::filesystem::is_regular_file(pConfig))
{ {
std::cerr << str(boost::format("UNL_DEFAULT not regular file: %s") % theConfig.UNL_DEFAULT) << std::endl; std::cerr << str(boost::format(VALIDATORS_FILE_NAME " not regular file: %s") % pConfig) << std::endl;
return false; return false;
} }
std::ifstream ifsDefault(theConfig.UNL_DEFAULT.native().c_str(), std::ios::in); std::ifstream ifsDefault(pConfig.native().c_str(), std::ios::in);
if (!ifsDefault) if (!ifsDefault)
{ {
std::cerr << str(boost::format("Failed to open: %s") % theConfig.UNL_DEFAULT) << std::endl; std::cerr << str(boost::format(VALIDATORS_FILE_NAME " failed to open: %s") % pConfig) << std::endl;
return false; return false;
} }
@@ -1524,14 +1524,14 @@ bool UniqueNodeList::nodeLoad()
if (ifsDefault.bad()) if (ifsDefault.bad())
{ {
std::cerr << str(boost::format("Failed to read: %s") % theConfig.UNL_DEFAULT) << std::endl; std::cerr << str(boost::format("Failed to read: %s") % pConfig) << std::endl;
return false; return false;
} }
nodeDefault(strValidators, theConfig.UNL_DEFAULT.native()); nodeDefault(strValidators, pConfig.native());
std::cerr << str(boost::format("Processing: %s") % theConfig.UNL_DEFAULT) << std::endl; std::cerr << str(boost::format("Processing: %s") % pConfig) << std::endl;
return true; return true;
} }
@@ -1542,7 +1542,7 @@ void UniqueNodeList::validatorsResponse(const boost::system::error_code& err, st
if (!err) if (!err)
{ {
nodeDefault(strResponse, VALIDATORS_SITE); nodeDefault(strResponse, theConfig.VALIDATORS_SITE);
} }
else else
{ {
@@ -1554,7 +1554,7 @@ void UniqueNodeList::nodeNetwork()
{ {
HttpsClient::httpsGet( HttpsClient::httpsGet(
theApp->getIOService(), theApp->getIOService(),
VALIDATORS_SITE, theConfig.VALIDATORS_SITE,
443, 443,
VALIDATORS_FILE_PATH, VALIDATORS_FILE_PATH,
VALIDATORS_FILE_BYTES_MAX, VALIDATORS_FILE_BYTES_MAX,
@@ -1581,16 +1581,26 @@ void UniqueNodeList::nodeBootstrap()
bool bLoaded = iDomains || iNodes; bool bLoaded = iDomains || iNodes;
if (!bLoaded && !theConfig.UNL_DEFAULT.empty()) // Always merge in the file specified in the config.
if (!theConfig.UNL_DEFAULT.empty())
{ {
std::cerr << "Bootstrapping UNL: loading from file." << std::endl; std::cerr << "Bootstrapping UNL: loading from unl_default." << std::endl;
bLoaded = nodeLoad(); bLoaded = nodeLoad(theConfig.UNL_DEFAULT);
}
// If never loaded anything try the current directory.
if (!bLoaded && theConfig.UNL_DEFAULT.empty())
{
std::cerr << "Bootstrapping UNL: loading from '" VALIDATORS_FILE_NAME "'." << std::endl;
bLoaded = nodeLoad(VALIDATORS_FILE_NAME);
} }
if (!bLoaded) if (!bLoaded)
{ {
std::cerr << "Bootstrapping UNL: loading from " VALIDATORS_SITE "." << std::endl; std::cerr << "Bootstrapping UNL: loading from " << theConfig.VALIDATORS_SITE << "." << std::endl;
nodeNetwork(); nodeNetwork();
} }
} }

View File

@@ -151,7 +151,7 @@ public:
bool nodeInUNL(const NewcoinAddress& naNodePublic); bool nodeInUNL(const NewcoinAddress& naNodePublic);
void nodeBootstrap(); void nodeBootstrap();
bool nodeLoad(); bool nodeLoad(boost::filesystem::path pConfig);
void nodeNetwork(); void nodeNetwork();
Json::Value getUnlJson(); Json::Value getUnlJson();