Remove the use of beast::String from rippled (RIPD-443)

This commit is contained in:
Nik Bougalis
2014-09-28 18:38:11 -07:00
committed by Vinnie Falco
parent 4241dbb600
commit c0b69e8ef7
45 changed files with 285 additions and 342 deletions

View File

@@ -243,18 +243,16 @@ Ledger::~Ledger ()
{ {
if (mTransactionMap) if (mTransactionMap)
{ {
logTimedDestroy <Ledger> ( logTimedDestroy <Ledger> (mTransactionMap,
mTransactionMap, "mTransactionMap with " +
"mTransactionMap with " std::to_string(mTransactionMap->size ()) + " items");
+ std::to_string(mTransactionMap->size ()) + " items");
} }
if (mAccountStateMap) if (mAccountStateMap)
{ {
logTimedDestroy <Ledger> ( logTimedDestroy <Ledger> (mAccountStateMap,
mAccountStateMap, "mAccountStateMap with " +
"mAccountStateMap with " std::to_string (mAccountStateMap->size ()) + " items");
+ std::to_string (mAccountStateMap->size ()) + " items");
} }
} }

View File

@@ -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; std::vector <std::unique_ptr <NodeStore::Factory>> list;
// VFALCO NOTE SqliteFactory is here because it has // VFALCO NOTE SqliteFactory is here because it has
// dependencies like SqliteDatabase and DatabaseCon // dependencies like SqliteDatabase and DatabaseCon
// //
list.emplace_back (make_SqliteFactory ()); list.emplace_back (make_SqliteFactory (hashnode_cache_size));
return list; return list;
} }
@@ -241,7 +243,8 @@ public:
, m_journal (m_logs.journal("Application")) , m_journal (m_logs.journal("Application"))
, m_nodeStoreManager (NodeStore::make_Manager ( , 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_tempNodeCache ("NodeCache", 16384, 90, get_seconds_clock (),
m_logs.journal("TaggedCache")) m_logs.journal("TaggedCache"))

View File

@@ -167,13 +167,14 @@ int run (int argc, char** argv)
int iResult = 0; int iResult = 0;
po::variables_map vm; po::variables_map vm;
beast::String importDescription; std::string importText;
{ {
importDescription << importText += "Import an existing node database (specified in the [";
"Import an existing node database (specified in the " << importText += ConfigSection::importNodeDatabase ();
"[" << ConfigSection::importNodeDatabase () << "] configuration file section) " importText += "] configuration file section) into the current ";
"into the current node database (specified in the " << importText += "node database (specified in the [";
"[" << ConfigSection::nodeDatabase () << "] configuration file section). "; importText += ConfigSection::nodeDatabase ();
importText += "] configuration file section).";
} }
// VFALCO TODO Replace boost program options with something from Beast. // 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.") ("start", "Start from a fresh Ledger.")
("net", "Get the initial ledger from the network.") ("net", "Get the initial ledger from the network.")
("fg", "Run in the foreground.") ("fg", "Run in the foreground.")
("import", importDescription.toStdString ().c_str ()) ("import", importText.c_str ())
("version", "Display the build version.") ("version", "Display the build version.")
; ;
@@ -240,8 +241,8 @@ int run (int argc, char** argv)
if (vm.count ("version")) if (vm.count ("version"))
{ {
beast::String const& s (BuildInfo::getVersionString ()); std::cout << "rippled version " <<
std::cout << "rippled version " << s.toStdString() << std::endl; BuildInfo::getVersionString () << std::endl;
return 0; return 0;
} }

View File

@@ -371,10 +371,6 @@ public:
ProofOfWorkFactoryImp gen; ProofOfWorkFactoryImp gen;
ProofOfWork pow = gen.getProof (); ProofOfWork pow = gen.getProof ();
beast::String s;
s << "solve difficulty " << beast::String (pow.getDifficulty ());
uint256 solution = pow.solve (16777216); uint256 solution = pow.solve (16777216);
expect (! solution.isZero (), "Should be solved"); expect (! solution.isZero (), "Should be solved");

View File

@@ -51,16 +51,13 @@ static int s_nodeStoreDBCount = RIPPLE_ARRAYSIZE (s_nodeStoreDBInit);
class SqliteBackend : public NodeStore::Backend class SqliteBackend : public NodeStore::Backend
{ {
public: public:
explicit SqliteBackend (std::string const& path) explicit SqliteBackend (std::string const& path, int hashnode_cache_size)
: m_name (path) : m_name (path)
, m_db (new DatabaseCon(path, s_nodeStoreDBInit, s_nodeStoreDBCount)) , m_db (new DatabaseCon(path, s_nodeStoreDBInit, s_nodeStoreDBCount))
{ {
beast::String s; std::string s ("PRAGMA cache_size=-");
s += std::to_string (hashnode_cache_size);
// VFALCO TODO Remove this dependency on theConfig m_db->getDB()->executeSQL (s);
//
s << "PRAGMA cache_size=-" << beast::String (getConfig ().getSize(siHashNodeDBCache) * 1024);
m_db->getDB()->executeSQL (s.toStdString ().c_str ());
} }
~SqliteBackend() ~SqliteBackend()
@@ -227,8 +224,16 @@ private:
class SqliteFactory : public NodeStore::Factory class SqliteFactory : public NodeStore::Factory
{ {
int hashnode_cache_size_;
public: public:
beast::String getName () const SqliteFactory (int hashnode_cache_size)
: hashnode_cache_size_ (hashnode_cache_size)
{
}
std::string
getName () const
{ {
return "Sqlite"; return "Sqlite";
} }
@@ -237,15 +242,16 @@ public:
size_t, NodeStore::Parameters const& keyValues, size_t, NodeStore::Parameters const& keyValues,
NodeStore::Scheduler&, beast::Journal) 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);
} }
} }

