mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 19:45:53 +00:00
Remove the use of beast::String from rippled (RIPD-443)
This commit is contained in:
committed by
Vinnie Falco
parent
4241dbb600
commit
c0b69e8ef7
@@ -243,18 +243,16 @@ Ledger::~Ledger ()
|
||||
{
|
||||
if (mTransactionMap)
|
||||
{
|
||||
logTimedDestroy <Ledger> (
|
||||
mTransactionMap,
|
||||
"mTransactionMap with "
|
||||
+ std::to_string(mTransactionMap->size ()) + " items");
|
||||
logTimedDestroy <Ledger> (mTransactionMap,
|
||||
"mTransactionMap with " +
|
||||
std::to_string(mTransactionMap->size ()) + " items");
|
||||
}
|
||||
|
||||
if (mAccountStateMap)
|
||||
{
|
||||
logTimedDestroy <Ledger> (
|
||||
mAccountStateMap,
|
||||
"mAccountStateMap with "
|
||||
+ std::to_string (mAccountStateMap->size ()) + " items");
|
||||
logTimedDestroy <Ledger> (mAccountStateMap,
|
||||
"mAccountStateMap with " +
|
||||
std::to_string (mAccountStateMap->size ()) + " items");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -209,14 +209,16 @@ public:
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
static std::vector <std::unique_ptr <NodeStore::Factory>> make_Factories ()
|
||||
static
|
||||
std::vector <std::unique_ptr <NodeStore::Factory>>
|
||||
make_Factories (int hashnode_cache_size)
|
||||
{
|
||||
std::vector <std::unique_ptr <NodeStore::Factory>> list;
|
||||
|
||||
// VFALCO NOTE SqliteFactory is here because it has
|
||||
// dependencies like SqliteDatabase and DatabaseCon
|
||||
//
|
||||
list.emplace_back (make_SqliteFactory ());
|
||||
list.emplace_back (make_SqliteFactory (hashnode_cache_size));
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -241,7 +243,8 @@ public:
|
||||
, m_journal (m_logs.journal("Application"))
|
||||
|
||||
, m_nodeStoreManager (NodeStore::make_Manager (
|
||||
std::move (make_Factories ())))
|
||||
std::move (make_Factories (
|
||||
getConfig ().getSize(siHashNodeDBCache) * 1024))))
|
||||
|
||||
, m_tempNodeCache ("NodeCache", 16384, 90, get_seconds_clock (),
|
||||
m_logs.journal("TaggedCache"))
|
||||
|
||||
@@ -167,13 +167,14 @@ int run (int argc, char** argv)
|
||||
int iResult = 0;
|
||||
po::variables_map vm;
|
||||
|
||||
beast::String importDescription;
|
||||
std::string importText;
|
||||
{
|
||||
importDescription <<
|
||||
"Import an existing node database (specified in the " <<
|
||||
"[" << ConfigSection::importNodeDatabase () << "] configuration file section) "
|
||||
"into the current node database (specified in the " <<
|
||||
"[" << ConfigSection::nodeDatabase () << "] configuration file section). ";
|
||||
importText += "Import an existing node database (specified in the [";
|
||||
importText += ConfigSection::importNodeDatabase ();
|
||||
importText += "] configuration file section) into the current ";
|
||||
importText += "node database (specified in the [";
|
||||
importText += ConfigSection::nodeDatabase ();
|
||||
importText += "] configuration file section).";
|
||||
}
|
||||
|
||||
// VFALCO TODO Replace boost program options with something from Beast.
|
||||
@@ -201,7 +202,7 @@ int run (int argc, char** argv)
|
||||
("start", "Start from a fresh Ledger.")
|
||||
("net", "Get the initial ledger from the network.")
|
||||
("fg", "Run in the foreground.")
|
||||
("import", importDescription.toStdString ().c_str ())
|
||||
("import", importText.c_str ())
|
||||
("version", "Display the build version.")
|
||||
;
|
||||
|
||||
@@ -240,8 +241,8 @@ int run (int argc, char** argv)
|
||||
|
||||
if (vm.count ("version"))
|
||||
{
|
||||
beast::String const& s (BuildInfo::getVersionString ());
|
||||
std::cout << "rippled version " << s.toStdString() << std::endl;
|
||||
std::cout << "rippled version " <<
|
||||
BuildInfo::getVersionString () << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -371,10 +371,6 @@ public:
|
||||
ProofOfWorkFactoryImp gen;
|
||||
ProofOfWork pow = gen.getProof ();
|
||||
|
||||
beast::String s;
|
||||
|
||||
s << "solve difficulty " << beast::String (pow.getDifficulty ());
|
||||
|
||||
uint256 solution = pow.solve (16777216);
|
||||
|
||||
expect (! solution.isZero (), "Should be solved");
|
||||
|
||||
@@ -51,16 +51,13 @@ static int s_nodeStoreDBCount = RIPPLE_ARRAYSIZE (s_nodeStoreDBInit);
|
||||
class SqliteBackend : public NodeStore::Backend
|
||||
{
|
||||
public:
|
||||
explicit SqliteBackend (std::string const& path)
|
||||
explicit SqliteBackend (std::string const& path, int hashnode_cache_size)
|
||||
: m_name (path)
|
||||
, m_db (new DatabaseCon(path, s_nodeStoreDBInit, s_nodeStoreDBCount))
|
||||
{
|
||||
beast::String s;
|
||||
|
||||
// VFALCO TODO Remove this dependency on theConfig
|
||||
//
|
||||
s << "PRAGMA cache_size=-" << beast::String (getConfig ().getSize(siHashNodeDBCache) * 1024);
|
||||
m_db->getDB()->executeSQL (s.toStdString ().c_str ());
|
||||
std::string s ("PRAGMA cache_size=-");
|
||||
s += std::to_string (hashnode_cache_size);
|
||||
m_db->getDB()->executeSQL (s);
|
||||
}
|
||||
|
||||
~SqliteBackend()
|
||||
@@ -227,8 +224,16 @@ private:
|
||||
|
||||
class SqliteFactory : public NodeStore::Factory
|
||||
{
|
||||
int hashnode_cache_size_;
|
||||
|
||||
public:
|
||||
beast::String getName () const
|
||||
SqliteFactory (int hashnode_cache_size)
|
||||
: hashnode_cache_size_ (hashnode_cache_size)
|
||||
{
|
||||
}
|
||||
|
||||
std::string
|
||||
getName () const
|
||||
{
|
||||
return "Sqlite";
|
||||
}
|
||||
@@ -237,15 +242,16 @@ public:
|
||||
size_t, NodeStore::Parameters const& keyValues,
|
||||
NodeStore::Scheduler&, beast::Journal)
|
||||
{
|
||||
return std::make_unique <SqliteBackend> (keyValues ["path"].toStdString ());
|
||||
return std::make_unique <SqliteBackend> (
|
||||
keyValues ["path"].toStdString (), hashnode_cache_size_);
|
||||
}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
std::unique_ptr <NodeStore::Factory> make_SqliteFactory ()
|
||||
std::unique_ptr <NodeStore::Factory> make_SqliteFactory (int hashnode_cache_size)
|
||||
{
|
||||
return std::make_unique <SqliteFactory> ();
|
||||
return std::make_unique <SqliteFactory> (hashnode_cache_size);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace ripple {
|
||||
/** Factory to produce SQLite backends for the NodeStore.
|
||||
@see Database
|
||||
*/
|
||||
std::unique_ptr <NodeStore::Factory> make_SqliteFactory ();
|
||||
std::unique_ptr <NodeStore::Factory> make_SqliteFactory (int hashnode_cache_size);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -83,22 +83,17 @@ SHAMap::~SHAMap ()
|
||||
{
|
||||
mState = smsInvalid;
|
||||
|
||||
logTimedDestroy <SHAMap> (mTNByID,
|
||||
beast::String ("mTNByID with ") +
|
||||
beast::String::fromNumber (mTNByID.size ()) + " items");
|
||||
logTimedDestroy <SHAMap> (mTNByID, "mTNByID with " +
|
||||
std::to_string (mTNByID.size ()) + " items");
|
||||
|
||||
if (mDirtyNodes)
|
||||
{
|
||||
logTimedDestroy <SHAMap> (mDirtyNodes,
|
||||
beast::String ("mDirtyNodes with ") +
|
||||
beast::String::fromNumber (mDirtyNodes->size ()) + " items");
|
||||
logTimedDestroy <SHAMap> (mDirtyNodes, "mDirtyNodes with " +
|
||||
std::to_string (mDirtyNodes->size ()) + " items");
|
||||
}
|
||||
|
||||
if (root)
|
||||
{
|
||||
logTimedDestroy <SHAMap> (root,
|
||||
beast::String ("root node"));
|
||||
}
|
||||
logTimedDestroy <SHAMap> (root, "root node");
|
||||
}
|
||||
|
||||
void SHAMapNodeID::setMHash () const
|
||||
|
||||
@@ -99,15 +99,17 @@ double timedDestroy (Object& object)
|
||||
*/
|
||||
template <typename PartitionKey, typename Object>
|
||||
void logTimedDestroy (
|
||||
Object& object, beast::String objectDescription, double thresholdSeconds = 1)
|
||||
Object& object,
|
||||
std::string const& objectDescription,
|
||||
double thresholdSeconds = 1)
|
||||
{
|
||||
double const seconds = timedDestroy (object);
|
||||
|
||||
if (seconds > thresholdSeconds)
|
||||
{
|
||||
deprecatedLogs().journal("LoggedTimings").warning <<
|
||||
objectDescription << " took "<<
|
||||
beast::String (detail::cleanElapsed (seconds)) <<
|
||||
objectDescription << " took " <<
|
||||
detail::cleanElapsed (seconds) <<
|
||||
" seconds to destroy";
|
||||
}
|
||||
}
|
||||
@@ -116,11 +118,13 @@ void logTimedDestroy (
|
||||
|
||||
/** Log a timed function call if the time exceeds a threshold. */
|
||||
template <typename Function>
|
||||
void logTimedCall (beast::Journal::Stream stream,
|
||||
beast::String description,
|
||||
void logTimedCall (
|
||||
beast::Journal::Stream stream,
|
||||
std::string const& description,
|
||||
char const* fileName,
|
||||
int lineNumber,
|
||||
Function f, double thresholdSeconds = 1)
|
||||
Function f,
|
||||
double thresholdSeconds = 1)
|
||||
{
|
||||
double const seconds = beast::measureFunctionCallTime (f);
|
||||
|
||||
@@ -128,7 +132,7 @@ void logTimedCall (beast::Journal::Stream stream,
|
||||
{
|
||||
stream <<
|
||||
description << " took "<<
|
||||
beast::String (detail::cleanElapsed (seconds)) <<
|
||||
detail::cleanElapsed (seconds) <<
|
||||
" seconds to execute at " <<
|
||||
beast::Debug::getSourceLocation (fileName, lineNumber);
|
||||
}
|
||||
|
||||
@@ -40,28 +40,30 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
static beast::String getArgName (arg_type arg)
|
||||
static std::string getArgName (arg_type arg)
|
||||
{
|
||||
beast::String s;
|
||||
std::string s;
|
||||
|
||||
if (arg & MultiSocket::Flag::client_role)
|
||||
s << "client,";
|
||||
s += "client,";
|
||||
|
||||
if (arg & MultiSocket::Flag::server_role)
|
||||
s << "server,";
|
||||
s += "server,";
|
||||
|
||||
if (arg & MultiSocket::Flag::ssl)
|
||||
s << "ssl,";
|
||||
s += "ssl,";
|
||||
|
||||
if (arg & MultiSocket::Flag::ssl_required)
|
||||
s << "ssl_required,";
|
||||
s += "ssl_required,";
|
||||
|
||||
if (arg & MultiSocket::Flag::proxy)
|
||||
s << "proxy,";
|
||||
s += "proxy,";
|
||||
|
||||
if (s != beast::String::empty)
|
||||
if (!s.empty ())
|
||||
{
|
||||
s = "(" + s.substring (0, s.length () - 1) + ")";
|
||||
s = std::string ("(") +
|
||||
s.substr (0, s.length () - 1) +
|
||||
std::string (")");
|
||||
}
|
||||
|
||||
return s;
|
||||
@@ -88,7 +90,7 @@ public:
|
||||
return holder.context->get ();
|
||||
}
|
||||
|
||||
beast::String name () const
|
||||
std::string name () const
|
||||
{
|
||||
return getArgName (m_flags);
|
||||
}
|
||||
|
||||
@@ -60,8 +60,7 @@ getIniFileSection (IniFileSections& secSource, std::string const& strSection);
|
||||
*/
|
||||
// DEPRECATED
|
||||
beast::StringPairArray
|
||||
parseKeyValueSection (IniFileSections& secSource,
|
||||
beast::String const& strSection);
|
||||
parseKeyValueSection (IniFileSections& secSource, std::string const& strSection);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -246,13 +245,9 @@ public:
|
||||
|
||||
/** Convert the RPC/port combination to a readable string.
|
||||
*/
|
||||
beast::String const getRpcAddress ()
|
||||
std::string const getRpcAddress ()
|
||||
{
|
||||
beast::String s;
|
||||
|
||||
s << m_rpcIP.c_str () << ":" << m_rpcPort;
|
||||
|
||||
return s;
|
||||
return m_rpcIP + ":" + std::to_string (m_rpcPort);
|
||||
}
|
||||
|
||||
/** Determine the level of administrative permission to grant.
|
||||
|
||||
@@ -30,9 +30,9 @@ namespace ripple {
|
||||
//
|
||||
struct ConfigSection
|
||||
{
|
||||
static beast::String nodeDatabase () { return "node_db"; }
|
||||
static beast::String tempNodeDatabase () { return "temp_db"; }
|
||||
static beast::String importNodeDatabase () { return "import_db"; }
|
||||
static std::string nodeDatabase () { return "node_db"; }
|
||||
static std::string tempNodeDatabase () { return "temp_db"; }
|
||||
static std::string importNodeDatabase () { return "import_db"; }
|
||||
};
|
||||
|
||||
// VFALCO TODO Rename and replace these macros with variables.
|
||||
|
||||
@@ -145,34 +145,28 @@ bool getSingleSection (IniFileSections& secSource,
|
||||
}
|
||||
|
||||
beast::StringPairArray
|
||||
parseKeyValueSection (IniFileSections& secSource,
|
||||
beast::String const& strSection)
|
||||
parseKeyValueSection (IniFileSections& secSource, std::string const& strSection)
|
||||
{
|
||||
beast::StringPairArray result;
|
||||
|
||||
// yuck.
|
||||
std::string const stdStrSection (strSection.toStdString ());
|
||||
|
||||
typedef IniFileSections::mapped_type Entries;
|
||||
|
||||
Entries* const entries = getIniFileSection (secSource, stdStrSection);
|
||||
Entries* const entries = getIniFileSection (secSource, strSection);
|
||||
|
||||
if (entries != nullptr)
|
||||
{
|
||||
for (Entries::const_iterator iter = entries->begin ();
|
||||
iter != entries->end (); ++iter)
|
||||
{
|
||||
beast::String const line (iter->c_str ());
|
||||
std::string const line (iter->c_str ());
|
||||
|
||||
int const equalPos = line.indexOfChar ('=');
|
||||
int const equalPos = line.find ('=');
|
||||
|
||||
if (equalPos != -1)
|
||||
if (equalPos != std::string::npos)
|
||||
{
|
||||
beast::String const key = line.substring (0, equalPos);
|
||||
beast::String const value = line.substring (equalPos + 1,
|
||||
line.length ());
|
||||
|
||||
result.set (key, value);
|
||||
result.set (
|
||||
line.substr (0, equalPos),
|
||||
line.substr (equalPos + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,7 +473,7 @@ void RFC1751::getEnglishFromKey (std::string& strHuman, std::string const& strKe
|
||||
strHuman = strFirst + " " + strSecond;
|
||||
}
|
||||
|
||||
beast::String RFC1751::getWordFromBlob (void const* data, size_t bytes)
|
||||
std::string RFC1751::getWordFromBlob (void const* data, size_t bytes)
|
||||
{
|
||||
std::uint32_t hash;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
it to turn the pubkey_node into an easily remembered and identified
|
||||
4 character string.
|
||||
*/
|
||||
static beast::String getWordFromBlob (void const* data, size_t bytes);
|
||||
static std::string getWordFromBlob (void const* data, size_t bytes);
|
||||
|
||||
private:
|
||||
static unsigned long extract (char const* s, int start, int length);
|
||||
|
||||
@@ -118,10 +118,10 @@ public:
|
||||
|
||||
bool const result = amount.setValue (value);
|
||||
|
||||
expect (result == success, std::string ("parse ") + value);
|
||||
expect (result == success, "parse " + value);
|
||||
|
||||
if (success)
|
||||
expect (amount.getText () == value, std::string ("format ") + value);
|
||||
expect (amount.getText () == value, "format " + value);
|
||||
}
|
||||
|
||||
void testSetValue ()
|
||||
@@ -449,29 +449,17 @@ public:
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
template <class Cond>
|
||||
bool
|
||||
expect (Cond cond, beast::String const& s)
|
||||
{
|
||||
return suite::expect (cond, s.toStdString());
|
||||
}
|
||||
|
||||
template <class Cond>
|
||||
bool
|
||||
expect (Cond cond)
|
||||
{
|
||||
return suite::expect (cond);
|
||||
}
|
||||
|
||||
void testUnderflow ()
|
||||
{
|
||||
testcase ("underflow");
|
||||
|
||||
STAmount bigNative (STAmount::cMaxNative / 2);
|
||||
STAmount bigValue (noIssue(),
|
||||
(STAmount::cMinValue + STAmount::cMaxValue) / 2, STAmount::cMaxOffset - 1);
|
||||
(STAmount::cMinValue + STAmount::cMaxValue) / 2,
|
||||
STAmount::cMaxOffset - 1);
|
||||
STAmount smallValue (noIssue(),
|
||||
(STAmount::cMinValue + STAmount::cMaxValue) / 2, STAmount::cMinOffset + 1);
|
||||
(STAmount::cMinValue + STAmount::cMaxValue) / 2,
|
||||
STAmount::cMinOffset + 1);
|
||||
STAmount zeroSt (noIssue(), 0);
|
||||
|
||||
STAmount smallXsmall = multiply (smallValue, smallValue, noIssue());
|
||||
@@ -480,7 +468,7 @@ public:
|
||||
|
||||
STAmount bigDsmall = divide (smallValue, bigValue, noIssue());
|
||||
|
||||
expect (bigDsmall == zero, beast::String ("small/big != 0: ") + bigDsmall.getText ());
|
||||
expect (bigDsmall == zero, "small/big != 0: " + bigDsmall.getText ());
|
||||
|
||||
#if 0
|
||||
// TODO(tom): this test makes no sense - we should have no way to have
|
||||
@@ -488,15 +476,18 @@ public:
|
||||
bigDsmall = divide (smallValue, bigNative, noCurrency(), xrpAccount ());
|
||||
#endif
|
||||
|
||||
expect (bigDsmall == zero, beast::String ("small/bigNative != 0: ") + bigDsmall.getText ());
|
||||
expect (bigDsmall == zero,
|
||||
"small/bigNative != 0: " + bigDsmall.getText ());
|
||||
|
||||
bigDsmall = divide (smallValue, bigValue, xrpIssue ());
|
||||
|
||||
expect (bigDsmall == zero, beast::String ("(small/big)->N != 0: ") + bigDsmall.getText ());
|
||||
expect (bigDsmall == zero,
|
||||
"(small/big)->N != 0: " + bigDsmall.getText ());
|
||||
|
||||
bigDsmall = divide (smallValue, bigNative, xrpIssue ());
|
||||
|
||||
expect (bigDsmall == zero, beast::String ("(small/bigNative)->N != 0: ") + bigDsmall.getText ());
|
||||
expect (bigDsmall == zero,
|
||||
"(small/bigNative)->N != 0: " + bigDsmall.getText ());
|
||||
|
||||
// very bad offer
|
||||
std::uint64_t r = getRate (smallValue, bigValue);
|
||||
|
||||
@@ -37,7 +37,9 @@ public:
|
||||
getConfig ().RPC_SSL_CERT,
|
||||
getConfig ().RPC_SSL_CHAIN))
|
||||
{
|
||||
WriteLog (lsINFO, RPCDoor) << "RPC port: " << getConfig ().getRpcAddress().toRawUTF8() << " allow remote: " << getConfig ().RPC_ALLOW_REMOTE;
|
||||
WriteLog (lsINFO, RPCDoor) <<
|
||||
"RPC port: " << getConfig ().getRpcAddress() <<
|
||||
" allow remote: " << getConfig ().RPC_ALLOW_REMOTE;
|
||||
|
||||
startListening ();
|
||||
}
|
||||
@@ -47,7 +49,7 @@ public:
|
||||
~RPCDoorImp ()
|
||||
{
|
||||
WriteLog (lsINFO, RPCDoor) <<
|
||||
"RPC port: " << getConfig ().getRpcAddress().toRawUTF8() <<
|
||||
"RPC port: " << getConfig ().getRpcAddress() <<
|
||||
" allow remote: " << getConfig ().RPC_ALLOW_REMOTE;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
This is used for diagnostics and may not reflect the actual path
|
||||
or paths used by the underlying backend.
|
||||
*/
|
||||
virtual beast::String getName () const = 0;
|
||||
virtual std::string getName () const = 0;
|
||||
|
||||
/** Fetch an object.
|
||||
If the object is known to be not in the database, isn't found in the
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
virtual ~Factory () = 0;
|
||||
|
||||
/** Retrieve the name of this factory. */
|
||||
virtual beast::String getName () const = 0;
|
||||
virtual std::string getName () const = 0;
|
||||
|
||||
/** Create an instance of this factory's backend.
|
||||
@param keyBytes The fixed number of bytes per key.
|
||||
|
||||
@@ -233,7 +233,7 @@ public:
|
||||
class HyperDBFactory : public NodeStore::Factory
|
||||
{
|
||||
public:
|
||||
beast::String
|
||||
std::string
|
||||
getName () const
|
||||
{
|
||||
return "HyperLevelDB";
|
||||
|
||||
@@ -254,7 +254,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
beast::String
|
||||
std::string
|
||||
getName () const
|
||||
{
|
||||
return "LevelDB";
|
||||
|
||||
@@ -105,7 +105,7 @@ public:
|
||||
class MemoryFactory : public Factory
|
||||
{
|
||||
public:
|
||||
beast::String
|
||||
std::string
|
||||
getName () const
|
||||
{
|
||||
return "Memory";
|
||||
|
||||
@@ -72,7 +72,8 @@ private:
|
||||
class NullFactory : public Factory
|
||||
{
|
||||
public:
|
||||
beast::String getName () const
|
||||
std::string
|
||||
getName () const
|
||||
{
|
||||
return "none";
|
||||
}
|
||||
|
||||
@@ -356,7 +356,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
beast::String
|
||||
std::string
|
||||
getName () const
|
||||
{
|
||||
return "RocksDB";
|
||||
|
||||
@@ -92,7 +92,8 @@ public:
|
||||
e.join();
|
||||
}
|
||||
|
||||
beast::String getName () const
|
||||
std::string
|
||||
getName () const
|
||||
{
|
||||
return m_backend->getName ();
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
#include <ripple/nodestore/Manager.h>
|
||||
|
||||
#include <beast/utility/ci_char_traits.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace NodeStore {
|
||||
|
||||
@@ -67,10 +69,14 @@ public:
|
||||
Factory*
|
||||
find (std::string const& name) const
|
||||
{
|
||||
beast::ci_equal_to casecmp;
|
||||
|
||||
for (List::const_iterator iter (m_list.begin ());
|
||||
iter != m_list.end (); ++iter)
|
||||
if ((*iter)->getName().compareIgnoreCase (name) == 0)
|
||||
{
|
||||
if (casecmp ((*iter)->getName(), name))
|
||||
return iter->get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,14 +27,14 @@ namespace NodeStore {
|
||||
class Backend_test : public TestBase
|
||||
{
|
||||
public:
|
||||
void testBackend (beast::String type, std::int64_t const seedValue,
|
||||
void testBackend (std::string const& type, std::int64_t const seedValue,
|
||||
int numObjectsToTest = 2000)
|
||||
{
|
||||
std::unique_ptr <Manager> manager (make_Manager ());
|
||||
|
||||
DummyScheduler scheduler;
|
||||
|
||||
testcase ((beast::String ("Backend type=") + type).toStdString());
|
||||
testcase ("Backend type=" + type);
|
||||
|
||||
beast::StringPairArray params;
|
||||
beast::File const path (beast::File::createTempFile ("node_db"));
|
||||
|
||||
@@ -23,7 +23,8 @@ namespace NodeStore {
|
||||
class NodeStoreDatabase_test : public TestBase
|
||||
{
|
||||
public:
|
||||
void testImport (beast::String destBackendType, beast::String srcBackendType, std::int64_t seedValue)
|
||||
void testImport (std::string const& destBackendType,
|
||||
std::string const& srcBackendType, std::int64_t seedValue)
|
||||
{
|
||||
std::unique_ptr <Manager> manager (make_Manager ());
|
||||
|
||||
@@ -63,7 +64,8 @@ public:
|
||||
std::unique_ptr <Database> dest (manager->make_Database (
|
||||
"test", scheduler, j, 2, destParams));
|
||||
|
||||
testcase ((beast::String ("import into '") + destBackendType + "' from '" + srcBackendType + "'").toStdString());
|
||||
testcase ("import into '" + destBackendType +
|
||||
"' from '" + srcBackendType + "'");
|
||||
|
||||
// Do the import
|
||||
dest->import (*src);
|
||||
@@ -80,7 +82,7 @@ public:
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void testNodeStore (beast::String type,
|
||||
void testNodeStore (std::string const& type,
|
||||
bool const useEphemeralDatabase,
|
||||
bool const testPersistence,
|
||||
std::int64_t const seedValue,
|
||||
@@ -90,12 +92,11 @@ public:
|
||||
|
||||
DummyScheduler scheduler;
|
||||
|
||||
beast::String s;
|
||||
s << beast::String ("NodeStore backend '") + type + "'";
|
||||
std::string s = "NodeStore backend '" + type + "'";
|
||||
if (useEphemeralDatabase)
|
||||
s << " (with ephemeral database)";
|
||||
s += " (with ephemeral database)";
|
||||
|
||||
testcase (s.toStdString());
|
||||
testcase (s);
|
||||
|
||||
beast::File const node_db (beast::File::createTempFile ("node_db"));
|
||||
beast::StringPairArray nodeParams;
|
||||
|
||||
@@ -53,15 +53,13 @@ public:
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void testBackend (beast::String type, std::int64_t const seedValue)
|
||||
void testBackend (std::string const& type, std::int64_t const seedValue)
|
||||
{
|
||||
std::unique_ptr <Manager> manager (make_Manager ());
|
||||
|
||||
DummyScheduler scheduler;
|
||||
|
||||
beast::String s;
|
||||
s << "Testing backend '" << type << "' performance";
|
||||
testcase (s.toStdString());
|
||||
testcase ("Testing backend '" + type + "' performance");
|
||||
|
||||
beast::StringPairArray params;
|
||||
beast::File const path (beast::File::createTempFile ("node_db"));
|
||||
@@ -85,25 +83,19 @@ public:
|
||||
// Individual write batch test
|
||||
t.start ();
|
||||
storeBatch (*backend, batch1);
|
||||
s = "";
|
||||
s << " Single write: " << beast::String (t.getElapsed (), 2) << " seconds";
|
||||
log << s.toStdString();
|
||||
log << " Single write: " << std::to_string (t.getElapsed ()) << " seconds";
|
||||
|
||||
// Bulk write batch test
|
||||
t.start ();
|
||||
backend->storeBatch (batch2);
|
||||
s = "";
|
||||
s << " Batch write: " << beast::String (t.getElapsed (), 2) << " seconds";
|
||||
log << s.toStdString();
|
||||
log << " Batch write: " << std::to_string (t.getElapsed ()) << " seconds";
|
||||
|
||||
// Read test
|
||||
Batch copy;
|
||||
t.start ();
|
||||
fetchCopyOfBatch (*backend, ©, batch1);
|
||||
fetchCopyOfBatch (*backend, ©, batch2);
|
||||
s = "";
|
||||
s << " Batch read: " << beast::String (t.getElapsed (), 2) << " seconds";
|
||||
log << s.toStdString();
|
||||
log << " Batch read: " << std::to_string (t.getElapsed ()) << " seconds";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -173,7 +173,7 @@ public:
|
||||
createGossip (g[i]);
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
logic.importConsumers (beast::String::fromNumber (i).toStdString(), g[i]);
|
||||
logic.importConsumers (std::to_string (i), g[i]);
|
||||
|
||||
pass();
|
||||
}
|
||||
|
||||
@@ -51,15 +51,12 @@ struct Results
|
||||
return *this;
|
||||
}
|
||||
|
||||
beast::String toString () const
|
||||
std::string to_string () const
|
||||
{
|
||||
using beast::String;
|
||||
String s;
|
||||
s = "steps(" + String::fromNumber (steps) + ")"
|
||||
+ ", sent(" + String::fromNumber (sent) + ")"
|
||||
+ ", received(" + String::fromNumber (received) + ")"
|
||||
+ ", dropped(" + String::fromNumber (dropped) + ")";
|
||||
return s;
|
||||
return "steps=" + std::to_string (steps) +
|
||||
", sent=" + std::to_string (sent) +
|
||||
", received=" + std::to_string (received) +
|
||||
", dropped=" + std::to_string (dropped);
|
||||
}
|
||||
|
||||
Results& operator+= (Results const& other)
|
||||
|
||||
@@ -27,32 +27,17 @@ namespace TestOverlay
|
||||
class SimplePayload
|
||||
{
|
||||
public:
|
||||
SimplePayload ()
|
||||
{
|
||||
}
|
||||
SimplePayload () = default;
|
||||
SimplePayload (SimplePayload const& other) = default;
|
||||
SimplePayload& operator= (SimplePayload const& other) = default;
|
||||
|
||||
SimplePayload (int what, beast::String data = beast::String::empty, int hops = 0)
|
||||
SimplePayload (int what, std::string const& data = "", int hops = 0)
|
||||
: m_hops (hops)
|
||||
, m_what (what)
|
||||
, m_data (data)
|
||||
{
|
||||
}
|
||||
|
||||
SimplePayload (SimplePayload const& other)
|
||||
: m_hops (other.m_hops)
|
||||
, m_what (other.m_what)
|
||||
, m_data (other.m_data)
|
||||
{
|
||||
}
|
||||
|
||||
SimplePayload& operator= (SimplePayload const& other)
|
||||
{
|
||||
m_hops = other.m_hops;
|
||||
m_what = other.m_what;
|
||||
m_data = other.m_data;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SimplePayload withHop () const
|
||||
{
|
||||
return SimplePayload (m_what, m_data, m_hops + 1);
|
||||
@@ -68,7 +53,7 @@ public:
|
||||
return m_what;
|
||||
}
|
||||
|
||||
beast::String data () const
|
||||
std::string data () const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
@@ -76,7 +61,7 @@ public:
|
||||
private:
|
||||
int m_hops;
|
||||
int m_what;
|
||||
beast::String m_data;
|
||||
std::string m_data;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -118,20 +118,14 @@ public:
|
||||
Results result;
|
||||
for (int i = 0; result.received < 249 && i < 100; ++i)
|
||||
{
|
||||
using beast::String;
|
||||
String s =
|
||||
String ("step #") + String::fromNumber (
|
||||
network.steps()) + " ";
|
||||
auto s = "step #" + std::to_string (network.steps()) + " ";
|
||||
result += network.step ();
|
||||
s << result.toString ();
|
||||
log << s.toStdString();
|
||||
log << s << result.to_string ();
|
||||
}
|
||||
|
||||
int const seen (network.state().seen());
|
||||
|
||||
beast::String s = "Seen = " + beast::String::fromNumber (seen);
|
||||
log <<
|
||||
s.toStdString();
|
||||
log << "Seen = " << std::to_string (seen);
|
||||
pass ();
|
||||
}
|
||||
|
||||
|
||||
@@ -68,10 +68,8 @@ public:
|
||||
Can be called from any thread.
|
||||
*/
|
||||
/** @{ */
|
||||
virtual void addStrings (beast::String name,
|
||||
virtual void addStrings (std::string const& name,
|
||||
std::vector <std::string> const& strings) = 0;
|
||||
virtual void addStrings (beast::String name,
|
||||
beast::StringArray const& stringArray) = 0;
|
||||
virtual void addFile (beast::File const& file) = 0;
|
||||
virtual void addStaticSource (Validators::Source* source) = 0;
|
||||
/** @} */
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
RipplePublicKey publicKey;
|
||||
|
||||
/** Optional human readable comment describing the validator. */
|
||||
beast::String label;
|
||||
std::string label;
|
||||
};
|
||||
|
||||
/** Destroy the Source.
|
||||
@@ -55,10 +55,10 @@ public:
|
||||
/** An identifier that uniquely describes the source.
|
||||
This is used for identification in the database.
|
||||
*/
|
||||
virtual beast::String uniqueID () const = 0;
|
||||
virtual std::string uniqueID () const = 0;
|
||||
|
||||
/** A string that is used to recreate the source from the database entry. */
|
||||
virtual beast::String createParam () = 0;
|
||||
virtual std::string createParam () = 0;
|
||||
|
||||
/** Cancel any pending fetch.
|
||||
The default implementation does nothing.
|
||||
@@ -74,8 +74,7 @@ public:
|
||||
Results ();
|
||||
|
||||
bool success;
|
||||
// VFALCO TODO Replace with std::string
|
||||
beast::String message;
|
||||
std::string message;
|
||||
// VFALCO TODO Replace with chrono
|
||||
beast::Time expirationTime;
|
||||
std::vector <Item> list;
|
||||
|
||||
@@ -216,7 +216,7 @@ public:
|
||||
|
||||
// Returns `true` if a Source with the same unique ID already exists
|
||||
//
|
||||
bool findSourceByID (beast::String id)
|
||||
bool findSourceByID (std::string id)
|
||||
{
|
||||
for (SourceTable::const_iterator iter (m_sources.begin());
|
||||
iter != m_sources.end(); ++iter)
|
||||
@@ -364,7 +364,7 @@ public:
|
||||
|
||||
m_journal.debug <<
|
||||
"Rebuilt chosen list with " <<
|
||||
beast::String::fromNumber (m_chosenList->size()) << " entries";
|
||||
std::to_string (m_chosenList->size()) << " entries";
|
||||
}
|
||||
|
||||
/** Mark the Chosen List for a rebuild. */
|
||||
|
||||
@@ -198,25 +198,15 @@ public:
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void addStrings (beast::String name, std::vector <std::string> const& strings)
|
||||
void addStrings (std::string const& name, std::vector <std::string> const& strings)
|
||||
{
|
||||
beast::StringArray stringArray;
|
||||
stringArray.ensureStorageAllocated (strings.size());
|
||||
for (std::size_t i = 0; i < strings.size(); ++i)
|
||||
stringArray.add (strings [i]);
|
||||
addStrings (name, stringArray);
|
||||
}
|
||||
|
||||
void addStrings (beast::String name, beast::StringArray const& stringArray)
|
||||
{
|
||||
if (stringArray.size() > 0)
|
||||
{
|
||||
addStaticSource (SourceStrings::New (name, stringArray));
|
||||
}
|
||||
else
|
||||
if (strings.empty ())
|
||||
{
|
||||
m_journal.debug << "Static source '" << name << "' is empty.";
|
||||
return;
|
||||
}
|
||||
|
||||
addStaticSource (SourceStrings::New (name, strings));
|
||||
}
|
||||
|
||||
void addFile (beast::File const& file)
|
||||
|
||||
@@ -45,14 +45,14 @@ public:
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
beast::String uniqueID () const
|
||||
std::string uniqueID () const
|
||||
{
|
||||
return "File," + m_file.getFullPathName ();
|
||||
return "File," + m_file.getFullPathName ().toStdString();
|
||||
}
|
||||
|
||||
beast::String createParam ()
|
||||
std::string createParam ()
|
||||
{
|
||||
return m_file.getFullPathName ();
|
||||
return m_file.getFullPathName ().toStdString();
|
||||
}
|
||||
|
||||
void fetch (Results& results, beast::Journal journal)
|
||||
|
||||
@@ -25,8 +25,7 @@ class SourceStringsImp
|
||||
, public beast::LeakChecked <SourceStringsImp>
|
||||
{
|
||||
public:
|
||||
SourceStringsImp (
|
||||
beast::String name, beast::StringArray const& strings)
|
||||
SourceStringsImp (std::string const& name, std::vector <std::string> const& strings)
|
||||
: m_name (name)
|
||||
, m_strings (strings)
|
||||
{
|
||||
@@ -38,18 +37,18 @@ public:
|
||||
|
||||
std::string to_string () const
|
||||
{
|
||||
return m_name.toStdString();
|
||||
return m_name;
|
||||
}
|
||||
|
||||
beast::String uniqueID () const
|
||||
std::string uniqueID () const
|
||||
{
|
||||
// VFALCO TODO This can't be right...?
|
||||
return beast::String::empty;
|
||||
return std::string{};
|
||||
}
|
||||
|
||||
beast::String createParam ()
|
||||
std::string createParam ()
|
||||
{
|
||||
return beast::String::empty;
|
||||
return std::string{};
|
||||
}
|
||||
|
||||
void fetch (Results& results, beast::Journal journal)
|
||||
@@ -57,10 +56,7 @@ public:
|
||||
results.list.reserve (m_strings.size ());
|
||||
|
||||
for (int i = 0; i < m_strings.size (); ++i)
|
||||
{
|
||||
std::string const s (m_strings [i].toStdString ());
|
||||
Utilities::parseResultLine (results, s);
|
||||
}
|
||||
Utilities::parseResultLine (results, m_strings [i]);
|
||||
|
||||
results.success = results.list.size () > 0;
|
||||
results.expirationTime = beast::Time::getCurrentTime () +
|
||||
@@ -68,14 +64,14 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
beast::String m_name;
|
||||
beast::StringArray m_strings;
|
||||
std::string m_name;
|
||||
std::vector <std::string> m_strings;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
SourceStrings* SourceStrings::New (
|
||||
beast::String name, beast::StringArray const& strings)
|
||||
std::string const& name, std::vector <std::string> const& strings)
|
||||
{
|
||||
return new SourceStringsImp (name, strings);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class SourceStrings : public Source
|
||||
{
|
||||
public:
|
||||
static SourceStrings* New (
|
||||
beast::String name, beast::StringArray const& strings);
|
||||
std::string const& name, std::vector <std::string> const& strings);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -46,14 +46,14 @@ public:
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
beast::String uniqueID () const
|
||||
std::string uniqueID () const
|
||||
{
|
||||
return "URL," + m_url.toString();
|
||||
return "URL," + m_url.to_string();
|
||||
}
|
||||
|
||||
beast::String createParam ()
|
||||
std::string createParam ()
|
||||
{
|
||||
return m_url.toString();
|
||||
return m_url.to_string();
|
||||
}
|
||||
|
||||
void cancel ()
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
namespace ripple {
|
||||
namespace Validators {
|
||||
|
||||
@@ -65,10 +67,10 @@ void StoreSqdb::insert (SourceDesc& desc)
|
||||
{
|
||||
beast::Error error;
|
||||
|
||||
beast::String const sourceID (desc.source->uniqueID().toStdString());
|
||||
beast::String const createParam (desc.source->createParam().toStdString());
|
||||
beast::String const lastFetchTime (Utilities::timeToString (desc.lastFetchTime));
|
||||
beast::String const expirationTime (Utilities::timeToString (desc.expirationTime));
|
||||
auto const sourceID (desc.source->uniqueID());
|
||||
auto const createParam (desc.source->createParam());
|
||||
auto const lastFetchTime (timeToString (desc.lastFetchTime));
|
||||
auto const expirationTime (timeToString (desc.expirationTime));
|
||||
|
||||
beast::sqdb::statement st = (m_session.prepare <<
|
||||
"INSERT INTO Validators_Source ( "
|
||||
@@ -101,14 +103,80 @@ void StoreSqdb::insert (SourceDesc& desc)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
std::string StoreSqdb::itos (int i, std::size_t width)
|
||||
{
|
||||
auto s = std::to_string (i);
|
||||
|
||||
if (s.length () < width)
|
||||
s = std::string (width - s.length(), '0').append (s);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
beast::Time StoreSqdb::stringToTime (std::string const& s)
|
||||
{
|
||||
static boost::regex const date_pattern (
|
||||
"^" // the beginning of the string
|
||||
"(19[789][0-9]|[2-9][0-9][0-9][0-9])-" // 1970-9999 followed by -
|
||||
"(0[0-9]|1[01])-" // 0-11 followed by -
|
||||
"(0[1-9]|[12][0-9]|3[01]) " // 1-31 followed by space
|
||||
"([01][0-9]|2[0-3]):" // 0-23 followed by :
|
||||
"([0-5][0-9]):" // 0-59 followed by :
|
||||
"([0-5][0-9])" // 0-59
|
||||
"$",
|
||||
boost::regex_constants::optimize);
|
||||
|
||||
boost::smatch match;
|
||||
|
||||
if (boost::regex_match (s, match, date_pattern))
|
||||
{
|
||||
int const year = beast::lexicalCast<int> (std::string (match[1]), -1);
|
||||
int const mon = beast::lexicalCast<int> (std::string (match[2]), -1);
|
||||
int const day = beast::lexicalCast<int> (std::string (match[3]), -1);
|
||||
int const hour = beast::lexicalCast<int> (std::string (match[4]), -1);
|
||||
int const min = beast::lexicalCast<int> (std::string (match[5]), -1);
|
||||
int const sec = beast::lexicalCast<int> (std::string (match[6]), -1);
|
||||
|
||||
if (year != -1 &&
|
||||
mon != -1 &&
|
||||
day != -1 &&
|
||||
hour != -1 &&
|
||||
min != -1 &&
|
||||
sec != -1)
|
||||
{
|
||||
// local time
|
||||
return beast::Time (year, mon, day, hour, min, sec, 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
return beast::Time (0);
|
||||
}
|
||||
|
||||
std::string StoreSqdb::timeToString (beast::Time const& t)
|
||||
{
|
||||
std::string ret;
|
||||
|
||||
if (t.isNotNull ())
|
||||
{
|
||||
ret = itos (t.getYear(), 4) + "-" +
|
||||
itos (t.getMonth(), 2) + "-" +
|
||||
itos (t.getDayOfMonth (), 2) + " " +
|
||||
itos (t.getHours () , 2) + ":" +
|
||||
itos (t.getMinutes (), 2) + ":" +
|
||||
itos (t.getSeconds(), 2);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
void StoreSqdb::update (SourceDesc& desc, bool updateFetchResults)
|
||||
{
|
||||
beast::Error error;
|
||||
|
||||
beast::String const sourceID (desc.source->uniqueID());
|
||||
beast::String const lastFetchTime (Utilities::timeToString (desc.lastFetchTime));
|
||||
beast::String const expirationTime (Utilities::timeToString (desc.expirationTime));
|
||||
std::string const sourceID (desc.source->uniqueID());
|
||||
std::string const lastFetchTime (timeToString (desc.lastFetchTime));
|
||||
std::string const expirationTime (timeToString (desc.expirationTime));
|
||||
|
||||
beast::sqdb::transaction tr (m_session);
|
||||
|
||||
@@ -136,7 +204,7 @@ void StoreSqdb::update (SourceDesc& desc, bool updateFetchResults)
|
||||
if (! error)
|
||||
{
|
||||
std::string publicKeyString;
|
||||
beast::String label;
|
||||
std::string label;
|
||||
|
||||
beast::sqdb::statement st = (m_session.prepare <<
|
||||
"INSERT INTO Validators_SourceItem ( "
|
||||
@@ -197,9 +265,10 @@ bool StoreSqdb::select (SourceDesc& desc)
|
||||
|
||||
beast::Error error;
|
||||
|
||||
beast::String const sourceID (desc.source->uniqueID());
|
||||
beast::String lastFetchTime;
|
||||
beast::String expirationTime;
|
||||
std::string const sourceID (desc.source->uniqueID());
|
||||
std::string lastFetchTime;
|
||||
std::string expirationTime;
|
||||
|
||||
beast::sqdb::statement st = (m_session.prepare <<
|
||||
"SELECT "
|
||||
" lastFetchTime, "
|
||||
@@ -217,8 +286,8 @@ bool StoreSqdb::select (SourceDesc& desc)
|
||||
"Found record for " << *desc.source;
|
||||
|
||||
found = true;
|
||||
desc.lastFetchTime = Utilities::stringToTime (lastFetchTime);
|
||||
desc.expirationTime = Utilities::stringToTime (expirationTime);
|
||||
desc.lastFetchTime = stringToTime (lastFetchTime);
|
||||
desc.expirationTime = stringToTime (expirationTime);
|
||||
}
|
||||
else if (! error)
|
||||
{
|
||||
@@ -243,7 +312,7 @@ void StoreSqdb::selectList (SourceDesc& desc)
|
||||
{
|
||||
beast::Error error;
|
||||
|
||||
beast::String const sourceID (desc.source->uniqueID());
|
||||
std::string const sourceID (desc.source->uniqueID());
|
||||
|
||||
// Get the count
|
||||
std::size_t count;
|
||||
|
||||
@@ -62,6 +62,12 @@ private:
|
||||
|
||||
beast::Journal m_journal;
|
||||
beast::sqdb::session m_session;
|
||||
|
||||
|
||||
// DEPRECATED
|
||||
static std::string itos (int i, std::size_t fieldSize = 0);
|
||||
static std::string timeToString (beast::Time const& t);
|
||||
static beast::Time stringToTime (std::string const& s);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
|
||||
struct TestSource : Source
|
||||
{
|
||||
TestSource (beast::String const& name, std::uint32_t start, std::uint32_t end)
|
||||
TestSource (std::string const& name, std::uint32_t start, std::uint32_t end)
|
||||
: m_name (name)
|
||||
, m_start (start)
|
||||
, m_end (end)
|
||||
@@ -44,38 +44,37 @@ public:
|
||||
|
||||
std::string to_string () const
|
||||
{
|
||||
return uniqueID().toStdString();
|
||||
return uniqueID();
|
||||
}
|
||||
|
||||
beast::String uniqueID () const
|
||||
std::string uniqueID () const
|
||||
{
|
||||
using beast::String;
|
||||
return String ("Test,") + m_name + "," +
|
||||
String::fromNumber (m_start) + "," +
|
||||
String::fromNumber (m_end);
|
||||
return "Test," + m_name + "," +
|
||||
std::to_string (m_start) + "," +
|
||||
std::to_string (m_end);
|
||||
}
|
||||
|
||||
beast::String createParam ()
|
||||
std::string createParam ()
|
||||
{
|
||||
return beast::String::empty;
|
||||
return std::string{};
|
||||
}
|
||||
|
||||
void fetch (Results& results, beast::Journal)
|
||||
{
|
||||
results.success = true;
|
||||
results.message = beast::String::empty;
|
||||
results.message = std::string{};
|
||||
results.list.reserve (numberOfTestValidators);
|
||||
|
||||
for (std::uint32_t i = m_start ; i < m_end; ++i)
|
||||
{
|
||||
Item item;;
|
||||
Item item;
|
||||
item.publicKey = RipplePublicKey::createFromInteger (i);
|
||||
item.label = beast::String::fromNumber (i);
|
||||
item.label = std::to_string (i);
|
||||
results.list.push_back (item);
|
||||
}
|
||||
}
|
||||
|
||||
beast::String m_name;
|
||||
std::string m_name;
|
||||
std::size_t m_start;
|
||||
std::size_t m_end;
|
||||
};
|
||||
@@ -113,7 +112,7 @@ public:
|
||||
beast::Random r;
|
||||
for (int i = 1; i <= numberofTestSources; ++i)
|
||||
{
|
||||
beast::String const name (beast::String::fromNumber (i));
|
||||
std::string const name (std::to_string (i));
|
||||
std::uint32_t const start = r.nextInt (numberOfTestValidators);
|
||||
std::uint32_t const end = start + r.nextInt (numberOfTestValidators);
|
||||
logic.add (new TestSource (name, start, end));
|
||||
|
||||
@@ -136,74 +136,5 @@ void Utilities::parseResultLine (
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
beast::String Utilities::itos (int i, int fieldSize)
|
||||
{
|
||||
return beast::String::fromNumber (i).paddedLeft (beast::beast_wchar('0'), fieldSize);
|
||||
}
|
||||
|
||||
beast::String Utilities::timeToString (beast::Time const& t)
|
||||
{
|
||||
if (t.isNotNull ())
|
||||
{
|
||||
return
|
||||
itos (t.getYear(), 4) + "-" +
|
||||
itos (t.getMonth(), 2) + "-" +
|
||||
itos (t.getDayOfMonth (), 2) + " " +
|
||||
itos (t.getHours () , 2) + ":" +
|
||||
itos (t.getMinutes (), 2) + ":" +
|
||||
itos (t.getSeconds(), 2);
|
||||
}
|
||||
|
||||
return beast::String::empty;
|
||||
}
|
||||
|
||||
int Utilities::stoi (beast::String& s, int fieldSize, int minValue, int maxValue,
|
||||
beast::beast_wchar delimiter)
|
||||
{
|
||||
int const needed (fieldSize + ((delimiter != 0) ? 1 : 0));
|
||||
beast::String const v (s.substring (0, needed));
|
||||
s = s.substring (v.length ());
|
||||
if (s.length() == needed)
|
||||
{
|
||||
int const v (s.getIntValue());
|
||||
if (s.startsWith (itos (v, fieldSize)) &&
|
||||
v >= minValue && v <= maxValue &&
|
||||
(delimiter == 0 || s.endsWithChar (delimiter)))
|
||||
{
|
||||
return v;
|
||||
}
|
||||
}
|
||||
return -1; // fail
|
||||
}
|
||||
|
||||
beast::Time Utilities::stringToTime (beast::String s)
|
||||
{
|
||||
if (s.isNotEmpty ())
|
||||
{
|
||||
int const year (stoi (s, 4, 1970, 9999, '-'));
|
||||
int const mon (stoi (s, 2, 0, 11, '-'));
|
||||
int const day (stoi (s, 2, 1, 31, ' '));
|
||||
int const hour (stoi (s, 2, 0, 23, ':'));
|
||||
int const min (stoi (s, 2, 0, 59, ':'));
|
||||
int const sec (stoi (s, 2, 0, 59, 0 ));
|
||||
if (year != -1 &&
|
||||
mon != -1 &&
|
||||
day != -1 &&
|
||||
hour != -1 &&
|
||||
min != -1 &&
|
||||
sec != -1)
|
||||
{
|
||||
// local time
|
||||
return beast::Time (year, mon, day, hour, min, sec, 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
return beast::Time (0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,15 +121,6 @@ public:
|
||||
std::string const& line,
|
||||
beast::Journal journal = beast::Journal());
|
||||
|
||||
// helpers
|
||||
static beast::String itos (int i, int fieldSize = 0);
|
||||
static int stoi (beast::String& s, int fieldSize, int minValue, int maxValue,
|
||||
beast::beast_wchar delimiter);
|
||||
|
||||
// conversion betwen Time and String
|
||||
static beast::String timeToString (beast::Time const& t);
|
||||
static beast::Time stringToTime (beast::String s);
|
||||
|
||||
struct Helpers;
|
||||
|
||||
/** Parse a string into a Source::Item.
|
||||
|
||||
Reference in New Issue
Block a user