From f9fc9a3518aa420c8779dd292f40489e1e2c1af9 Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Tue, 14 Oct 2014 00:29:35 -0700 Subject: [PATCH] Reduce RippleD dependencies on Beast: * Use static_assert where appropriate * Use std::min and std::max where appropriate * Simplify RippleD error reporting * Remove use of beast::RandomAccessFile --- src/ripple/app/main/FatalErrorReporter.cpp | 8 ++---- src/ripple/app/main/FatalErrorReporter.h | 5 ++-- src/ripple/nodestore/impl/DecodedBlob.cpp | 4 ++- src/ripple/nodestore/impl/EncodedBlob.cpp | 3 +- src/ripple/validators/impl/SourceFile.cpp | 33 +++++++++------------- 5 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/ripple/app/main/FatalErrorReporter.cpp b/src/ripple/app/main/FatalErrorReporter.cpp index ed09d6ed4..e3ea462fd 100644 --- a/src/ripple/app/main/FatalErrorReporter.cpp +++ b/src/ripple/app/main/FatalErrorReporter.cpp @@ -33,11 +33,6 @@ FatalErrorReporter::~FatalErrorReporter () beast::FatalError::setReporter (m_savedReporter); } -void FatalErrorReporter::reportMessage (beast::String& formattedMessage) -{ - std::cerr << formattedMessage.toRawUTF8 () << std::endl; -} - //------------------------------------------------------------------------------ class FatalErrorReporter_test : public beast::unit_test::suite @@ -50,7 +45,8 @@ public: // We don't really expect the program to run after this // but the unit test is here so you can manually test it. - beast::FatalError ("The unit test intentionally failed", __FILE__, __LINE__); + beast::FatalError ("The unit test intentionally failed", + __FILE__, __LINE__); } }; diff --git a/src/ripple/app/main/FatalErrorReporter.h b/src/ripple/app/main/FatalErrorReporter.h index f10335104..97ac154c7 100644 --- a/src/ripple/app/main/FatalErrorReporter.h +++ b/src/ripple/app/main/FatalErrorReporter.h @@ -35,14 +35,13 @@ namespace ripple { constructors that can report a fatal error. Also, the Log would need to be guaranteed to be set up for this handler to work. */ -class FatalErrorReporter : public beast::FatalError::Reporter +class FatalErrorReporter + : public beast::FatalError::Reporter { public: FatalErrorReporter (); ~FatalErrorReporter (); - void reportMessage (beast::String& formattedMessage); - private: beast::FatalError::Reporter* m_savedReporter; }; diff --git a/src/ripple/nodestore/impl/DecodedBlob.cpp b/src/ripple/nodestore/impl/DecodedBlob.cpp index 200f963fa..55d5bb10d 100644 --- a/src/ripple/nodestore/impl/DecodedBlob.cpp +++ b/src/ripple/nodestore/impl/DecodedBlob.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +#include + namespace ripple { namespace NodeStore { @@ -38,7 +40,7 @@ DecodedBlob::DecodedBlob (void const* key, void const* value, int valueBytes) m_ledgerIndex = LedgerIndex (-1); m_objectType = hotUNKNOWN; m_objectData = nullptr; - m_dataBytes = beast::bmax (0, valueBytes - 9); + m_dataBytes = std::max (0, valueBytes - 9); if (valueBytes > 4) { diff --git a/src/ripple/nodestore/impl/EncodedBlob.cpp b/src/ripple/nodestore/impl/EncodedBlob.cpp index e8b9f01c9..e567baccf 100644 --- a/src/ripple/nodestore/impl/EncodedBlob.cpp +++ b/src/ripple/nodestore/impl/EncodedBlob.cpp @@ -31,7 +31,8 @@ EncodedBlob::prepare (NodeObject::Ptr const& object) m_data.ensureSize (m_size); // These sizes must be the same! - static_bassert (sizeof (std::uint32_t) == sizeof (object->getLedgerIndex ())); + static_assert (sizeof (std::uint32_t) == sizeof (object->getLedgerIndex ()), + "Ledger Indices must be exactly 32-bits long."); { std::uint32_t* buf = static_cast (m_data.getData ()); diff --git a/src/ripple/validators/impl/SourceFile.cpp b/src/ripple/validators/impl/SourceFile.cpp index eecb4dc83..402e6c0b1 100644 --- a/src/ripple/validators/impl/SourceFile.cpp +++ b/src/ripple/validators/impl/SourceFile.cpp @@ -18,7 +18,9 @@ //============================================================================== #include -#include + +#include +#include namespace ripple { namespace Validators { @@ -54,28 +56,21 @@ public: void fetch (Results& results, beast::Journal journal) { - std::int64_t const fileSize (m_file.getSize ()); + // 8MB is a somewhat arbitrary maximum file size, but it should be + // enough to cover all cases in the foreseeable future. - if (fileSize != 0) + std::int64_t const maxFileSize = 8 * 1024 * 1024; + std::int64_t const fileSize = m_file.getSize (); + + if (fileSize != 0 && (fileSize < maxFileSize)) { - if (fileSize < std::numeric_limits::max()) - { - beast::MemoryBlock buffer (fileSize); - beast::RandomAccessFile f; - beast::RandomAccessFile::ByteCount amountRead; + std::ifstream datafile (m_file.getFullPathName().toStdString ()); + std::string line; - f.open (m_file, beast::RandomAccessFile::readOnly); - f.read (buffer.begin(), fileSize, &amountRead); - - if (amountRead == fileSize) - { - Utilities::ParseResultLine lineFunction (results, journal); - Utilities::processLines (buffer.begin(), buffer.end(), lineFunction); - } - } - else + if (datafile.is_open ()) { - // too big! + while (std::getline(datafile, line)) + Utilities::parseResultLine (results, line, journal); } } else