View File

@@ -27,7 +27,7 @@ namespace ripple {
/** Factory to produce SQLite backends for the NodeStore. /** Factory to produce SQLite backends for the NodeStore.
@see Database @see Database
*/ */
std::unique_ptr <NodeStore::Factory> make_SqliteFactory (); std::unique_ptr <NodeStore::Factory> make_SqliteFactory (int hashnode_cache_size);
} }

View File

@@ -83,22 +83,17 @@ SHAMap::~SHAMap ()
{ {
mState = smsInvalid; mState = smsInvalid;
logTimedDestroy <SHAMap> (mTNByID, logTimedDestroy <SHAMap> (mTNByID, "mTNByID with " +
beast::String ("mTNByID with ") + std::to_string (mTNByID.size ()) + " items");
beast::String::fromNumber (mTNByID.size ()) + " items");
if (mDirtyNodes) if (mDirtyNodes)
{ {
logTimedDestroy <SHAMap> (mDirtyNodes, logTimedDestroy <SHAMap> (mDirtyNodes, "mDirtyNodes with " +
beast::String ("mDirtyNodes with ") + std::to_string (mDirtyNodes->size ()) + " items");
beast::String::fromNumber (mDirtyNodes->size ()) + " items");
} }
if (root) if (root)
{ logTimedDestroy <SHAMap> (root, "root node");
logTimedDestroy <SHAMap> (root,
beast::String ("root node"));
}
} }
void SHAMapNodeID::setMHash () const void SHAMapNodeID::setMHash () const

View File

@@ -99,15 +99,17 @@ double timedDestroy (Object& object)
*/ */
template <typename PartitionKey, typename Object> template <typename PartitionKey, typename Object>
void logTimedDestroy ( void logTimedDestroy (
Object& object, beast::String objectDescription, double thresholdSeconds = 1) Object& object,
std::string const& objectDescription,
double thresholdSeconds = 1)
{ {
double const seconds = timedDestroy (object); double const seconds = timedDestroy (object);
if (seconds > thresholdSeconds) if (seconds > thresholdSeconds)
{ {
deprecatedLogs().journal("LoggedTimings").warning << deprecatedLogs().journal("LoggedTimings").warning <<
objectDescription << " took "<< objectDescription << " took " <<
beast::String (detail::cleanElapsed (seconds)) << detail::cleanElapsed (seconds) <<
" seconds to destroy"; " seconds to destroy";
} }
} }
@@ -116,11 +118,13 @@ void logTimedDestroy (
/** Log a timed function call if the time exceeds a threshold. */ /** Log a timed function call if the time exceeds a threshold. */
template <typename Function> template <typename Function>
void logTimedCall (beast::Journal::Stream stream, void logTimedCall (
beast::String description, beast::Journal::Stream stream,
char const* fileName, std::string const& description,
int lineNumber, char const* fileName,
Function f, double thresholdSeconds = 1) int lineNumber,
Function f,
double thresholdSeconds = 1)
{ {
double const seconds = beast::measureFunctionCallTime (f); double const seconds = beast::measureFunctionCallTime (f);
@@ -128,9 +132,9 @@ void logTimedCall (beast::Journal::Stream stream,
{ {
stream << stream <<
description << " took "<< description << " took "<<
beast::String (detail::cleanElapsed (seconds)) << detail::cleanElapsed (seconds) <<
" seconds to execute at " << " seconds to execute at " <<
beast::Debug::getSourceLocation (fileName, lineNumber); beast::Debug::getSourceLocation (fileName, lineNumber);
} }
} }

View File

@@ -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) if (arg & MultiSocket::Flag::client_role)
s << "client,"; s += "client,";
if (arg & MultiSocket::Flag::server_role) if (arg & MultiSocket::Flag::server_role)
s << "server,"; s += "server,";
if (arg & MultiSocket::Flag::ssl) if (arg & MultiSocket::Flag::ssl)
s << "ssl,"; s += "ssl,";
if (arg & MultiSocket::Flag::ssl_required) if (arg & MultiSocket::Flag::ssl_required)
s << "ssl_required,"; s += "ssl_required,";
if (arg & MultiSocket::Flag::proxy) 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; return s;
@@ -88,7 +90,7 @@ public:
return holder.context->get (); return holder.context->get ();
} }
beast::String name () const std::string name () const
{ {
return getArgName (m_flags); return getArgName (m_flags);
} }

