mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add skeleton for unl_default.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
@@ -11,6 +12,7 @@
|
|||||||
#include "RPCServer.h"
|
#include "RPCServer.h"
|
||||||
#include "RequestParser.h"
|
#include "RequestParser.h"
|
||||||
#include "HttpReply.h"
|
#include "HttpReply.h"
|
||||||
|
#include "HttpsClient.h"
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "RPC.h"
|
#include "RPC.h"
|
||||||
#include "Wallet.h"
|
#include "Wallet.h"
|
||||||
@@ -19,6 +21,12 @@
|
|||||||
#include "NewcoinAddress.h"
|
#include "NewcoinAddress.h"
|
||||||
#include "AccountState.h"
|
#include "AccountState.h"
|
||||||
|
|
||||||
|
#define VALIDATORS_FETCH_SECONDS 30
|
||||||
|
#define VALIDATORS_FILE_NAME "validators.txt"
|
||||||
|
#define VALIDATORS_FILE_PATH "/" VALIDATORS_FILE_NAME
|
||||||
|
#define VALIDATORS_FILE_BYTES_MAX (50 << 10)
|
||||||
|
#define VALIDATORS_SITE "redstem.com"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Just read from wire until the entire request is in.
|
Just read from wire until the entire request is in.
|
||||||
*/
|
*/
|
||||||
@@ -523,8 +531,68 @@ Json::Value RPCServer::doUnlAdd(Json::Value& params) {
|
|||||||
else return "invalid params";
|
else return "invalid params";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RPCServer::validatorsResponse(const boost::system::error_code& err, std::string strResponse)
|
||||||
|
{
|
||||||
|
std::cerr << "Fetch '" VALIDATORS_FILE_NAME "' complete." << std::endl;
|
||||||
|
|
||||||
|
if(!err)
|
||||||
|
{
|
||||||
|
theApp->getUNL().nodeDefault(strResponse);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Error: " << err.message() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Json::Value RPCServer::doUnlDefault(Json::Value& params) {
|
Json::Value RPCServer::doUnlDefault(Json::Value& params) {
|
||||||
return "not implemented";
|
// Populate the UNL from a validators.txt file.
|
||||||
|
if(!params.size() || (1==params.size() && !params[0u].compare("network")))
|
||||||
|
{
|
||||||
|
bool bNetwork = 1 == params.size();
|
||||||
|
std::string strValidators;
|
||||||
|
|
||||||
|
if (!bNetwork)
|
||||||
|
{
|
||||||
|
std::ifstream ifsDefault(VALIDATORS_FILE_NAME, std::ios::in);
|
||||||
|
|
||||||
|
if (!ifsDefault)
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to read '" VALIDATORS_FILE_NAME "'." << std::endl;
|
||||||
|
|
||||||
|
bNetwork = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strValidators.assign((std::istreambuf_iterator<char>(ifsDefault)),
|
||||||
|
std::istreambuf_iterator<char>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bNetwork)
|
||||||
|
{
|
||||||
|
boost::shared_ptr<HttpsClient> client(new HttpsClient(
|
||||||
|
theApp->getIOService(),
|
||||||
|
VALIDATORS_SITE,
|
||||||
|
VALIDATORS_FILE_PATH,
|
||||||
|
443,
|
||||||
|
VALIDATORS_FILE_BYTES_MAX
|
||||||
|
));
|
||||||
|
|
||||||
|
client->httpsGet(
|
||||||
|
boost::posix_time::seconds(VALIDATORS_FETCH_SECONDS),
|
||||||
|
boost::bind(&RPCServer::validatorsResponse, this, _1, _2));
|
||||||
|
|
||||||
|
return "fetching " VALIDATORS_FILE_NAME;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
theApp->getUNL().nodeDefault(strValidators);
|
||||||
|
|
||||||
|
return "processing " VALIDATORS_FILE_NAME;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else return "invalid params";
|
||||||
}
|
}
|
||||||
|
|
||||||
// unl_delete <hanko>
|
// unl_delete <hanko>
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ class RPCServer : public boost::enable_shared_from_this<RPCServer>
|
|||||||
|
|
||||||
// Parses a string account name into a local or remote NewcoinAddress.
|
// Parses a string account name into a local or remote NewcoinAddress.
|
||||||
NewcoinAddress parseAccount(const std::string& account);
|
NewcoinAddress parseAccount(const std::string& account);
|
||||||
|
void validatorsResponse(const boost::system::error_code& err, std::string strResponse);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef boost::shared_ptr<RPCServer> pointer;
|
typedef boost::shared_ptr<RPCServer> pointer;
|
||||||
|
|||||||
@@ -194,4 +194,11 @@ Json::Value UniqueNodeList::getUnlJson()
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UniqueNodeList::nodeDefault(std::string strValidators) {
|
||||||
|
std::cerr << "Validators>" << std::endl;
|
||||||
|
std::cerr << strValidators;
|
||||||
|
std::cerr << "Validators<" << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
// vim:ts=4
|
// vim:ts=4
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ public:
|
|||||||
void fetchNode(std::string strDomain);
|
void fetchNode(std::string strDomain);
|
||||||
void removeNode(NewcoinAddress naHanko);
|
void removeNode(NewcoinAddress naHanko);
|
||||||
void reset();
|
void reset();
|
||||||
|
void nodeDefault(std::string strValidators);
|
||||||
|
|
||||||
// 2- we don't care, 1- we care and is valid, 2-invalid signature
|
// 2- we don't care, 1- we care and is valid, 2-invalid signature
|
||||||
// int checkValid(newcoin::Validation& valid);
|
// int checkValid(newcoin::Validation& valid);
|
||||||
|
|||||||
Reference in New Issue
Block a user