mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-26 05:55:51 +00:00
Tidy up and move more items into ripple_core
This commit is contained in:
@@ -1,132 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#define SECTION_DEFAULT_NAME ""
|
||||
|
||||
// for logging
|
||||
struct ParseSectionLog { };
|
||||
|
||||
SETUP_LOG (ParseSectionLog)
|
||||
|
||||
Section ParseSection (const std::string& strInput, const bool bTrim)
|
||||
{
|
||||
std::string strData (strInput);
|
||||
std::vector<std::string> vLines;
|
||||
Section secResult;
|
||||
|
||||
// Convert DOS format to unix.
|
||||
boost::algorithm::replace_all (strData, "\r\n", "\n");
|
||||
|
||||
// Convert MacOS format to unix.
|
||||
boost::algorithm::replace_all (strData, "\r", "\n");
|
||||
|
||||
boost::algorithm::split (vLines, strData, boost::algorithm::is_any_of ("\n"));
|
||||
|
||||
// Set the default Section name.
|
||||
std::string strSection = SECTION_DEFAULT_NAME;
|
||||
|
||||
// Initialize the default Section.
|
||||
secResult[strSection] = Section::mapped_type ();
|
||||
|
||||
// Parse each line.
|
||||
BOOST_FOREACH (std::string & strValue, vLines)
|
||||
{
|
||||
if (strValue.empty () || strValue[0] == '#')
|
||||
{
|
||||
// Blank line or comment, do nothing.
|
||||
|
||||
nothing ();
|
||||
}
|
||||
else if (strValue[0] == '[' && strValue[strValue.length () - 1] == ']')
|
||||
{
|
||||
// New Section.
|
||||
|
||||
strSection = strValue.substr (1, strValue.length () - 2);
|
||||
secResult[strSection] = Section::mapped_type ();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Another line for Section.
|
||||
if (bTrim)
|
||||
boost::algorithm::trim (strValue);
|
||||
|
||||
if (!strValue.empty ())
|
||||
secResult[strSection].push_back (strValue);
|
||||
}
|
||||
}
|
||||
|
||||
return secResult;
|
||||
}
|
||||
|
||||
void SectionEntriesPrint (std::vector<std::string>* vspEntries, const std::string& strSection)
|
||||
{
|
||||
std::cerr << "[" << strSection << "]" << std::endl;
|
||||
|
||||
if (vspEntries)
|
||||
{
|
||||
BOOST_FOREACH (std::string & strValue, *vspEntries)
|
||||
{
|
||||
std::cerr << strValue << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SectionPrint (Section secInput)
|
||||
{
|
||||
BOOST_FOREACH (Section::value_type & pairSection, secInput)
|
||||
{
|
||||
SectionEntriesPrint (&pairSection.second, pairSection.first);
|
||||
}
|
||||
}
|
||||
|
||||
Section::mapped_type* SectionEntries (Section& secSource, const std::string& strSection)
|
||||
{
|
||||
Section::iterator it;
|
||||
Section::mapped_type* smtResult;
|
||||
|
||||
it = secSource.find (strSection);
|
||||
|
||||
if (it == secSource.end ())
|
||||
{
|
||||
smtResult = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Section::mapped_type& vecEntries = it->second;
|
||||
|
||||
smtResult = & (it->second);
|
||||
}
|
||||
|
||||
return smtResult;
|
||||
}
|
||||
|
||||
int SectionCount (Section& secSource, const std::string& strSection)
|
||||
{
|
||||
Section::mapped_type* pmtEntries = SectionEntries (secSource, strSection);
|
||||
|
||||
return pmtEntries ? -1 : pmtEntries->size ();
|
||||
}
|
||||
|
||||
bool SectionSingleB (Section& secSource, const std::string& strSection, std::string& strValue)
|
||||
{
|
||||
Section::mapped_type* pmtEntries = SectionEntries (secSource, strSection);
|
||||
bool bSingle = pmtEntries && 1 == pmtEntries->size ();
|
||||
|
||||
if (bSingle)
|
||||
{
|
||||
strValue = (*pmtEntries)[0];
|
||||
}
|
||||
else if (pmtEntries)
|
||||
{
|
||||
WriteLog (lsWARNING, ParseSectionLog) << boost::str (boost::format ("Section [%s]: requires 1 line not %d lines.")
|
||||
% strSection
|
||||
% pmtEntries->size ());
|
||||
}
|
||||
|
||||
return bSingle;
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
@@ -1,19 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef _PARSE_SECTION_
|
||||
#define _PARSE_SECTION_
|
||||
|
||||
typedef std::map<const std::string, std::vector<std::string> > Section;
|
||||
|
||||
Section ParseSection (const std::string& strInput, const bool bTrim);
|
||||
void SectionPrint (Section secInput);
|
||||
void SectionEntriesPrint (std::vector<std::string>* vspEntries, const std::string& strSection);
|
||||
bool SectionSingleB (Section& secSource, const std::string& strSection, std::string& strValue);
|
||||
int SectionCount (Section& secSource, const std::string& strSection);
|
||||
Section::mapped_type* SectionEntries (Section& secSource, const std::string& strSection);
|
||||
|
||||
#endif
|
||||
@@ -1,582 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
//
|
||||
// TODO: Check permissions on config file before using it.
|
||||
//
|
||||
|
||||
// VFALCO TODO Rename and replace these macros with variables.
|
||||
#define SECTION_ACCOUNT_PROBE_MAX "account_probe_max"
|
||||
#define SECTION_CLUSTER_NODES "cluster_nodes"
|
||||
#define SECTION_DATABASE_PATH "database_path"
|
||||
#define SECTION_DEBUG_LOGFILE "debug_logfile"
|
||||
#define SECTION_ELB_SUPPORT "elb_support"
|
||||
#define SECTION_FEE_DEFAULT "fee_default"
|
||||
#define SECTION_FEE_NICKNAME_CREATE "fee_nickname_create"
|
||||
#define SECTION_FEE_OFFER "fee_offer"
|
||||
#define SECTION_FEE_OPERATION "fee_operation"
|
||||
#define SECTION_FEE_ACCOUNT_RESERVE "fee_account_reserve"
|
||||
#define SECTION_FEE_OWNER_RESERVE "fee_owner_reserve"
|
||||
#define SECTION_NODE_DB "node_db"
|
||||
#define SECTION_LDB_EPHEMERAL "ephemeral_db"
|
||||
#define SECTION_LEDGER_HISTORY "ledger_history"
|
||||
#define SECTION_IPS "ips"
|
||||
#define SECTION_NETWORK_QUORUM "network_quorum"
|
||||
#define SECTION_NODE_SEED "node_seed"
|
||||
#define SECTION_NODE_SIZE "node_size"
|
||||
#define SECTION_PATH_SEARCH_SIZE "path_search_size"
|
||||
#define SECTION_PEER_CONNECT_LOW_WATER "peer_connect_low_water"
|
||||
#define SECTION_PEER_IP "peer_ip"
|
||||
#define SECTION_PEER_PORT "peer_port"
|
||||
#define SECTION_PEER_PRIVATE "peer_private"
|
||||
#define SECTION_PEER_SCAN_INTERVAL_MIN "peer_scan_interval_min"
|
||||
#define SECTION_PEER_SSL_CIPHER_LIST "peer_ssl_cipher_list"
|
||||
#define SECTION_PEER_START_MAX "peer_start_max"
|
||||
#define SECTION_RPC_ALLOW_REMOTE "rpc_allow_remote"
|
||||
#define SECTION_RPC_ADMIN_ALLOW "rpc_admin_allow"
|
||||
#define SECTION_RPC_ADMIN_USER "rpc_admin_user"
|
||||
#define SECTION_RPC_ADMIN_PASSWORD "rpc_admin_password"
|
||||
#define SECTION_RPC_IP "rpc_ip"
|
||||
#define SECTION_RPC_PORT "rpc_port"
|
||||
#define SECTION_RPC_USER "rpc_user"
|
||||
#define SECTION_RPC_PASSWORD "rpc_password"
|
||||
#define SECTION_RPC_STARTUP "rpc_startup"
|
||||
#define SECTION_RPC_SECURE "rpc_secure"
|
||||
#define SECTION_RPC_SSL_CERT "rpc_ssl_cert"
|
||||
#define SECTION_RPC_SSL_CHAIN "rpc_ssl_chain"
|
||||
#define SECTION_RPC_SSL_KEY "rpc_ssl_key"
|
||||
#define SECTION_SMS_FROM "sms_from"
|
||||
#define SECTION_SMS_KEY "sms_key"
|
||||
#define SECTION_SMS_SECRET "sms_secret"
|
||||
#define SECTION_SMS_TO "sms_to"
|
||||
#define SECTION_SMS_URL "sms_url"
|
||||
#define SECTION_SNTP "sntp_servers"
|
||||
#define SECTION_SSL_VERIFY "ssl_verify"
|
||||
#define SECTION_SSL_VERIFY_FILE "ssl_verify_file"
|
||||
#define SECTION_SSL_VERIFY_DIR "ssl_verify_dir"
|
||||
#define SECTION_VALIDATORS_FILE "validators_file"
|
||||
#define SECTION_VALIDATION_QUORUM "validation_quorum"
|
||||
#define SECTION_VALIDATION_SEED "validation_seed"
|
||||
#define SECTION_WEBSOCKET_PUBLIC_IP "websocket_public_ip"
|
||||
#define SECTION_WEBSOCKET_PUBLIC_PORT "websocket_public_port"
|
||||
#define SECTION_WEBSOCKET_PUBLIC_SECURE "websocket_public_secure"
|
||||
#define SECTION_WEBSOCKET_PING_FREQ "websocket_ping_frequency"
|
||||
#define SECTION_WEBSOCKET_IP "websocket_ip"
|
||||
#define SECTION_WEBSOCKET_PORT "websocket_port"
|
||||
#define SECTION_WEBSOCKET_SECURE "websocket_secure"
|
||||
#define SECTION_WEBSOCKET_SSL_CERT "websocket_ssl_cert"
|
||||
#define SECTION_WEBSOCKET_SSL_CHAIN "websocket_ssl_chain"
|
||||
#define SECTION_WEBSOCKET_SSL_KEY "websocket_ssl_key"
|
||||
#define SECTION_VALIDATORS "validators"
|
||||
#define SECTION_VALIDATORS_SITE "validators_site"
|
||||
|
||||
// Fees are in XRP.
|
||||
#define DEFAULT_FEE_DEFAULT 10
|
||||
#define DEFAULT_FEE_ACCOUNT_RESERVE 200*SYSTEM_CURRENCY_PARTS
|
||||
#define DEFAULT_FEE_OWNER_RESERVE 50*SYSTEM_CURRENCY_PARTS
|
||||
#define DEFAULT_FEE_NICKNAME_CREATE 1000
|
||||
#define DEFAULT_FEE_OFFER DEFAULT_FEE_DEFAULT
|
||||
#define DEFAULT_FEE_OPERATION 1
|
||||
|
||||
Config theConfig;
|
||||
|
||||
void Config::setup (const std::string& strConf, bool bTestNet, bool bQuiet)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::string strDbPath, strConfFile;
|
||||
|
||||
//
|
||||
// Determine the config and data directories.
|
||||
// If the config file is found in the current working directory, use the current working directory as the config directory and
|
||||
// that with "db" as the data directory.
|
||||
//
|
||||
|
||||
TESTNET = bTestNet;
|
||||
QUIET = bQuiet;
|
||||
NODE_SIZE = 0;
|
||||
|
||||
// TESTNET forces a "testnet-" prefix on the conf file and db directory.
|
||||
strDbPath = TESTNET ? "testnet-db" : "db";
|
||||
strConfFile = boost::str (boost::format (TESTNET ? "testnet-%s" : "%s")
|
||||
% (strConf.empty () ? CONFIG_FILE_NAME : strConf));
|
||||
|
||||
VALIDATORS_BASE = boost::str (boost::format (TESTNET ? "testnet-%s" : "%s")
|
||||
% VALIDATORS_FILE_NAME);
|
||||
VALIDATORS_URI = boost::str (boost::format ("/%s") % VALIDATORS_BASE);
|
||||
|
||||
if (TESTNET)
|
||||
{
|
||||
SIGN_TRANSACTION = HashPrefix::txSignTestnet;
|
||||
SIGN_VALIDATION = HashPrefix::validationTestnet;
|
||||
SIGN_PROPOSAL = HashPrefix::proposalTestnet;
|
||||
}
|
||||
else
|
||||
{
|
||||
SIGN_TRANSACTION = HashPrefix::txSign;
|
||||
SIGN_VALIDATION = HashPrefix::validation;
|
||||
SIGN_PROPOSAL = HashPrefix::proposal;
|
||||
}
|
||||
|
||||
if (TESTNET)
|
||||
Base58::setCurrentAlphabet (Base58::getTestnetAlphabet ());
|
||||
|
||||
if (!strConf.empty ())
|
||||
{
|
||||
// --conf=<path> : everything is relative that file.
|
||||
CONFIG_FILE = strConfFile;
|
||||
CONFIG_DIR = boost::filesystem::absolute (CONFIG_FILE);
|
||||
CONFIG_DIR.remove_filename ();
|
||||
DATA_DIR = CONFIG_DIR / strDbPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
CONFIG_DIR = boost::filesystem::current_path ();
|
||||
CONFIG_FILE = CONFIG_DIR / strConfFile;
|
||||
DATA_DIR = CONFIG_DIR / strDbPath;
|
||||
|
||||
if (exists (CONFIG_FILE)
|
||||
// Can we figure out XDG dirs?
|
||||
|| (!getenv ("HOME") && (!getenv ("XDG_CONFIG_HOME") || !getenv ("XDG_DATA_HOME"))))
|
||||
{
|
||||
// Current working directory is fine, put dbs in a subdir.
|
||||
nothing ();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Construct XDG config and data home.
|
||||
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
std::string strHome = strGetEnv ("HOME");
|
||||
std::string strXdgConfigHome = strGetEnv ("XDG_CONFIG_HOME");
|
||||
std::string strXdgDataHome = strGetEnv ("XDG_DATA_HOME");
|
||||
|
||||
if (strXdgConfigHome.empty ())
|
||||
{
|
||||
// $XDG_CONFIG_HOME was not set, use default based on $HOME.
|
||||
strXdgConfigHome = boost::str (boost::format ("%s/.config") % strHome);
|
||||
}
|
||||
|
||||
if (strXdgDataHome.empty ())
|
||||
{
|
||||
// $XDG_DATA_HOME was not set, use default based on $HOME.
|
||||
strXdgDataHome = boost::str (boost::format ("%s/.local/share") % strHome);
|
||||
}
|
||||
|
||||
CONFIG_DIR = boost::str (boost::format ("%s/" SYSTEM_NAME) % strXdgConfigHome);
|
||||
CONFIG_FILE = CONFIG_DIR / strConfFile;
|
||||
DATA_DIR = boost::str (boost::format ("%s/" SYSTEM_NAME) % strXdgDataHome);
|
||||
|
||||
boost::filesystem::create_directories (CONFIG_DIR, ec);
|
||||
|
||||
if (ec)
|
||||
throw std::runtime_error (boost::str (boost::format ("Can not create %s") % CONFIG_DIR));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (SSL_VERIFY_FILE.empty ())
|
||||
{
|
||||
SSL_CONTEXT.set_default_verify_paths (ec);
|
||||
|
||||
if (ec && SSL_VERIFY_DIR.empty ())
|
||||
throw std::runtime_error (boost::str (boost::format ("Failed to set_default_verify_paths: %s") % ec.message ()));
|
||||
}
|
||||
else
|
||||
SSL_CONTEXT.load_verify_file (SSL_VERIFY_FILE);
|
||||
|
||||
if (!SSL_VERIFY_DIR.empty ())
|
||||
{
|
||||
SSL_CONTEXT.add_verify_path (SSL_VERIFY_DIR, ec);
|
||||
|
||||
if (ec)
|
||||
throw std::runtime_error (boost::str (boost::format ("Failed to add verify path: %s") % ec.message ()));
|
||||
}
|
||||
|
||||
// Update default values
|
||||
load ();
|
||||
|
||||
// std::cerr << "CONFIG FILE: " << CONFIG_FILE << std::endl;
|
||||
// std::cerr << "CONFIG DIR: " << CONFIG_DIR << std::endl;
|
||||
// std::cerr << "DATA DIR: " << DATA_DIR << std::endl;
|
||||
|
||||
boost::filesystem::create_directories (DATA_DIR, ec);
|
||||
|
||||
if (ec)
|
||||
throw std::runtime_error (boost::str (boost::format ("Can not create %s") % DATA_DIR));
|
||||
}
|
||||
|
||||
Config::Config ()
|
||||
: SSL_CONTEXT (boost::asio::ssl::context::sslv23)
|
||||
{
|
||||
//
|
||||
// Defaults
|
||||
//
|
||||
|
||||
TESTNET = false;
|
||||
NETWORK_START_TIME = 1319844908;
|
||||
|
||||
PEER_PORT = SYSTEM_PEER_PORT;
|
||||
RPC_PORT = 5001;
|
||||
RPC_SECURE = 0;
|
||||
WEBSOCKET_PORT = SYSTEM_WEBSOCKET_PORT;
|
||||
WEBSOCKET_PUBLIC_PORT = SYSTEM_WEBSOCKET_PUBLIC_PORT;
|
||||
WEBSOCKET_PUBLIC_SECURE = 1;
|
||||
WEBSOCKET_SECURE = 0;
|
||||
WEBSOCKET_PING_FREQ = (5 * 60);
|
||||
NUMBER_CONNECTIONS = 30;
|
||||
|
||||
// a new ledger every minute
|
||||
LEDGER_SECONDS = 60;
|
||||
LEDGER_CREATOR = false;
|
||||
|
||||
RPC_ALLOW_REMOTE = false;
|
||||
RPC_ADMIN_ALLOW.push_back ("127.0.0.1");
|
||||
|
||||
PEER_SSL_CIPHER_LIST = DEFAULT_PEER_SSL_CIPHER_LIST;
|
||||
PEER_SCAN_INTERVAL_MIN = DEFAULT_PEER_SCAN_INTERVAL_MIN;
|
||||
|
||||
PEER_START_MAX = DEFAULT_PEER_START_MAX;
|
||||
PEER_CONNECT_LOW_WATER = DEFAULT_PEER_CONNECT_LOW_WATER;
|
||||
|
||||
PEER_PRIVATE = false;
|
||||
|
||||
TRANSACTION_FEE_BASE = DEFAULT_FEE_DEFAULT;
|
||||
|
||||
NETWORK_QUORUM = 0; // Don't need to see other nodes
|
||||
VALIDATION_QUORUM = 1; // Only need one node to vouch
|
||||
|
||||
FEE_ACCOUNT_RESERVE = DEFAULT_FEE_ACCOUNT_RESERVE;
|
||||
FEE_OWNER_RESERVE = DEFAULT_FEE_OWNER_RESERVE;
|
||||
FEE_NICKNAME_CREATE = DEFAULT_FEE_NICKNAME_CREATE;
|
||||
FEE_OFFER = DEFAULT_FEE_OFFER;
|
||||
FEE_DEFAULT = DEFAULT_FEE_DEFAULT;
|
||||
FEE_CONTRACT_OPERATION = DEFAULT_FEE_OPERATION;
|
||||
|
||||
LEDGER_HISTORY = 256;
|
||||
|
||||
PATH_SEARCH_SIZE = DEFAULT_PATH_SEARCH_SIZE;
|
||||
ACCOUNT_PROBE_MAX = 10;
|
||||
|
||||
VALIDATORS_SITE = DEFAULT_VALIDATORS_SITE;
|
||||
|
||||
SSL_VERIFY = true;
|
||||
|
||||
NODE_DB = "sqlite";
|
||||
|
||||
LDB_IMPORT = false;
|
||||
ELB_SUPPORT = false;
|
||||
RUN_STANDALONE = false;
|
||||
START_UP = NORMAL;
|
||||
}
|
||||
|
||||
void Config::load ()
|
||||
{
|
||||
if (!QUIET)
|
||||
std::cerr << "Loading: " << CONFIG_FILE << std::endl;
|
||||
|
||||
std::ifstream ifsConfig (CONFIG_FILE.c_str (), std::ios::in);
|
||||
|
||||
if (!ifsConfig)
|
||||
{
|
||||
std::cerr << "Failed to open '" << CONFIG_FILE << "'." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string strConfigFile;
|
||||
|
||||
strConfigFile.assign ((std::istreambuf_iterator<char> (ifsConfig)),
|
||||
std::istreambuf_iterator<char> ());
|
||||
|
||||
if (ifsConfig.bad ())
|
||||
{
|
||||
std::cerr << "Failed to read '" << CONFIG_FILE << "'." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Section secConfig = ParseSection (strConfigFile, true);
|
||||
std::string strTemp;
|
||||
|
||||
// XXX Leak
|
||||
Section::mapped_type* smtTmp;
|
||||
|
||||
smtTmp = SectionEntries (secConfig, SECTION_VALIDATORS);
|
||||
|
||||
if (smtTmp)
|
||||
{
|
||||
VALIDATORS = *smtTmp;
|
||||
// SectionEntriesPrint(&VALIDATORS, SECTION_VALIDATORS);
|
||||
}
|
||||
|
||||
smtTmp = SectionEntries (secConfig, SECTION_CLUSTER_NODES);
|
||||
|
||||
if (smtTmp)
|
||||
{
|
||||
CLUSTER_NODES = *smtTmp;
|
||||
// SectionEntriesPrint(&CLUSTER_NODES, SECTION_CLUSTER_NODES);
|
||||
}
|
||||
|
||||
smtTmp = SectionEntries (secConfig, SECTION_IPS);
|
||||
|
||||
if (smtTmp)
|
||||
{
|
||||
IPS = *smtTmp;
|
||||
// SectionEntriesPrint(&IPS, SECTION_IPS);
|
||||
}
|
||||
|
||||
smtTmp = SectionEntries (secConfig, SECTION_SNTP);
|
||||
|
||||
if (smtTmp)
|
||||
{
|
||||
SNTP_SERVERS = *smtTmp;
|
||||
}
|
||||
|
||||
smtTmp = SectionEntries (secConfig, SECTION_RPC_STARTUP);
|
||||
|
||||
if (smtTmp)
|
||||
{
|
||||
RPC_STARTUP = Json::arrayValue;
|
||||
|
||||
BOOST_FOREACH (const std::string & strJson, *smtTmp)
|
||||
{
|
||||
Json::Reader jrReader;
|
||||
Json::Value jvCommand;
|
||||
|
||||
if (!jrReader.parse (strJson, jvCommand))
|
||||
throw std::runtime_error (boost::str (boost::format ("Couldn't parse [" SECTION_RPC_STARTUP "] command: %s") % strJson));
|
||||
|
||||
RPC_STARTUP.append (jvCommand);
|
||||
}
|
||||
}
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_DATABASE_PATH, DATABASE_PATH))
|
||||
DATA_DIR = DATABASE_PATH;
|
||||
|
||||
|
||||
(void) SectionSingleB (secConfig, SECTION_VALIDATORS_SITE, VALIDATORS_SITE);
|
||||
|
||||
(void) SectionSingleB (secConfig, SECTION_PEER_IP, PEER_IP);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_PEER_PORT, strTemp))
|
||||
PEER_PORT = boost::lexical_cast<int> (strTemp);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_PEER_PRIVATE, strTemp))
|
||||
PEER_PRIVATE = boost::lexical_cast<bool> (strTemp);
|
||||
|
||||
smtTmp = SectionEntries (secConfig, SECTION_RPC_ADMIN_ALLOW);
|
||||
|
||||
if (smtTmp)
|
||||
{
|
||||
RPC_ADMIN_ALLOW = *smtTmp;
|
||||
}
|
||||
|
||||
(void) SectionSingleB (secConfig, SECTION_RPC_ADMIN_PASSWORD, RPC_ADMIN_PASSWORD);
|
||||
(void) SectionSingleB (secConfig, SECTION_RPC_ADMIN_USER, RPC_ADMIN_USER);
|
||||
(void) SectionSingleB (secConfig, SECTION_RPC_IP, RPC_IP);
|
||||
(void) SectionSingleB (secConfig, SECTION_RPC_PASSWORD, RPC_PASSWORD);
|
||||
(void) SectionSingleB (secConfig, SECTION_RPC_USER, RPC_USER);
|
||||
(void) SectionSingleB (secConfig, SECTION_NODE_DB, NODE_DB);
|
||||
(void) SectionSingleB (secConfig, SECTION_LDB_EPHEMERAL, LDB_EPHEMERAL);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_RPC_PORT, strTemp))
|
||||
RPC_PORT = boost::lexical_cast<int> (strTemp);
|
||||
|
||||
if (SectionSingleB (secConfig, "ledger_creator" , strTemp))
|
||||
LEDGER_CREATOR = boost::lexical_cast<bool> (strTemp);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_RPC_ALLOW_REMOTE, strTemp))
|
||||
RPC_ALLOW_REMOTE = boost::lexical_cast<bool> (strTemp);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_NODE_SIZE, strTemp))
|
||||
{
|
||||
if (strTemp == "tiny")
|
||||
NODE_SIZE = 0;
|
||||
else if (strTemp == "small")
|
||||
NODE_SIZE = 1;
|
||||
else if (strTemp == "medium")
|
||||
NODE_SIZE = 2;
|
||||
else if (strTemp == "large")
|
||||
NODE_SIZE = 3;
|
||||
else if (strTemp == "huge")
|
||||
NODE_SIZE = 4;
|
||||
else
|
||||
{
|
||||
NODE_SIZE = boost::lexical_cast<int> (strTemp);
|
||||
|
||||
if (NODE_SIZE < 0)
|
||||
NODE_SIZE = 0;
|
||||
else if (NODE_SIZE > 4)
|
||||
NODE_SIZE = 4;
|
||||
}
|
||||
}
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_ELB_SUPPORT, strTemp))
|
||||
ELB_SUPPORT = boost::lexical_cast<bool> (strTemp);
|
||||
|
||||
(void) SectionSingleB (secConfig, SECTION_WEBSOCKET_IP, WEBSOCKET_IP);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_WEBSOCKET_PORT, strTemp))
|
||||
WEBSOCKET_PORT = boost::lexical_cast<int> (strTemp);
|
||||
|
||||
(void) SectionSingleB (secConfig, SECTION_WEBSOCKET_PUBLIC_IP, WEBSOCKET_PUBLIC_IP);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_WEBSOCKET_PUBLIC_PORT, strTemp))
|
||||
WEBSOCKET_PUBLIC_PORT = boost::lexical_cast<int> (strTemp);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_WEBSOCKET_SECURE, strTemp))
|
||||
WEBSOCKET_SECURE = boost::lexical_cast<int> (strTemp);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_WEBSOCKET_PUBLIC_SECURE, strTemp))
|
||||
WEBSOCKET_PUBLIC_SECURE = boost::lexical_cast<int> (strTemp);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_WEBSOCKET_PING_FREQ, strTemp))
|
||||
WEBSOCKET_PING_FREQ = boost::lexical_cast<int> (strTemp);
|
||||
|
||||
SectionSingleB (secConfig, SECTION_WEBSOCKET_SSL_CERT, WEBSOCKET_SSL_CERT);
|
||||
SectionSingleB (secConfig, SECTION_WEBSOCKET_SSL_CHAIN, WEBSOCKET_SSL_CHAIN);
|
||||
SectionSingleB (secConfig, SECTION_WEBSOCKET_SSL_KEY, WEBSOCKET_SSL_KEY);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_RPC_SECURE, strTemp))
|
||||
RPC_SECURE = boost::lexical_cast<int> (strTemp);
|
||||
|
||||
SectionSingleB (secConfig, SECTION_RPC_SSL_CERT, RPC_SSL_CERT);
|
||||
SectionSingleB (secConfig, SECTION_RPC_SSL_CHAIN, RPC_SSL_CHAIN);
|
||||
SectionSingleB (secConfig, SECTION_RPC_SSL_KEY, RPC_SSL_KEY);
|
||||
|
||||
|
||||
SectionSingleB (secConfig, SECTION_SSL_VERIFY_FILE, SSL_VERIFY_FILE);
|
||||
SectionSingleB (secConfig, SECTION_SSL_VERIFY_DIR, SSL_VERIFY_DIR);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_SSL_VERIFY, strTemp))
|
||||
SSL_VERIFY = boost::lexical_cast<bool> (strTemp);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_VALIDATION_SEED, strTemp))
|
||||
{
|
||||
VALIDATION_SEED.setSeedGeneric (strTemp);
|
||||
|
||||
if (VALIDATION_SEED.isValid ())
|
||||
{
|
||||
VALIDATION_PUB = RippleAddress::createNodePublic (VALIDATION_SEED);
|
||||
VALIDATION_PRIV = RippleAddress::createNodePrivate (VALIDATION_SEED);
|
||||
}
|
||||
}
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_NODE_SEED, strTemp))
|
||||
{
|
||||
NODE_SEED.setSeedGeneric (strTemp);
|
||||
|
||||
if (NODE_SEED.isValid ())
|
||||
{
|
||||
NODE_PUB = RippleAddress::createNodePublic (NODE_SEED);
|
||||
NODE_PRIV = RippleAddress::createNodePrivate (NODE_SEED);
|
||||
}
|
||||
}
|
||||
|
||||
(void) SectionSingleB (secConfig, SECTION_PEER_SSL_CIPHER_LIST, PEER_SSL_CIPHER_LIST);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_PEER_SCAN_INTERVAL_MIN, strTemp))
|
||||
// Minimum for min is 60 seconds.
|
||||
PEER_SCAN_INTERVAL_MIN = std::max (60, boost::lexical_cast<int> (strTemp));
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_PEER_START_MAX, strTemp))
|
||||
PEER_START_MAX = std::max (1, boost::lexical_cast<int> (strTemp));
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_PEER_CONNECT_LOW_WATER, strTemp))
|
||||
PEER_CONNECT_LOW_WATER = std::max (1, boost::lexical_cast<int> (strTemp));
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_NETWORK_QUORUM, strTemp))
|
||||
NETWORK_QUORUM = std::max (0, boost::lexical_cast<int> (strTemp));
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_VALIDATION_QUORUM, strTemp))
|
||||
VALIDATION_QUORUM = std::max (0, boost::lexical_cast<int> (strTemp));
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_FEE_ACCOUNT_RESERVE, strTemp))
|
||||
FEE_ACCOUNT_RESERVE = boost::lexical_cast<uint64> (strTemp);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_FEE_OWNER_RESERVE, strTemp))
|
||||
FEE_OWNER_RESERVE = boost::lexical_cast<uint64> (strTemp);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_FEE_NICKNAME_CREATE, strTemp))
|
||||
FEE_NICKNAME_CREATE = boost::lexical_cast<int> (strTemp);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_FEE_OFFER, strTemp))
|
||||
FEE_OFFER = boost::lexical_cast<int> (strTemp);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_FEE_DEFAULT, strTemp))
|
||||
FEE_DEFAULT = boost::lexical_cast<int> (strTemp);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_FEE_OPERATION, strTemp))
|
||||
FEE_CONTRACT_OPERATION = boost::lexical_cast<int> (strTemp);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_LEDGER_HISTORY, strTemp))
|
||||
{
|
||||
boost::to_lower (strTemp);
|
||||
|
||||
if (strTemp == "none")
|
||||
LEDGER_HISTORY = 0;
|
||||
else if (strTemp == "full")
|
||||
LEDGER_HISTORY = 1000000000u;
|
||||
else
|
||||
LEDGER_HISTORY = boost::lexical_cast<uint32> (strTemp);
|
||||
}
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_PATH_SEARCH_SIZE, strTemp))
|
||||
PATH_SEARCH_SIZE = boost::lexical_cast<int> (strTemp);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_ACCOUNT_PROBE_MAX, strTemp))
|
||||
ACCOUNT_PROBE_MAX = boost::lexical_cast<int> (strTemp);
|
||||
|
||||
(void) SectionSingleB (secConfig, SECTION_SMS_FROM, SMS_FROM);
|
||||
(void) SectionSingleB (secConfig, SECTION_SMS_KEY, SMS_KEY);
|
||||
(void) SectionSingleB (secConfig, SECTION_SMS_SECRET, SMS_SECRET);
|
||||
(void) SectionSingleB (secConfig, SECTION_SMS_TO, SMS_TO);
|
||||
(void) SectionSingleB (secConfig, SECTION_SMS_URL, SMS_URL);
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_VALIDATORS_FILE, strTemp))
|
||||
VALIDATORS_FILE = strTemp;
|
||||
|
||||
if (SectionSingleB (secConfig, SECTION_DEBUG_LOGFILE, strTemp))
|
||||
DEBUG_LOGFILE = strTemp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int Config::getSize (SizedItemName item)
|
||||
{
|
||||
SizedItem sizeTable[] = // tiny small medium large huge
|
||||
{
|
||||
|
||||
{ siSweepInterval, { 10, 30, 60, 90, 120 } },
|
||||
|
||||
{ siLedgerFetch, { 2, 2, 3, 3, 3 } },
|
||||
|
||||
{ siValidationsSize, { 256, 256, 512, 1024, 1024 } },
|
||||
{ siValidationsAge, { 500, 500, 500, 500, 500 } },
|
||||
|
||||
{ siNodeCacheSize, { 8192, 65536, 262144, 2097152, 0 } },
|
||||
{ siNodeCacheAge, { 30, 60, 90, 300, 900 } },
|
||||
|
||||
{ siSLECacheSize, { 4096, 8192, 16384, 65536, 0 } },
|
||||
{ siSLECacheAge, { 30, 60, 90, 120, 300 } },
|
||||
|
||||
{ siLedgerSize, { 32, 128, 256, 2048, 0 } },
|
||||
{ siLedgerAge, { 30, 90, 180, 300, 900 } },
|
||||
|
||||
{ siHashNodeDBCache, { 4, 12, 24, 32, 64 } },
|
||||
{ siTxnDBCache, { 4, 12, 24, 32, 32 } },
|
||||
{ siLgrDBCache, { 4, 8, 16, 16, 16 } },
|
||||
};
|
||||
|
||||
for (int i = 0; i < (sizeof (sizeTable) / sizeof (SizedItem)); ++i)
|
||||
{
|
||||
if (sizeTable[i].item == item)
|
||||
return sizeTable[i].sizes[NODE_SIZE];
|
||||
}
|
||||
|
||||
assert (false);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// vim:ts=4
|
||||
@@ -1,223 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_CONFIG_H
|
||||
#define RIPPLE_CONFIG_H
|
||||
|
||||
// VFALCO NOTE Set this to 1 to enable code which is unnecessary
|
||||
#define ENABLE_INSECURE 0
|
||||
|
||||
#define CONFIG_FILE_NAME SYSTEM_NAME "d.cfg" // rippled.cfg
|
||||
|
||||
#define DEFAULT_VALIDATORS_SITE ""
|
||||
#define VALIDATORS_FILE_NAME "validators.txt"
|
||||
|
||||
const int DOMAIN_BYTES_MAX = 256;
|
||||
const int PUBLIC_BYTES_MAX = 33; // Maximum bytes for an account public key.
|
||||
|
||||
const int SYSTEM_PEER_PORT = 6561;
|
||||
const int SYSTEM_WEBSOCKET_PORT = 6562;
|
||||
const int SYSTEM_WEBSOCKET_PUBLIC_PORT = 6563; // XXX Going away.
|
||||
|
||||
// Allow anonymous DH.
|
||||
#define DEFAULT_PEER_SSL_CIPHER_LIST "ALL:!LOW:!EXP:!MD5:@STRENGTH"
|
||||
|
||||
// Normal, recommend 1 hour: 60*60
|
||||
// Testing, recommend 1 minute: 60
|
||||
#define DEFAULT_PEER_SCAN_INTERVAL_MIN (60*60) // Seconds
|
||||
|
||||
// Maximum number of peers to try to connect to as client at once.
|
||||
#define DEFAULT_PEER_START_MAX 5
|
||||
|
||||
// Might connect with fewer for testing.
|
||||
#define DEFAULT_PEER_CONNECT_LOW_WATER 4
|
||||
|
||||
// Grows exponentially worse.
|
||||
#define DEFAULT_PATH_SEARCH_SIZE 4
|
||||
|
||||
enum SizedItemName
|
||||
{
|
||||
siSweepInterval,
|
||||
siValidationsSize,
|
||||
siValidationsAge,
|
||||
siNodeCacheSize,
|
||||
siNodeCacheAge,
|
||||
siSLECacheSize,
|
||||
siSLECacheAge,
|
||||
siLedgerSize,
|
||||
siLedgerAge,
|
||||
siLedgerFetch,
|
||||
siHashNodeDBCache,
|
||||
siTxnDBCache,
|
||||
siLgrDBCache,
|
||||
};
|
||||
|
||||
struct SizedItem
|
||||
{
|
||||
SizedItemName item;
|
||||
int sizes[5];
|
||||
};
|
||||
|
||||
// VFALCO TODO rename all fields to not look like macros, and be more verbose
|
||||
// VFALCO TODO document every member
|
||||
class Config
|
||||
{
|
||||
public:
|
||||
// Configuration parameters
|
||||
bool QUIET;
|
||||
bool TESTNET;
|
||||
|
||||
boost::filesystem::path CONFIG_FILE;
|
||||
boost::filesystem::path CONFIG_DIR;
|
||||
boost::filesystem::path DATA_DIR;
|
||||
boost::filesystem::path DEBUG_LOGFILE;
|
||||
boost::filesystem::path VALIDATORS_FILE; // As specifed in rippled.cfg.
|
||||
std::string NODE_DB; // Database to use for nodes
|
||||
std::string LDB_EPHEMERAL; // Database for temporary storage
|
||||
bool LDB_IMPORT; // Import into LevelDB
|
||||
bool ELB_SUPPORT; // Support Amazon ELB
|
||||
|
||||
std::string VALIDATORS_SITE; // Where to find validators.txt on the Internet.
|
||||
std::string VALIDATORS_URI; // URI of validators.txt.
|
||||
std::string VALIDATORS_BASE; // Name with testnet-, if needed.
|
||||
std::vector<std::string> VALIDATORS; // Validators from rippled.cfg.
|
||||
std::vector<std::string> IPS; // Peer IPs from rippled.cfg.
|
||||
std::vector<std::string> SNTP_SERVERS; // SNTP servers from rippled.cfg.
|
||||
|
||||
enum StartUpType
|
||||
{
|
||||
FRESH,
|
||||
NORMAL,
|
||||
LOAD,
|
||||
NETWORK
|
||||
};
|
||||
StartUpType START_UP;
|
||||
|
||||
|
||||
|
||||
std::string START_LEDGER;
|
||||
|
||||
// Database
|
||||
std::string DATABASE_PATH;
|
||||
|
||||
// Network parameters
|
||||
int NETWORK_START_TIME; // The Unix time we start ledger 0.
|
||||
int TRANSACTION_FEE_BASE; // The number of fee units a reference transaction costs
|
||||
int LEDGER_SECONDS;
|
||||
int LEDGER_PROPOSAL_DELAY_SECONDS;
|
||||
int LEDGER_AVALANCHE_SECONDS;
|
||||
bool LEDGER_CREATOR; // Should be false unless we are starting a new ledger.
|
||||
|
||||
/** Operate in stand-alone mode.
|
||||
|
||||
In stand alone mode:
|
||||
|
||||
- Peer connections are not attempted or accepted
|
||||
- The ledger is not advanced automatically.
|
||||
- If no ledger is loaded, the default ledger with the root
|
||||
account is created.
|
||||
*/
|
||||
bool RUN_STANDALONE;
|
||||
|
||||
// Note: The following parameters do not relate to the UNL or trust at all
|
||||
unsigned int NETWORK_QUORUM; // Minimum number of nodes to consider the network present
|
||||
int VALIDATION_QUORUM; // Minimum validations to consider ledger authoritative
|
||||
|
||||
// Peer networking parameters
|
||||
std::string PEER_IP;
|
||||
int PEER_PORT;
|
||||
int NUMBER_CONNECTIONS;
|
||||
std::string PEER_SSL_CIPHER_LIST;
|
||||
int PEER_SCAN_INTERVAL_MIN;
|
||||
int PEER_START_MAX;
|
||||
unsigned int PEER_CONNECT_LOW_WATER;
|
||||
bool PEER_PRIVATE; // True to ask peers not to relay current IP.
|
||||
|
||||
// Websocket networking parameters
|
||||
std::string WEBSOCKET_PUBLIC_IP; // XXX Going away. Merge with the inbound peer connction.
|
||||
int WEBSOCKET_PUBLIC_PORT;
|
||||
int WEBSOCKET_PUBLIC_SECURE;
|
||||
|
||||
std::string WEBSOCKET_IP;
|
||||
int WEBSOCKET_PORT;
|
||||
int WEBSOCKET_SECURE;
|
||||
|
||||
int WEBSOCKET_PING_FREQ;
|
||||
|
||||
std::string WEBSOCKET_SSL_CERT;
|
||||
std::string WEBSOCKET_SSL_CHAIN;
|
||||
std::string WEBSOCKET_SSL_KEY;
|
||||
|
||||
// RPC parameters
|
||||
std::string RPC_IP;
|
||||
int RPC_PORT;
|
||||
std::vector<std::string> RPC_ADMIN_ALLOW;
|
||||
std::string RPC_ADMIN_PASSWORD;
|
||||
std::string RPC_ADMIN_USER;
|
||||
std::string RPC_PASSWORD;
|
||||
std::string RPC_USER;
|
||||
bool RPC_ALLOW_REMOTE;
|
||||
Json::Value RPC_STARTUP;
|
||||
|
||||
int RPC_SECURE;
|
||||
std::string RPC_SSL_CERT;
|
||||
std::string RPC_SSL_CHAIN;
|
||||
std::string RPC_SSL_KEY;
|
||||
|
||||
// Path searching
|
||||
int PATH_SEARCH_SIZE;
|
||||
|
||||
// Validation
|
||||
RippleAddress VALIDATION_SEED, VALIDATION_PUB, VALIDATION_PRIV;
|
||||
|
||||
// Node/Cluster
|
||||
std::vector<std::string> CLUSTER_NODES;
|
||||
RippleAddress NODE_SEED, NODE_PUB, NODE_PRIV;
|
||||
|
||||
// Fee schedule (All below values are in fee units)
|
||||
uint64 FEE_DEFAULT; // Default fee.
|
||||
uint64 FEE_ACCOUNT_RESERVE; // Amount of units not allowed to send.
|
||||
uint64 FEE_OWNER_RESERVE; // Amount of units not allowed to send per owner entry.
|
||||
uint64 FEE_NICKNAME_CREATE; // Fee to create a nickname.
|
||||
uint64 FEE_OFFER; // Rate per day.
|
||||
int FEE_CONTRACT_OPERATION; // fee for each contract operation
|
||||
|
||||
// Node storage configuration
|
||||
uint32 LEDGER_HISTORY;
|
||||
int NODE_SIZE;
|
||||
|
||||
// Client behavior
|
||||
int ACCOUNT_PROBE_MAX; // How far to scan for accounts.
|
||||
|
||||
// Signing signatures.
|
||||
uint32 SIGN_TRANSACTION;
|
||||
uint32 SIGN_VALIDATION;
|
||||
uint32 SIGN_PROPOSAL;
|
||||
|
||||
boost::asio::ssl::context SSL_CONTEXT; // Generic SSL context.
|
||||
bool SSL_VERIFY;
|
||||
std::string SSL_VERIFY_FILE;
|
||||
std::string SSL_VERIFY_DIR;
|
||||
|
||||
std::string SMS_FROM;
|
||||
std::string SMS_KEY;
|
||||
std::string SMS_SECRET;
|
||||
std::string SMS_TO;
|
||||
std::string SMS_URL;
|
||||
|
||||
public:
|
||||
Config ();
|
||||
|
||||
int getSize (SizedItemName);
|
||||
void setup (const std::string& strConf, bool bTestNet, bool bQuiet);
|
||||
void load ();
|
||||
};
|
||||
|
||||
extern Config theConfig;
|
||||
|
||||
#endif
|
||||
|
||||
// vim:ts=4
|
||||
@@ -7,15 +7,6 @@
|
||||
#ifndef RIPPLE_IAPPLICATION_H
|
||||
#define RIPPLE_IAPPLICATION_H
|
||||
|
||||
// VFALCO TODO Replace these with beast "unsigned long long" generators
|
||||
// VFALCO NOTE Apparently these are used elsewhere. Make them constants in the config
|
||||
// or in the IApplication
|
||||
//
|
||||
#define SYSTEM_CURRENCY_GIFT 1000ull
|
||||
#define SYSTEM_CURRENCY_USERS 100000000ull
|
||||
#define SYSTEM_CURRENCY_PARTS 1000000ull // 10^SYSTEM_CURRENCY_PRECISION
|
||||
#define SYSTEM_CURRENCY_START (SYSTEM_CURRENCY_GIFT*SYSTEM_CURRENCY_USERS*SYSTEM_CURRENCY_PARTS)
|
||||
|
||||
// VFALCO TODO Fix forward declares required for header dependency loops
|
||||
class IFeatures;
|
||||
class IFeeVote;
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_ILOADFEETRACK_H
|
||||
#define RIPPLE_ILOADFEETRACK_H
|
||||
|
||||
/** Tracks the current fee and load schedule.
|
||||
*/
|
||||
class ILoadFeeTrack
|
||||
{
|
||||
public:
|
||||
static ILoadFeeTrack* New ();
|
||||
|
||||
virtual ~ILoadFeeTrack () { }
|
||||
|
||||
// Scale from fee units to millionths of a ripple
|
||||
virtual uint64 scaleFeeBase (uint64 fee, uint64 baseFee, uint32 referenceFeeUnits) = 0;
|
||||
|
||||
// Scale using load as well as base rate
|
||||
virtual uint64 scaleFeeLoad (uint64 fee, uint64 baseFee, uint32 referenceFeeUnits, bool bAdmin) = 0;
|
||||
|
||||
virtual uint32 getRemoteFee () = 0;
|
||||
virtual uint32 getLocalFee () = 0;
|
||||
|
||||
virtual uint32 getLoadBase () = 0;
|
||||
virtual uint32 getLoadFactor () = 0;
|
||||
|
||||
virtual Json::Value getJson (uint64 baseFee, uint32 referenceFeeUnits) = 0;
|
||||
|
||||
virtual void setRemoteFee (uint32) = 0;
|
||||
virtual bool raiseLocalFee () = 0;
|
||||
virtual bool lowerLocalFee () = 0;
|
||||
virtual bool isLoaded () = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// vim:ts=4
|
||||
@@ -1,209 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
class LoadFeeTrack : public ILoadFeeTrack
|
||||
{
|
||||
private:
|
||||
static const int lftNormalFee = 256; // 256 is the minimum/normal load factor
|
||||
static const int lftFeeIncFraction = 16; // increase fee by 1/16
|
||||
static const int lftFeeDecFraction = 4; // decrease fee by 1/4
|
||||
static const int lftFeeMax = lftNormalFee * 1000000;
|
||||
|
||||
uint32 mLocalTxnLoadFee; // Scale factor, lftNormalFee = normal fee
|
||||
uint32 mRemoteTxnLoadFee; // Scale factor, lftNormalFee = normal fee
|
||||
int raiseCount;
|
||||
|
||||
boost::mutex mLock;
|
||||
|
||||
// VFALCO TODO Move this function to some "math utilities" file
|
||||
// compute (value)*(mul)/(div) - avoid overflow but keep precision
|
||||
uint64 mulDiv (uint64 value, uint32 mul, uint64 div)
|
||||
{
|
||||
static uint64 boundary = (0x00000000FFFFFFFF);
|
||||
|
||||
if (value > boundary) // Large value, avoid overflow
|
||||
return (value / div) * mul;
|
||||
else // Normal value, preserve accuracy
|
||||
return (value * mul) / div;
|
||||
}
|
||||
|
||||
public:
|
||||
LoadFeeTrack ()
|
||||
: mLocalTxnLoadFee (lftNormalFee)
|
||||
, mRemoteTxnLoadFee (lftNormalFee)
|
||||
, raiseCount (0)
|
||||
{
|
||||
}
|
||||
|
||||
// Scale using load as well as base rate
|
||||
uint64 scaleFeeLoad (uint64 fee, uint64 baseFee, uint32 referenceFeeUnits, bool bAdmin)
|
||||
{
|
||||
static uint64 midrange (0x00000000FFFFFFFF);
|
||||
|
||||
bool big = (fee > midrange);
|
||||
|
||||
if (big) // big fee, divide first to avoid overflow
|
||||
fee /= baseFee;
|
||||
else // normal fee, multiply first for accuracy
|
||||
fee *= referenceFeeUnits;
|
||||
|
||||
uint32 feeFactor = std::max (mLocalTxnLoadFee, mRemoteTxnLoadFee);
|
||||
|
||||
// Let admins pay the normal fee until the local load exceeds four times the remote
|
||||
if (bAdmin && (feeFactor > mRemoteTxnLoadFee) && (feeFactor < (4 * mRemoteTxnLoadFee)))
|
||||
feeFactor = mRemoteTxnLoadFee;
|
||||
|
||||
{
|
||||
boost::mutex::scoped_lock sl (mLock);
|
||||
fee = mulDiv (fee, feeFactor, lftNormalFee);
|
||||
}
|
||||
|
||||
if (big) // Fee was big to start, must now multiply
|
||||
fee *= referenceFeeUnits;
|
||||
else // Fee was small to start, mst now divide
|
||||
fee /= baseFee;
|
||||
|
||||
return fee;
|
||||
}
|
||||
|
||||
// Scale from fee units to millionths of a ripple
|
||||
uint64 scaleFeeBase (uint64 fee, uint64 baseFee, uint32 referenceFeeUnits)
|
||||
{
|
||||
return mulDiv (fee, referenceFeeUnits, baseFee);
|
||||
}
|
||||
|
||||
uint32 getRemoteFee ()
|
||||
{
|
||||
boost::mutex::scoped_lock sl (mLock);
|
||||
return mRemoteTxnLoadFee;
|
||||
}
|
||||
|
||||
uint32 getLocalFee ()
|
||||
{
|
||||
boost::mutex::scoped_lock sl (mLock);
|
||||
return mLocalTxnLoadFee;
|
||||
}
|
||||
|
||||
uint32 getLoadBase ()
|
||||
{
|
||||
return lftNormalFee;
|
||||
}
|
||||
|
||||
uint32 getLoadFactor ()
|
||||
{
|
||||
boost::mutex::scoped_lock sl (mLock);
|
||||
return std::max (mLocalTxnLoadFee, mRemoteTxnLoadFee);
|
||||
}
|
||||
|
||||
bool isLoaded ()
|
||||
{
|
||||
boost::mutex::scoped_lock sl (mLock);
|
||||
return (raiseCount != 0) || (mLocalTxnLoadFee != lftNormalFee);
|
||||
}
|
||||
|
||||
void setRemoteFee (uint32 f)
|
||||
{
|
||||
boost::mutex::scoped_lock sl (mLock);
|
||||
mRemoteTxnLoadFee = f;
|
||||
}
|
||||
|
||||
bool raiseLocalFee ()
|
||||
{
|
||||
boost::mutex::scoped_lock sl (mLock);
|
||||
|
||||
if (++raiseCount < 2)
|
||||
return false;
|
||||
|
||||
uint32 origFee = mLocalTxnLoadFee;
|
||||
|
||||
if (mLocalTxnLoadFee < mRemoteTxnLoadFee) // make sure this fee takes effect
|
||||
mLocalTxnLoadFee = mRemoteTxnLoadFee;
|
||||
|
||||
mLocalTxnLoadFee += (mLocalTxnLoadFee / lftFeeIncFraction); // increment by 1/16th
|
||||
|
||||
if (mLocalTxnLoadFee > lftFeeMax)
|
||||
mLocalTxnLoadFee = lftFeeMax;
|
||||
|
||||
if (origFee == mLocalTxnLoadFee)
|
||||
return false;
|
||||
|
||||
WriteLog (lsDEBUG, LoadManager) << "Local load fee raised from " << origFee << " to " << mLocalTxnLoadFee;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool lowerLocalFee ()
|
||||
{
|
||||
boost::mutex::scoped_lock sl (mLock);
|
||||
uint32 origFee = mLocalTxnLoadFee;
|
||||
raiseCount = 0;
|
||||
|
||||
mLocalTxnLoadFee -= (mLocalTxnLoadFee / lftFeeDecFraction ); // reduce by 1/4
|
||||
|
||||
if (mLocalTxnLoadFee < lftNormalFee)
|
||||
mLocalTxnLoadFee = lftNormalFee;
|
||||
|
||||
if (origFee == mLocalTxnLoadFee)
|
||||
return false;
|
||||
|
||||
WriteLog (lsDEBUG, LoadManager) << "Local load fee lowered from " << origFee << " to " << mLocalTxnLoadFee;
|
||||
return true;
|
||||
}
|
||||
|
||||
Json::Value getJson (uint64 baseFee, uint32 referenceFeeUnits)
|
||||
{
|
||||
Json::Value j (Json::objectValue);
|
||||
|
||||
{
|
||||
boost::mutex::scoped_lock sl (mLock);
|
||||
|
||||
// base_fee = The cost to send a "reference" transaction under no load, in millionths of a Ripple
|
||||
j["base_fee"] = Json::Value::UInt (baseFee);
|
||||
|
||||
// load_fee = The cost to send a "reference" transaction now, in millionths of a Ripple
|
||||
j["load_fee"] = Json::Value::UInt (
|
||||
mulDiv (baseFee, std::max (mLocalTxnLoadFee, mRemoteTxnLoadFee), lftNormalFee));
|
||||
}
|
||||
|
||||
return j;
|
||||
}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ILoadFeeTrack* ILoadFeeTrack::New ()
|
||||
{
|
||||
return new LoadFeeTrack;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
BOOST_AUTO_TEST_SUITE (LoadManager_test)
|
||||
|
||||
BOOST_AUTO_TEST_CASE (LoadFeeTrack_test)
|
||||
{
|
||||
WriteLog (lsDEBUG, LoadManager) << "Running load fee track test";
|
||||
|
||||
Config d; // get a default configuration object
|
||||
LoadFeeTrack l;
|
||||
|
||||
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (10000, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 10000);
|
||||
BOOST_REQUIRE_EQUAL (l.scaleFeeLoad (10000, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE, false), 10000);
|
||||
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (1, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 1);
|
||||
BOOST_REQUIRE_EQUAL (l.scaleFeeLoad (1, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE, false), 1);
|
||||
|
||||
// Check new default fee values give same fees as old defaults
|
||||
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_DEFAULT, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 10);
|
||||
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_ACCOUNT_RESERVE, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 200 * SYSTEM_CURRENCY_PARTS);
|
||||
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_OWNER_RESERVE, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 50 * SYSTEM_CURRENCY_PARTS);
|
||||
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_NICKNAME_CREATE, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 1000);
|
||||
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_OFFER, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 10);
|
||||
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_CONTRACT_OPERATION, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 1);
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END ()
|
||||
|
||||
// vim:ts=4
|
||||
Reference in New Issue
Block a user