View File

@@ -60,8 +60,7 @@ getIniFileSection (IniFileSections& secSource, std::string const& strSection);
*/ */
// DEPRECATED // DEPRECATED
beast::StringPairArray beast::StringPairArray
parseKeyValueSection (IniFileSections& secSource, parseKeyValueSection (IniFileSections& secSource, std::string const& strSection);
beast::String const& strSection);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -246,13 +245,9 @@ public:
/** Convert the RPC/port combination to a readable string. /** Convert the RPC/port combination to a readable string.
*/ */
beast::String const getRpcAddress () std::string const getRpcAddress ()
{ {
beast::String s; return m_rpcIP + ":" + std::to_string (m_rpcPort);
s << m_rpcIP.c_str () << ":" << m_rpcPort;
return s;
} }
/** Determine the level of administrative permission to grant. /** Determine the level of administrative permission to grant.

View File

@@ -30,9 +30,9 @@ namespace ripple {
// //
struct ConfigSection struct ConfigSection
{ {
static beast::String nodeDatabase () { return "node_db"; } static std::string nodeDatabase () { return "node_db"; }
static beast::String tempNodeDatabase () { return "temp_db"; } static std::string tempNodeDatabase () { return "temp_db"; }
static beast::String importNodeDatabase () { return "import_db"; } static std::string importNodeDatabase () { return "import_db"; }
}; };
// VFALCO TODO Rename and replace these macros with variables. // VFALCO TODO Rename and replace these macros with variables.

View File

@@ -145,34 +145,28 @@ bool getSingleSection (IniFileSections& secSource,
} }
beast::StringPairArray beast::StringPairArray
parseKeyValueSection (IniFileSections& secSource, parseKeyValueSection (IniFileSections& secSource, std::string const& strSection)
beast::String const& strSection)
{ {
beast::StringPairArray result; beast::StringPairArray result;
// yuck.
std::string const stdStrSection (strSection.toStdString ());
typedef IniFileSections::mapped_type Entries; typedef IniFileSections::mapped_type Entries;
Entries* const entries = getIniFileSection (secSource, stdStrSection); Entries* const entries = getIniFileSection (secSource, strSection);
if (entries != nullptr) if (entries != nullptr)
{ {
for (Entries::const_iterator iter = entries->begin (); for (Entries::const_iterator iter = entries->begin ();
iter != entries->end (); ++iter) 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); result.set (
beast::String const value = line.substring (equalPos + 1, line.substr (0, equalPos),
line.length ()); line.substr (equalPos + 1));
result.set (key, value);
} }
} }
} }

View File

@@ -473,7 +473,7 @@ void RFC1751::getEnglishFromKey (std::string& strHuman, std::string const& strKe
strHuman = strFirst + " " + strSecond; 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; std::uint32_t hash;

View File

@@ -36,7 +36,7 @@ public:
it to turn the pubkey_node into an easily remembered and identified it to turn the pubkey_node into an easily remembered and identified
4 character string. 4 character string.
*/ */
static beast::String getWordFromBlob (void const* data, size_t bytes); static std::string getWordFromBlob (void const* data, size_t bytes);
private: private:
static unsigned long extract (char const* s, int start, int length); static unsigned long extract (char const* s, int start, int length);

