Merge pull request #87 from UdjinM6/110_fix_masternode_conf_strict

make masternode.conf loading more strict
This commit is contained in:
Darkcoin 2014-12-27 07:52:34 -07:00
commit 7418ae7e35
4 changed files with 31 additions and 20 deletions

View File

@ -80,7 +80,11 @@ bool AppInit(int argc, char* argv[])
return false; return false;
} }
masternodeConfig.read(GetMasternodeConfigFile()); std::string strErr;
if(!masternodeConfig.read(GetMasternodeConfigFile(), strErr)) {
fprintf(stderr,"Error reading masternode configuration file: %s\n", strErr.c_str());
return false;
}
// Check for -testnet or -regtest parameter (TestNet() calls are only valid after this clause) // Check for -testnet or -regtest parameter (TestNet() calls are only valid after this clause)
if (!SelectParamsFromCommandLine()) { if (!SelectParamsFromCommandLine()) {

View File

@ -8,10 +8,10 @@ void CMasternodeConfig::add(std::string alias, std::string ip, std::string privK
entries.push_back(cme); entries.push_back(cme);
} }
void CMasternodeConfig::read(boost::filesystem::path path) { bool CMasternodeConfig::read(boost::filesystem::path path, std::string& strErr) {
boost::filesystem::ifstream streamConfig(GetMasternodeConfigFile()); boost::filesystem::ifstream streamConfig(GetMasternodeConfigFile());
if (!streamConfig.good()) { if (!streamConfig.good()) {
return; // No masternode.conf file is OK return true; // No masternode.conf file is OK
} }
for(std::string line; std::getline(streamConfig, line); ) for(std::string line; std::getline(streamConfig, line); )
@ -22,11 +22,13 @@ void CMasternodeConfig::read(boost::filesystem::path path) {
std::istringstream iss(line); std::istringstream iss(line);
std::string alias, ip, privKey, txHash, outputIndex; std::string alias, ip, privKey, txHash, outputIndex;
if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) { if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) {
LogPrintf("CMasternodeConfig::read - Could not parse masternode.conf. Line: %s\n", line.c_str()); strErr = "Could not parse masternode.conf line: " + line;
continue; streamConfig.close();
return false;
} }
add(alias, ip, privKey, txHash, outputIndex); add(alias, ip, privKey, txHash, outputIndex);
} }
streamConfig.close(); streamConfig.close();
return true;
} }

View File

@ -84,7 +84,7 @@ public:
} }
void clear(); void clear();
void read(boost::filesystem::path path); bool read(boost::filesystem::path path, std::string& strErr);
void add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex); void add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex);
std::vector<CMasternodeEntry>& getEntries() { std::vector<CMasternodeEntry>& getEntries() {

View File

@ -534,7 +534,12 @@ int main(int argc, char *argv[])
return false; return false;
} }
masternodeConfig.read(GetMasternodeConfigFile()); string strErr;
if(!masternodeConfig.read(GetMasternodeConfigFile(), strErr)) {
QMessageBox::critical(0, QObject::tr("Darkcoin"),
QObject::tr("Error reading masternode configuration file: %1").arg(strErr.c_str()));
return false;
}
/// 7. Determine network (and switch to network specific options) /// 7. Determine network (and switch to network specific options)
// - Do not call Params() before this step // - Do not call Params() before this step