Add support [validators] in newcoind.cfg.

This commit is contained in:
Arthur Britto
2012-06-18 14:13:06 -07:00
parent ec008fe76d
commit 8f74e5bf07
7 changed files with 74 additions and 29 deletions

View File

@@ -692,10 +692,11 @@ void UniqueNodeList::processIps(const std::string& strSite, const NewcoinAddress
// --> strValidatorsSrc: source details for display
// --> naNodePublic: remote source public key - not valid for local
// --> vsWhy: reason for adding validator to SeedDomains or SeedNodes.
void UniqueNodeList::processValidators(const std::string& strSite, const std::string& strValidatorsSrc, const NewcoinAddress& naNodePublic, validatorSource vsWhy, section::mapped_type* pmtVecStrValidators)
int UniqueNodeList::processValidators(const std::string& strSite, const std::string& strValidatorsSrc, const NewcoinAddress& naNodePublic, validatorSource vsWhy, section::mapped_type* pmtVecStrValidators)
{
Database* db = theApp->getWalletDB()->getDB();
std::string strNodePublic = naNodePublic.isValid() ? naNodePublic.humanNodePublic() : "local";
std::string strNodePublic = naNodePublic.isValid() ? naNodePublic.humanNodePublic() : strValidatorsSrc;
int iValues = 0;
std::cerr
<< str(boost::format("Validator: '%s' : '%s' : processing %d validators.")
@@ -718,7 +719,6 @@ void UniqueNodeList::processValidators(const std::string& strSite, const std::st
vstrValues.reserve(MIN(pmtVecStrValidators->size(), REFERRAL_VALIDATORS_MAX));
int iValues = 0;
BOOST_FOREACH(std::string strReferral, *pmtVecStrValidators)
{
if (iValues == REFERRAL_VALIDATORS_MAX)
@@ -734,7 +734,7 @@ void UniqueNodeList::processValidators(const std::string& strSite, const std::st
if (!boost::regex_match(strReferral, smMatch, reReferral))
{
std::cerr
<< str(boost::format("Validator: '%s' ["SECTION_VALIDATORS"]: rejecting '%s'")
<< str(boost::format("Validator: '%s' ["SECTION_VALIDATORS"]: rejecting line: '%s'")
% strSite % strReferral)
<< std::endl;
}
@@ -744,7 +744,7 @@ void UniqueNodeList::processValidators(const std::string& strSite, const std::st
std::string strComment = smMatch[2];
NewcoinAddress naValidator;
// std::cerr << str(boost::format("Validator: '%s' : '%s'") % strRefered % strComment) << std::endl;
std::cerr << str(boost::format("Validator='%s', Comment='%s'") % strRefered % strComment) << std::endl;
if (naValidator.setNodePublic(strRefered))
{
@@ -781,6 +781,8 @@ void UniqueNodeList::processValidators(const std::string& strSite, const std::st
}
fetchDirty();
return iValues;
}
// Given a section with IPs, parse and persist it for a validator.
@@ -823,7 +825,7 @@ void UniqueNodeList::getIpsUrl(const NewcoinAddress& naNodePublic, section secSi
}
}
// Given a section with validators, parse and persist it.
// After fetching a newcoin.txt from a web site, given a section with validators, parse and persist it.
void UniqueNodeList::responseValidators(const std::string& strValidatorsUrl, const NewcoinAddress& naNodePublic, section secSite, const std::string& strSite, const boost::system::error_code& err, const std::string strValidatorsFile)
{
if (!err)
@@ -1137,10 +1139,11 @@ int UniqueNodeList::iSourceScore(validatorSource vsWhy)
int iScore = 0;
switch (vsWhy) {
case vsConfig: iScore = 1500; break;
case vsManual: iScore = 1500; break;
case vsReferral: iScore = 0; break;
case vsValidator: iScore = 1000; break;
case vsWeb: iScore = 200; break;
case vsReferral: iScore = 0; break;
default:
throw std::runtime_error("Internal error: bad validatorSource.");
}
@@ -1529,7 +1532,7 @@ bool UniqueNodeList::nodeLoad(boost::filesystem::path pConfig)
return false;
}
nodeDefault(strValidators, pConfig.native());
nodeProcess("local", strValidators, pConfig.native());
std::cerr << str(boost::format("Processing: %s") % pConfig) << std::endl;
@@ -1542,7 +1545,7 @@ void UniqueNodeList::validatorsResponse(const boost::system::error_code& err, st
if (!err)
{
nodeDefault(strResponse, theConfig.VALIDATORS_SITE);
nodeProcess("network", strResponse, theConfig.VALIDATORS_SITE);
}
else
{
@@ -1597,6 +1600,17 @@ void UniqueNodeList::nodeBootstrap()
bLoaded = nodeLoad(VALIDATORS_FILE_NAME);
}
// Always load from newcoind.cfg
if (!theConfig.VALIDATORS.empty())
{
NewcoinAddress naInvalid; // Don't want a referrer on added entries.
std::cerr << "Bootstrapping UNL: loading from " CONFIG_FILE_NAME "." << std::endl;
if (processValidators("local", CONFIG_FILE_NAME, naInvalid, vsConfig, &theConfig.VALIDATORS))
bLoaded = true;
}
if (!bLoaded)
{
std::cerr << "Bootstrapping UNL: loading from " << theConfig.VALIDATORS_SITE << "." << std::endl;
@@ -1606,8 +1620,9 @@ void UniqueNodeList::nodeBootstrap()
}
// Process a validators.txt.
// --> strSite: source of validators
// --> strValidators: contents of a validators.txt
void UniqueNodeList::nodeDefault(const std::string& strValidators, const std::string& strSource) {
void UniqueNodeList::nodeProcess(const std::string& strSite, const std::string& strValidators, const std::string& strSource) {
section secValidators = ParseSection(strValidators, true);
section::mapped_type* pmtEntries = sectionEntries(secValidators, SECTION_VALIDATORS);
@@ -1616,7 +1631,7 @@ void UniqueNodeList::nodeDefault(const std::string& strValidators, const std::st
NewcoinAddress naInvalid; // Don't want a referrer on added entries.
// YYY Unspecified might be bootstrap or rpc command
processValidators("unspecified", strSource, naInvalid, vsValidator, pmtEntries);
processValidators(strSite, strSource, naInvalid, vsValidator, pmtEntries);
}
else
{