View File

@@ -118,10 +118,10 @@ public:
bool const result = amount.setValue (value); bool const result = amount.setValue (value);
expect (result == success, std::string ("parse ") + value); expect (result == success, "parse " + value);
if (success) if (success)
expect (amount.getText () == value, std::string ("format ") + value); expect (amount.getText () == value, "format " + value);
} }
void testSetValue () 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 () void testUnderflow ()
{ {
testcase ("underflow"); testcase ("underflow");
STAmount bigNative (STAmount::cMaxNative / 2); STAmount bigNative (STAmount::cMaxNative / 2);
STAmount bigValue (noIssue(), STAmount bigValue (noIssue(),
(STAmount::cMinValue + STAmount::cMaxValue) / 2, STAmount::cMaxOffset - 1); (STAmount::cMinValue + STAmount::cMaxValue) / 2,
STAmount::cMaxOffset - 1);
STAmount smallValue (noIssue(), STAmount smallValue (noIssue(),
(STAmount::cMinValue + STAmount::cMaxValue) / 2, STAmount::cMinOffset + 1); (STAmount::cMinValue + STAmount::cMaxValue) / 2,
STAmount::cMinOffset + 1);
STAmount zeroSt (noIssue(), 0); STAmount zeroSt (noIssue(), 0);
STAmount smallXsmall = multiply (smallValue, smallValue, noIssue()); STAmount smallXsmall = multiply (smallValue, smallValue, noIssue());
@@ -480,7 +468,7 @@ public:
STAmount bigDsmall = divide (smallValue, bigValue, noIssue()); 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 #if 0
// TODO(tom): this test makes no sense - we should have no way to have // 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 ()); bigDsmall = divide (smallValue, bigNative, noCurrency(), xrpAccount ());
#endif #endif
expect (bigDsmall == zero, beast::String ("small/bigNative != 0: ") + bigDsmall.getText ()); expect (bigDsmall == zero,
"small/bigNative != 0: " + bigDsmall.getText ());
bigDsmall = divide (smallValue, bigValue, xrpIssue ()); 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 ()); 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 // very bad offer
std::uint64_t r = getRate (smallValue, bigValue); std::uint64_t r = getRate (smallValue, bigValue);

View File

@@ -37,7 +37,9 @@ public:
getConfig ().RPC_SSL_CERT, getConfig ().RPC_SSL_CERT,
getConfig ().RPC_SSL_CHAIN)) 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 (); startListening ();
} }
@@ -47,7 +49,7 @@ public:
~RPCDoorImp () ~RPCDoorImp ()
{ {
WriteLog (lsINFO, RPCDoor) << WriteLog (lsINFO, RPCDoor) <<
"RPC port: " << getConfig ().getRpcAddress().toRawUTF8() << "RPC port: " << getConfig ().getRpcAddress() <<
" allow remote: " << getConfig ().RPC_ALLOW_REMOTE; " allow remote: " << getConfig ().RPC_ALLOW_REMOTE;
} }

View File

