mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Use newcoind.cfg instead of config.xml
This commit is contained in:
@@ -126,7 +126,7 @@ Json::Value callRPC(const std::string& strMethod, const Json::Value& params)
|
||||
// Connect to localhost
|
||||
|
||||
std::cout << "Connecting to port:" << theConfig.RPC_PORT << std::endl;
|
||||
ip::tcp::endpoint endpoint( ip::address::from_string("127.0.0.1"), theConfig.RPC_PORT);
|
||||
ip::tcp::endpoint endpoint(ip::address::from_string(theConfig.RPC_IP), theConfig.RPC_PORT);
|
||||
ip::tcp::iostream stream;
|
||||
stream.connect(endpoint);
|
||||
if(stream.fail())
|
||||
@@ -142,11 +142,11 @@ Json::Value callRPC(const std::string& strMethod, const Json::Value& params)
|
||||
|
||||
// Send request
|
||||
std::string strRequest = JSONRPCRequest(strMethod, params, Json::Value(1));
|
||||
std::cout << "send request " << strMethod << " : " << strRequest << std::endl;
|
||||
std::cout << "send request " << strMethod << " : " << strRequest << std::endl;
|
||||
std::string strPost = createHTTPPost(strRequest, mapRequestHeaders);
|
||||
stream << strPost << std::flush;
|
||||
|
||||
std::cout << "post " << strPost << std::endl;
|
||||
std::cout << "post " << strPost << std::endl;
|
||||
|
||||
// Receive reply
|
||||
std::map<std::string, std::string> mapHeaders;
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
#include "Config.h"
|
||||
#include "../util/pugixml.hpp"
|
||||
|
||||
#include "ParseSection.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
using namespace pugi;
|
||||
#define CONFIG_FILE_NAME "newcoind.cfg"
|
||||
#define SECTION_PEER_IP "peer_ip"
|
||||
#define SECTION_PEER_PORT "peer_port"
|
||||
#define SECTION_RPC_IP "rpc_ip"
|
||||
#define SECTION_RPC_PORT "rpc_port"
|
||||
#define SECTION_VALIDATION_PASSWORD "validation_password"
|
||||
#define SECTION_VALIDATION_KEY "validation_key"
|
||||
|
||||
Config theConfig;
|
||||
|
||||
@@ -17,7 +25,7 @@ Config::Config()
|
||||
PEER_PORT=6561;
|
||||
RPC_PORT=5001;
|
||||
NUMBER_CONNECTIONS=30;
|
||||
|
||||
|
||||
// a new ledger every 30 min
|
||||
LEDGER_SECONDS=(60*30);
|
||||
|
||||
@@ -31,16 +39,42 @@ Config::Config()
|
||||
|
||||
void Config::load()
|
||||
{
|
||||
|
||||
xml_document doc;
|
||||
xml_parse_result result = doc.load_file("config.xml");
|
||||
xml_node root=doc.child("config");
|
||||
std::ifstream ifsConfig(CONFIG_FILE_NAME, std::ios::in);
|
||||
|
||||
xml_node node= root.child("PEER_PORT");
|
||||
if(!node.empty()) PEER_PORT=boost::lexical_cast<int>(node.child_value());
|
||||
if (!ifsConfig)
|
||||
{
|
||||
std::cerr << "Failed to open '" CONFIG_FILE_NAME "'." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string strConfigFile;
|
||||
|
||||
node= root.child("RPC_PORT");
|
||||
if(!node.empty()) RPC_PORT=boost::lexical_cast<int>(node.child_value());
|
||||
strConfigFile.assign((std::istreambuf_iterator<char>(ifsConfig)),
|
||||
std::istreambuf_iterator<char>());
|
||||
|
||||
if (ifsConfig.bad())
|
||||
{
|
||||
std::cerr << "Failed to read '" CONFIG_FILE_NAME "'." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
section secConfig = ParseSection(strConfigFile, true);
|
||||
std::string strTemp;
|
||||
|
||||
(void) sectionSingleB(secConfig, SECTION_PEER_IP, PEER_IP);
|
||||
|
||||
if (sectionSingleB(secConfig, SECTION_PEER_PORT, strTemp))
|
||||
PEER_PORT=boost::lexical_cast<int>(strTemp);
|
||||
|
||||
(void) sectionSingleB(secConfig, SECTION_RPC_IP, RPC_IP);
|
||||
|
||||
if (sectionSingleB(secConfig, SECTION_RPC_PORT, strTemp))
|
||||
RPC_PORT=boost::lexical_cast<int>(strTemp);
|
||||
|
||||
(void) sectionSingleB(secConfig, SECTION_VALIDATION_PASSWORD, VALIDATION_PASSWORD);
|
||||
(void) sectionSingleB(secConfig, SECTION_VALIDATION_KEY, VALIDATION_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
node=root.child("DB_TYPE");
|
||||
@@ -51,3 +85,5 @@ void Config::load()
|
||||
}else */
|
||||
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -20,6 +20,7 @@ public:
|
||||
float BELIEF_PERCENT;
|
||||
|
||||
// node networking parameters
|
||||
std::string PEER_IP;
|
||||
int PEER_PORT;
|
||||
int NUMBER_CONNECTIONS;
|
||||
bool NODE_INBOUND; // we accept inbound connections
|
||||
@@ -31,10 +32,14 @@ public:
|
||||
std::string HANKO_PRIVATE;
|
||||
|
||||
// RPC parameters
|
||||
std::string RPC_IP;
|
||||
int RPC_PORT;
|
||||
std::string RPC_USER;
|
||||
std::string RPC_PASSWORD;
|
||||
|
||||
std::string VALIDATION_PASSWORD;
|
||||
std::string VALIDATION_KEY;
|
||||
|
||||
// configuration parameters
|
||||
std::string DATA_DIR;
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
using namespace std;
|
||||
using namespace boost::asio::ip;
|
||||
|
||||
PeerDoor::PeerDoor(boost::asio::io_service& io_service) :
|
||||
mAcceptor(io_service, tcp::endpoint(tcp::v4(), theConfig.PEER_PORT))
|
||||
PeerDoor::PeerDoor(boost::asio::io_service& io_service) :
|
||||
mAcceptor(io_service, tcp::endpoint(address().from_string(theConfig.PEER_IP), theConfig.PEER_PORT))
|
||||
{
|
||||
cout << "Opening peer door on port: " << theConfig.PEER_PORT << endl;
|
||||
startListening();
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
using namespace std;
|
||||
using namespace boost::asio::ip;
|
||||
|
||||
RPCDoor::RPCDoor(boost::asio::io_service& io_service) :
|
||||
mAcceptor(io_service, tcp::endpoint(boost::asio::ip::address_v4::loopback(), theConfig.RPC_PORT))
|
||||
RPCDoor::RPCDoor(boost::asio::io_service& io_service) :
|
||||
mAcceptor(io_service, tcp::endpoint(address::from_string(theConfig.RPC_IP), theConfig.RPC_PORT))
|
||||
{
|
||||
cout << "Opening rpc door on port: " << theConfig.RPC_PORT << endl;
|
||||
startListening();
|
||||
|
||||
@@ -558,7 +558,7 @@ Json::Value RPCServer::doUnlDefault(Json::Value& params) {
|
||||
|
||||
if (!ifsDefault)
|
||||
{
|
||||
std::cerr << "Failed to read '" VALIDATORS_FILE_NAME "'." << std::endl;
|
||||
std::cerr << "Failed to open '" VALIDATORS_FILE_NAME "'." << std::endl;
|
||||
|
||||
bNetwork = true;
|
||||
}
|
||||
@@ -566,6 +566,13 @@ Json::Value RPCServer::doUnlDefault(Json::Value& params) {
|
||||
{
|
||||
strValidators.assign((std::istreambuf_iterator<char>(ifsDefault)),
|
||||
std::istreambuf_iterator<char>());
|
||||
|
||||
if (ifsDefault.bad())
|
||||
{
|
||||
std::cerr << "Failed to read '" VALIDATORS_FILE_NAME "'." << std::endl;
|
||||
|
||||
bNetwork = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,6 @@ void UniqueNodeList::responseFetch(const std::string strDomain, const boost::sys
|
||||
std::cerr << "Error: " << err.message() << std::endl;
|
||||
|
||||
section secSite = ParseSection(strSiteFile, true);
|
||||
section::iterator it;
|
||||
bool bGood = !err;
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user