@@ -51,7 +51,7 @@ public:
This is used for diagnostics and may not reflect the actual path This is used for diagnostics and may not reflect the actual path
or paths used by the underlying backend. or paths used by the underlying backend.
*/ */
virtual beast::String getName () const = 0; virtual std::string getName () const = 0;
/** Fetch an object. /** Fetch an object.
If the object is known to be not in the database, isn't found in the If the object is known to be not in the database, isn't found in the

View File

@@ -32,7 +32,7 @@ public:
virtual ~Factory () = 0; virtual ~Factory () = 0;
/** Retrieve the name of this factory. */ /** 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. /** Create an instance of this factory's backend.
@param keyBytes The fixed number of bytes per key. @param keyBytes The fixed number of bytes per key.

View File

@@ -233,7 +233,7 @@ public:
class HyperDBFactory : public NodeStore::Factory class HyperDBFactory : public NodeStore::Factory
{ {
public: public:
beast::String std::string
getName () const getName () const
{ {
return "HyperLevelDB"; return "HyperLevelDB";

View File

@@ -254,7 +254,7 @@ public:
{ {
} }
beast::String std::string
getName () const getName () const
{ {
return "LevelDB"; return "LevelDB";

View File

@@ -105,7 +105,7 @@ public:
class MemoryFactory : public Factory class MemoryFactory : public Factory
{ {
public: public:
beast::String std::string
getName () const getName () const
{ {
return "Memory"; return "Memory";

View File

@@ -72,7 +72,8 @@ private:
class NullFactory : public Factory class NullFactory : public Factory
{ {
public: public:
beast::String getName () const std::string
getName () const
{ {
return "none"; return "none";
} }

View File

@@ -356,7 +356,7 @@ public:
{ {
} }
beast::String std::string
getName () const getName () const
{ {
return "RocksDB"; return "RocksDB";

View File

@@ -92,7 +92,8 @@ public:
e.join(); e.join();
} }
beast::String getName () const std::string
getName () const
{ {
return m_backend->getName (); return m_backend->getName ();
} }

View File

@@ -19,6 +19,8 @@
#include <ripple/nodestore/Manager.h> #include <ripple/nodestore/Manager.h>
#include <beast/utility/ci_char_traits.h>
namespace ripple { namespace ripple {
namespace NodeStore { namespace NodeStore {
@@ -67,10 +69,14 @@ public:
Factory* Factory*
find (std::string const& name) const find (std::string const& name) const
{ {
beast::ci_equal_to casecmp;
for (List::const_iterator iter (m_list.begin ()); for (List::const_iterator iter (m_list.begin ());
iter != m_list.end (); ++iter) iter != m_list.end (); ++iter)
if ((*iter)->getName().compareIgnoreCase (name) == 0) {
if (casecmp ((*iter)->getName(), name))
return iter->get(); return iter->get();
}
return nullptr; return nullptr;
} }

View File

@@ -27,14 +27,14 @@ namespace NodeStore {
class Backend_test : public TestBase class Backend_test : public TestBase
{ {
public: 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) int numObjectsToTest = 2000)
{ {
std::unique_ptr <Manager> manager (make_Manager ()); std::unique_ptr <Manager> manager (make_Manager ());
DummyScheduler scheduler; DummyScheduler scheduler;
testcase ((beast::String ("Backend type=") + type).toStdString()); testcase ("Backend type=" + type);
beast::StringPairArray params; beast::StringPairArray params;
beast::File const path (beast::File::createTempFile ("node_db")); beast::File const path (beast::File::createTempFile ("node_db"));

View File

@@ -23,7 +23,8 @@ namespace NodeStore {
class NodeStoreDatabase_test : public TestBase class NodeStoreDatabase_test : public TestBase
{ {
public: 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 ()); std::unique_ptr <Manager> manager (make_Manager ());
@@ -63,7 +64,8 @@ public:
std::unique_ptr <Database> dest (manager->make_Database ( std::unique_ptr <Database> dest (manager->make_Database (
"test", scheduler, j, 2, destParams)); "test", scheduler, j, 2, destParams));
testcase ((beast::String ("import into '") + destBackendType + "' from '" + srcBackendType + "'").toStdString()); testcase ("import into '" + destBackendType +
"' from '" + srcBackendType + "'");
// Do the import // Do the import
dest->import (*src); dest->import (*src);
@@ -80,7 +82,7 @@ public:
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
void testNodeStore (beast::String type, void testNodeStore (std::string const& type,
bool const useEphemeralDatabase, bool const useEphemeralDatabase,
bool const testPersistence, bool const testPersistence,
std::int64_t const seedValue, std::int64_t const seedValue,
@@ -90,12 +92,11 @@ public:
DummyScheduler scheduler; DummyScheduler scheduler;
beast::String s; std::string s = "NodeStore backend '" + type + "'";
s << beast::String ("NodeStore backend '") + type + "'";
if (useEphemeralDatabase) 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::File const node_db (beast::File::createTempFile ("node_db"));
beast::StringPairArray nodeParams; beast::StringPairArray nodeParams;

View File

@@ -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 ()); std::unique_ptr <Manager> manager (make_Manager ());
DummyScheduler scheduler; DummyScheduler scheduler;
beast::String s; testcase ("Testing backend '" + type + "' performance");
s << "Testing backend '" << type << "' performance";
testcase (s.toStdString());
beast::StringPairArray params; beast::StringPairArray params;
beast::File const path (beast::File::createTempFile ("node_db")); beast::File const path (beast::File::createTempFile ("node_db"));
@@ -85,25 +83,19 @@ public:
// Individual write batch test // Individual write batch test
t.start (); t.start ();
storeBatch (*backend, batch1); storeBatch (*backend, batch1);
s = ""; log << " Single write: " << std::to_string (t.getElapsed ()) << " seconds";
s << " Single write: " << beast::String (t.getElapsed (), 2) << " seconds";
log << s.toStdString();
// Bulk write batch test // Bulk write batch test
t.start (); t.start ();
backend->storeBatch (batch2); backend->storeBatch (batch2);
s = ""; log << " Batch write: " << std::to_string (t.getElapsed ()) << " seconds";
s << " Batch write: " << beast::String (t.getElapsed (), 2) << " seconds";
log << s.toStdString();
// Read test // Read test
Batch copy; Batch copy;
t.start (); t.start ();
fetchCopyOfBatch (*backend, &copy, batch1); fetchCopyOfBatch (*backend, &copy, batch1);
fetchCopyOfBatch (*backend, &copy, batch2); fetchCopyOfBatch (*backend, &copy, batch2);
s = ""; log << " Batch read: " << std::to_string (t.getElapsed ()) << " seconds";
s << " Batch read: " << beast::String (t.getElapsed (), 2) << " seconds";
log << s.toStdString();
} }
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------

View File

@@ -173,7 +173,7 @@ public:
createGossip (g[i]); createGossip (g[i]);
for (int i = 0; i < 5; ++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(); pass();
} }

View File

@@ -51,15 +51,12 @@ struct Results
return *this; return *this;
} }
beast::String toString () const std::string to_string () const
{ {
using beast::String; return "steps=" + std::to_string (steps) +
String s; ", sent=" + std::to_string (sent) +
s = "steps(" + String::fromNumber (steps) + ")" ", received=" + std::to_string (received) +
+ ", sent(" + String::fromNumber (sent) + ")" ", dropped=" + std::to_string (dropped);
+ ", received(" + String::fromNumber (received) + ")"
+ ", dropped(" + String::fromNumber (dropped) + ")";
return s;
} }
Results& operator+= (Results const& other) Results& operator+= (Results const& other)

View File

@@ -27,32 +27,17 @@ namespace TestOverlay
class SimplePayload class SimplePayload
{ {
public: 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_hops (hops)
, m_what (what) , m_what (what)
, m_data (data) , 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 SimplePayload withHop () const
{ {
return SimplePayload (m_what, m_data, m_hops + 1); return SimplePayload (m_what, m_data, m_hops + 1);
@@ -68,7 +53,7 @@ public:
return m_what; return m_what;
} }
beast::String data () const std::string data () const
{ {
return m_data; return m_data;
} }
@@ -76,7 +61,7 @@ public:
private: private:
int m_hops; int m_hops;
int m_what; int m_what;
beast::String m_data; std::string m_data;
}; };
} }

View File

@@ -118,20 +118,14 @@ public:
Results result; Results result;
for (int i = 0; result.received < 249 && i < 100; ++i) for (int i = 0; result.received < 249 && i < 100; ++i)
{ {
using beast::String; auto s = "step #" + std::to_string (network.steps()) + " ";
String s =
String ("step #") + String::fromNumber (
network.steps()) + " ";
result += network.step (); result += network.step ();
s << result.toString (); log << s << result.to_string ();
log << s.toStdString();
} }
int const seen (network.state().seen()); int const seen (network.state().seen());
beast::String s = "Seen = " + beast::String::fromNumber (seen); log << "Seen = " << std::to_string (seen);
log <<
s.toStdString();
pass (); pass ();
} }

View File

@@ -68,10 +68,8 @@ public:
Can be called from any thread. 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; 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 addFile (beast::File const& file) = 0;
virtual void addStaticSource (Validators::Source* source) = 0; virtual void addStaticSource (Validators::Source* source) = 0;
/** @} */ /** @} */

View File

@@ -39,7 +39,7 @@ public:
RipplePublicKey publicKey; RipplePublicKey publicKey;
/** Optional human readable comment describing the validator. */ /** Optional human readable comment describing the validator. */
beast::String label; std::string label;
}; };
/** Destroy the Source. /** Destroy the Source.
@@ -55,10 +55,10 @@ public:
/** An identifier that uniquely describes the source. /** An identifier that uniquely describes the source.
This is used for identification in the database. 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. */ /** 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. /** Cancel any pending fetch.
The default implementation does nothing. The default implementation does nothing.
@@ -74,8 +74,7 @@ public:
Results (); Results ();
bool success; bool success;
// VFALCO TODO Replace with std::string std::string message;
beast::String message;
// VFALCO TODO Replace with chrono // VFALCO TODO Replace with chrono
beast::Time expirationTime; beast::Time expirationTime;
std::vector <Item> list; std::vector <Item> list;

View File

@@ -216,7 +216,7 @@ public:
// Returns `true` if a Source with the same unique ID already exists // 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()); for (SourceTable::const_iterator iter (m_sources.begin());
iter != m_sources.end(); ++iter) iter != m_sources.end(); ++iter)
@@ -364,7 +364,7 @@ public:
m_journal.debug << m_journal.debug <<
"Rebuilt chosen list with " << "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. */ /** Mark the Chosen List for a rebuild. */

View File

@@ -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; if (strings.empty ())
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
{ {
m_journal.debug << "Static source '" << name << "' is empty."; m_journal.debug << "Static source '" << name << "' is empty.";
return;
} }
addStaticSource (SourceStrings::New (name, strings));
} }
void addFile (beast::File const& file) void addFile (beast::File const& file)

View File

@@ -45,14 +45,14 @@ public:
return ss.str(); 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) void fetch (Results& results, beast::Journal journal)

View File

@@ -25,8 +25,7 @@ class SourceStringsImp
, public beast::LeakChecked <SourceStringsImp> , public beast::LeakChecked <SourceStringsImp>
{ {
public: public:
SourceStringsImp ( SourceStringsImp (std::string const& name, std::vector <std::string> const& strings)
beast::String name, beast::StringArray const& strings)
: m_name (name) : m_name (name)
, m_strings (strings) , m_strings (strings)
{ {
@@ -38,18 +37,18 @@ public:
std::string to_string () const 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...? // 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) void fetch (Results& results, beast::Journal journal)
@@ -57,10 +56,7 @@ public:
results.list.reserve (m_strings.size ()); results.list.reserve (m_strings.size ());
for (int i = 0; i < m_strings.size (); ++i) for (int i = 0; i < m_strings.size (); ++i)
{ Utilities::parseResultLine (results, m_strings [i]);
std::string const s (m_strings [i].toStdString ());
Utilities::parseResultLine (results, s);
}
results.success = results.list.size () > 0; results.success = results.list.size () > 0;
results.expirationTime = beast::Time::getCurrentTime () + results.expirationTime = beast::Time::getCurrentTime () +
@@ -68,14 +64,14 @@ public:
} }
private: private:
beast::String m_name; std::string m_name;
beast::StringArray m_strings; std::vector <std::string> m_strings;
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
SourceStrings* SourceStrings::New ( 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); return new SourceStringsImp (name, strings);
} }

View File

@@ -30,7 +30,7 @@ class SourceStrings : public Source
{ {
public: public:
static SourceStrings* New ( static SourceStrings* New (
beast::String name, beast::StringArray const& strings); std::string const& name, std::vector <std::string> const& strings);
}; };
} }

View File

@@ -46,14 +46,14 @@ public:
return ss.str(); 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 () void cancel ()

View File

@@ -17,6 +17,8 @@
*/ */
//============================================================================== //==============================================================================
#include <boost/regex.hpp>
namespace ripple { namespace ripple {
namespace Validators { namespace Validators {
@@ -65,10 +67,10 @@ void StoreSqdb::insert (SourceDesc& desc)
{ {
beast::Error error; beast::Error error;
beast::String const sourceID (desc.source->uniqueID().toStdString()); auto const sourceID (desc.source->uniqueID());
beast::String const createParam (desc.source->createParam().toStdString()); auto const createParam (desc.source->createParam());
beast::String const lastFetchTime (Utilities::timeToString (desc.lastFetchTime)); auto const lastFetchTime (timeToString (desc.lastFetchTime));
beast::String const expirationTime (Utilities::timeToString (desc.expirationTime)); auto const expirationTime (timeToString (desc.expirationTime));
beast::sqdb::statement st = (m_session.prepare << beast::sqdb::statement st = (m_session.prepare <<
"INSERT INTO Validators_Source ( " "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) void StoreSqdb::update (SourceDesc& desc, bool updateFetchResults)
{ {
beast::Error error; beast::Error error;
beast::String const sourceID (desc.source->uniqueID()); std::string const sourceID (desc.source->uniqueID());
beast::String const lastFetchTime (Utilities::timeToString (desc.lastFetchTime)); std::string const lastFetchTime (timeToString (desc.lastFetchTime));
beast::String const expirationTime (Utilities::timeToString (desc.expirationTime)); std::string const expirationTime (timeToString (desc.expirationTime));
beast::sqdb::transaction tr (m_session); beast::sqdb::transaction tr (m_session);
@@ -136,7 +204,7 @@ void StoreSqdb::update (SourceDesc& desc, bool updateFetchResults)
if (! error) if (! error)
{ {
std::string publicKeyString; std::string publicKeyString;
beast::String label; std::string label;
beast::sqdb::statement st = (m_session.prepare << beast::sqdb::statement st = (m_session.prepare <<
"INSERT INTO Validators_SourceItem ( " "INSERT INTO Validators_SourceItem ( "
@@ -197,9 +265,10 @@ bool StoreSqdb::select (SourceDesc& desc)
beast::Error error; beast::Error error;
beast::String const sourceID (desc.source->uniqueID()); std::string const sourceID (desc.source->uniqueID());
beast::String lastFetchTime; std::string lastFetchTime;
beast::String expirationTime; std::string expirationTime;
beast::sqdb::statement st = (m_session.prepare << beast::sqdb::statement st = (m_session.prepare <<
"SELECT " "SELECT "
" lastFetchTime, " " lastFetchTime, "
@@ -217,8 +286,8 @@ bool StoreSqdb::select (SourceDesc& desc)
"Found record for " << *desc.source; "Found record for " << *desc.source;
found = true; found = true;
desc.lastFetchTime = Utilities::stringToTime (lastFetchTime); desc.lastFetchTime = stringToTime (lastFetchTime);
desc.expirationTime = Utilities::stringToTime (expirationTime); desc.expirationTime = stringToTime (expirationTime);
} }
else if (! error) else if (! error)
{ {
@@ -243,7 +312,7 @@ void StoreSqdb::selectList (SourceDesc& desc)
{ {
beast::Error error; beast::Error error;
beast::String const sourceID (desc.source->uniqueID()); std::string const sourceID (desc.source->uniqueID());
// Get the count // Get the count
std::size_t count; std::size_t count;

View File

@@ -62,6 +62,12 @@ private:
beast::Journal m_journal; beast::Journal m_journal;
beast::sqdb::session m_session; 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);
}; };
} }

View File

@@ -35,7 +35,7 @@ public:
struct TestSource : Source 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_name (name)
, m_start (start) , m_start (start)
, m_end (end) , m_end (end)
@@ -44,38 +44,37 @@ public:
std::string to_string () const std::string to_string () const
{ {
return uniqueID().toStdString(); return uniqueID();
} }
beast::String uniqueID () const std::string uniqueID () const
{ {
using beast::String; return "Test," + m_name + "," +
return String ("Test,") + m_name + "," + std::to_string (m_start) + "," +
String::fromNumber (m_start) + "," + std::to_string (m_end);
String::fromNumber (m_end);
} }
beast::String createParam () std::string createParam ()
{ {
return beast::String::empty; return std::string{};
} }
void fetch (Results& results, beast::Journal) void fetch (Results& results, beast::Journal)
{ {
results.success = true; results.success = true;
results.message = beast::String::empty; results.message = std::string{};
results.list.reserve (numberOfTestValidators); results.list.reserve (numberOfTestValidators);
for (std::uint32_t i = m_start ; i < m_end; ++i) for (std::uint32_t i = m_start ; i < m_end; ++i)
{ {
Item item;; Item item;
item.publicKey = RipplePublicKey::createFromInteger (i); item.publicKey = RipplePublicKey::createFromInteger (i);
item.label = beast::String::fromNumber (i); item.label = std::to_string (i);
results.list.push_back (item); results.list.push_back (item);
} }
} }
beast::String m_name; std::string m_name;
std::size_t m_start; std::size_t m_start;
std::size_t m_end; std::size_t m_end;
}; };
@@ -113,7 +112,7 @@ public:
beast::Random r; beast::Random r;
for (int i = 1; i <= numberofTestSources; ++i) 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 start = r.nextInt (numberOfTestValidators);
std::uint32_t const end = start + r.nextInt (numberOfTestValidators); std::uint32_t const end = start + r.nextInt (numberOfTestValidators);
logic.add (new TestSource (name, start, end)); logic.add (new TestSource (name, start, end));

View File

@@ -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);
}
//------------------------------------------------------------------------------
} }
} }

View File

@@ -121,15 +121,6 @@ public:
std::string const& line, std::string const& line,
beast::Journal journal = beast::Journal()); 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; struct Helpers;
/** Parse a string into a Source::Item. /** Parse a string into a Source::Item.