diff --git a/Builds/QtCreator/rippled.pro b/Builds/QtCreator/rippled.pro index f31d9f678..d8a9ac5d5 100644 --- a/Builds/QtCreator/rippled.pro +++ b/Builds/QtCreator/rippled.pro @@ -69,7 +69,9 @@ SOURCES += \ ../../src/ripple/json/ripple_json.cpp \ ../../src/ripple/rpc/ripple_rpc.cpp \ ../../src/ripple/sophia/ripple_sophia.c \ + ../../src/ripple/sslutil/ripple_sslutil.cpp \ ../../src/ripple/testoverlay/ripple_testoverlay.cpp \ + ../../src/ripple/types/ripple_types.cpp \ ../../src/ripple/validators/ripple_validators.cpp # --------- diff --git a/Builds/VisualStudio2012/RippleD.vcxproj b/Builds/VisualStudio2012/RippleD.vcxproj index c80c2f27b..9c0b4bea7 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj +++ b/Builds/VisualStudio2012/RippleD.vcxproj @@ -86,6 +86,25 @@ + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + true true @@ -93,6 +112,49 @@ true + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + true true @@ -466,6 +528,12 @@ true true + + true + true + true + true + true true @@ -768,42 +836,18 @@ true - - true - true - true - true - - - true - true - true - true - true true true true - - true - true - true - true - true true true true - - true - true - true - true - true true @@ -979,24 +1023,12 @@ true - - true - true - true - true - true true true true - - true - true - true - true - true true @@ -1039,12 +1071,6 @@ true true - - true - true - true - true - true true @@ -1561,6 +1587,12 @@ + + + + + + @@ -1572,6 +1604,17 @@ + + + + + + + + + + + @@ -1641,6 +1684,7 @@ + @@ -1679,7 +1723,6 @@ - @@ -1690,18 +1733,12 @@ - - - - - + + - - - @@ -1742,16 +1779,13 @@ - - - diff --git a/Builds/VisualStudio2012/RippleD.vcxproj.filters b/Builds/VisualStudio2012/RippleD.vcxproj.filters index f7ddb8a6d..029b59910 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2012/RippleD.vcxproj.filters @@ -214,6 +214,24 @@ {95c93134-7e8d-47ec-9649-4a8d5d97ce12} + + {a3a2d1ec-d731-42df-9397-40a561c6809a} + + + {1bfc2af7-9750-4f5b-b2a2-15d7997c4d59} + + + {e7342119-7a16-49cd-80b5-fdb21c154f0c} + + + {7d0d63f0-edc6-4f86-a6ba-f33c32615457} + + + {96a1206f-7ad0-4829-a09d-64660c2ede0e} + + + {794194cf-e641-4838-ba78-82482c6e87c0} + @@ -222,24 +240,12 @@ [2] Old Ripple\ripple_basics\containers - - [2] Old Ripple\ripple_basics\types - - - [2] Old Ripple\ripple_basics\utility - [2] Old Ripple\ripple_basics\utility - - [2] Old Ripple\ripple_basics\utility - [2] Old Ripple\ripple_basics\utility - - [2] Old Ripple\ripple_basics\utility - [2] Old Ripple\ripple_basics\utility @@ -270,15 +276,9 @@ [2] Old Ripple\ripple_core\functional - - [2] Old Ripple\ripple_data\crypto - [2] Old Ripple\ripple_data\crypto - - [2] Old Ripple\ripple_data\crypto - [2] Old Ripple\ripple_data\crypto @@ -294,9 +294,6 @@ [2] Old Ripple\ripple_data\protocol - - [2] Old Ripple\ripple_data\protocol - [2] Old Ripple\ripple_data\protocol @@ -1020,6 +1017,45 @@ [1] Ripple\http\impl + + [1] Ripple\types + + + [1] Ripple\types\impl + + + [1] Ripple\sslutil + + + [1] Ripple\sslutil\impl + + + [1] Ripple\types\impl + + + [1] Ripple\types\impl + + + [1] Ripple\types\impl + + + [1] Ripple\types\impl + + + [1] Ripple\types\impl + + + [1] Ripple\types\impl + + + [1] Ripple\sslutil\impl + + + [1] Ripple\sslutil\impl + + + [2] Old Ripple\ripple_app\peers + @@ -1028,51 +1064,24 @@ [2] Old Ripple\ripple_basics\containers - - [2] Old Ripple\ripple_basics\containers - [2] Old Ripple\ripple_basics\containers [2] Old Ripple\ripple_basics\system - - [2] Old Ripple\ripple_basics\system - - - [2] Old Ripple\ripple_basics\system - [2] Old Ripple\ripple_basics\types - - [2] Old Ripple\ripple_basics\types - - - [2] Old Ripple\ripple_basics\types - - - [2] Old Ripple\ripple_basics\utility - [2] Old Ripple\ripple_basics\utility - - [2] Old Ripple\ripple_basics\utility - - - [2] Old Ripple\ripple_basics\utility - [2] Old Ripple\ripple_basics\utility [2] Old Ripple\ripple_basics\utility - - [2] Old Ripple\ripple_basics\utility - [2] Old Ripple\ripple_basics\utility @@ -1106,15 +1115,9 @@ [2] Old Ripple\ripple_core\functional - - [2] Old Ripple\ripple_data\crypto - [2] Old Ripple\ripple_data\crypto - - [2] Old Ripple\ripple_data\crypto - [2] Old Ripple\ripple_data\crypto @@ -1127,9 +1130,6 @@ [2] Old Ripple\ripple_data\protocol - - [2] Old Ripple\ripple_data\protocol - [2] Old Ripple\ripple_data\protocol @@ -2022,6 +2022,66 @@ [1] Ripple\rpc\impl + + [2] Old Ripple\ripple_basics\types + + + [2] Old Ripple\ripple_basics\types + + + [1] Ripple\types + + + [1] Ripple\types\api + + + [1] Ripple\types\api + + + [1] Ripple\sslutil + + + [1] Ripple\sslutil\api + + + [1] Ripple\sslutil\api + + + [1] Ripple\sslutil\api + + + [1] Ripple\types\api + + + [1] Ripple\types\api + + + [1] Ripple\types\api + + + [1] Ripple\types\api + + + [1] Ripple\types\api + + + [1] Ripple\types\api + + + [1] Ripple\types\api + + + [1] Ripple\types\api + + + [1] Ripple\sslutil\api + + + [1] Ripple\sslutil\api + + + [2] Old Ripple\ripple_app\peers + diff --git a/SConstruct b/SConstruct index a586af0d2..7ce6d5807 100644 --- a/SConstruct +++ b/SConstruct @@ -150,7 +150,9 @@ COMPILED_FILES.extend([ 'src/ripple/json/ripple_json.cpp', 'src/ripple/rpc/ripple_rpc.cpp', 'src/ripple/sophia/ripple_sophia.c', + 'src/ripple/sslutil/ripple_sslutil.cpp', 'src/ripple/testoverlay/ripple_testoverlay.cpp', + 'src/ripple/types/ripple_types.cpp', 'src/ripple/validators/ripple_validators.cpp' ]) diff --git a/src/ripple/http/ripple_http.cpp b/src/ripple/http/ripple_http.cpp index 1a8a997ff..eb96695d1 100644 --- a/src/ripple/http/ripple_http.cpp +++ b/src/ripple/http/ripple_http.cpp @@ -10,7 +10,7 @@ #include "../ripple_net/ripple_net.h" -#include "beast/modules/beast_core/system/BeforeBoost.h" // must come first +#include "beast/modules/beast_core/system/BeforeBoost.h" #include #include diff --git a/src/ripple/rpc/ripple_rpc.cpp b/src/ripple/rpc/ripple_rpc.cpp index f0772f66d..b1234ee52 100644 --- a/src/ripple/rpc/ripple_rpc.cpp +++ b/src/ripple/rpc/ripple_rpc.cpp @@ -8,7 +8,7 @@ #include "ripple_rpc.h" -#include "beast/modules/beast_core/system/BeforeBoost.h" // must come first +#include "beast/modules/beast_core/system/BeforeBoost.h" #include # include "impl/ManagerImpl.h" diff --git a/src/ripple/sslutil/api/CAutoBN_CTX.h b/src/ripple/sslutil/api/CAutoBN_CTX.h new file mode 100644 index 000000000..b28f4a3b8 --- /dev/null +++ b/src/ripple/sslutil/api/CAutoBN_CTX.h @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2011 The Bitcoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file license.txt or http://www.opensource.org/licenses/mit-license.php. + +#ifndef RIPPLE_SSLUTIL_CAUTOBN_CTX_H_INCLUDED +#define RIPPLE_SSLUTIL_CAUTOBN_CTX_H_INCLUDED + +#include "bignum_error.h" + +namespace ripple { + +class CAutoBN_CTX : public Uncopyable +{ +protected: + BN_CTX* pctx; + CAutoBN_CTX& operator= (BN_CTX* pnew) + { + pctx = pnew; + return *this; + } + +public: + CAutoBN_CTX () + { + pctx = BN_CTX_new (); + + if (pctx == nullptr) + throw bignum_error ("CAutoBN_CTX : BN_CTX_new() returned nullptr"); + } + + ~CAutoBN_CTX () + { + if (pctx != nullptr) + BN_CTX_free (pctx); + } + + operator BN_CTX* () + { + return pctx; + } + BN_CTX& operator* () + { + return *pctx; + } + BN_CTX** operator& () + { + return &pctx; + } + bool operator! () + { + return (pctx == nullptr); + } +}; + +} + +#endif diff --git a/src/ripple_data/crypto/CBigNum.h b/src/ripple/sslutil/api/CBigNum.h similarity index 64% rename from src/ripple_data/crypto/CBigNum.h rename to src/ripple/sslutil/api/CBigNum.h index 951e4cecf..5a8060af4 100644 --- a/src/ripple_data/crypto/CBigNum.h +++ b/src/ripple/sslutil/api/CBigNum.h @@ -9,67 +9,12 @@ // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. -#ifndef RIPPLE_CBIGNUM_H -#define RIPPLE_CBIGNUM_H +#ifndef RIPPLE_SSLUTIL_CBIGNUM_H_INCLUDED +#define RIPPLE_SSLUTIL_CBIGNUM_H_INCLUDED -//------------------------------------------------------------------------------ +namespace ripple { -class bignum_error : public std::runtime_error -{ -public: - explicit bignum_error (const std::string& str) : std::runtime_error (str) {} -}; - -//------------------------------------------------------------------------------ - -class CAutoBN_CTX -{ -private: - CAutoBN_CTX (const CAutoBN_CTX&); // no implementation - CAutoBN_CTX& operator= (const CAutoBN_CTX&); // no implementation - -protected: - BN_CTX* pctx; - CAutoBN_CTX& operator= (BN_CTX* pnew) - { - pctx = pnew; - return *this; - } - -public: - CAutoBN_CTX () - { - pctx = BN_CTX_new (); - - if (pctx == NULL) - throw bignum_error ("CAutoBN_CTX : BN_CTX_new() returned NULL"); - } - - ~CAutoBN_CTX () - { - if (pctx != NULL) - BN_CTX_free (pctx); - } - - operator BN_CTX* () - { - return pctx; - } - BN_CTX& operator* () - { - return *pctx; - } - BN_CTX** operator& () - { - return &pctx; - } - bool operator! () - { - return (pctx == NULL); - } -}; - -//------------------------------------------------------------------------------ +class uint256; // VFALCO TODO figure out a way to remove the dependency on openssl in the // header. Maybe rewrite this to use cryptopp. @@ -150,22 +95,12 @@ bool operator> (const CBigNum& a, const CBigNum& b); //------------------------------------------------------------------------------ -// VFALCO NOTE this seems as good a place as any for this. - -// Here's the old implementation using macros, in case something broke -//#if (ULONG_MAX > UINT_MAX) -//#define BN_add_word64(bn, word) BN_add_word(bn, word) -//#define BN_sub_word64(bn, word) BN_sub_word(bn, word) -//#define BN_mul_word64(bn, word) BN_mul_word(bn, word) -//#define BN_div_word64(bn, word) BN_div_word(bn, word) -//#endif - // VFALCO I believe only STAmount uses these -extern int BN_add_word64 (BIGNUM* a, uint64 w); -extern int BN_sub_word64 (BIGNUM* a, uint64 w); -extern int BN_mul_word64 (BIGNUM* a, uint64 w); -extern uint64 BN_div_word64 (BIGNUM* a, uint64 w); +int BN_add_word64 (BIGNUM* a, uint64 w); +int BN_sub_word64 (BIGNUM* a, uint64 w); +int BN_mul_word64 (BIGNUM* a, uint64 w); +uint64 BN_div_word64 (BIGNUM* a, uint64 w); + +} #endif - -// vim:ts=4 diff --git a/src/ripple_basics/utility/DiffieHellmanUtil.h b/src/ripple/sslutil/api/DHUtil.h similarity index 53% rename from src/ripple_basics/utility/DiffieHellmanUtil.h rename to src/ripple/sslutil/api/DHUtil.h index 18b0a7fcf..a3d247c9d 100644 --- a/src/ripple_basics/utility/DiffieHellmanUtil.h +++ b/src/ripple/sslutil/api/DHUtil.h @@ -4,12 +4,14 @@ */ //============================================================================== -#ifndef RIPPLE_DIFFIEHELLMANUTIL_H -#define RIPPLE_DIFFIEHELLMANUTIL_H +#ifndef RIPPLE_SSLUTIL_DHUTIL_H_INCLUDED +#define RIPPLE_SSLUTIL_DHUTIL_H_INCLUDED -extern DH* DH_der_load (const std::string& strDer); -extern std::string DH_der_gen (int iKeyLength); +namespace ripple { + +DH* DH_der_load (const std::string& strDer); +std::string DH_der_gen (int iKeyLength); + +} #endif - -// vim:ts=4 diff --git a/src/ripple_basics/utility/HashUtilities.h b/src/ripple/sslutil/api/HashUtilities.h similarity index 56% rename from src/ripple_basics/utility/HashUtilities.h rename to src/ripple/sslutil/api/HashUtilities.h index f2ead4da7..a30c96e44 100644 --- a/src/ripple_basics/utility/HashUtilities.h +++ b/src/ripple/sslutil/api/HashUtilities.h @@ -4,8 +4,10 @@ */ //============================================================================== -#ifndef RIPPLE_HASHUTILITIES_H -#define RIPPLE_HASHUTILITIES_H +#ifndef RIPPLE_SSLUTIL_HASHUTILITIES_H_INCLUDED +#define RIPPLE_SSLUTIL_HASHUTILITIES_H_INCLUDED + +namespace ripple { // VFALCO NOTE these came from BitcoinUtil.h @@ -13,7 +15,7 @@ // then define these in a .cpp so they are no longer inline. // template -inline uint256 SHA256Hash (const T1 pbegin, const T1 pend) +uint256 SHA256Hash (const T1 pbegin, const T1 pend) { static unsigned char pblank[1]; uint256 hash1; @@ -24,7 +26,7 @@ inline uint256 SHA256Hash (const T1 pbegin, const T1 pend) } template -inline uint256 SHA256Hash (const T1 p1begin, const T1 p1end, +uint256 SHA256Hash (const T1 p1begin, const T1 p1end, const T2 p2begin, const T2 p2end) { static unsigned char pblank[1]; @@ -40,9 +42,9 @@ inline uint256 SHA256Hash (const T1 p1begin, const T1 p1end, } template -inline uint256 SHA256Hash (const T1 p1begin, const T1 p1end, - const T2 p2begin, const T2 p2end, - const T3 p3begin, const T3 p3end) +uint256 SHA256Hash (const T1 p1begin, const T1 p1end, + const T2 p2begin, const T2 p2end, + const T3 p3begin, const T3 p3end) { static unsigned char pblank[1]; uint256 hash1; @@ -57,39 +59,8 @@ inline uint256 SHA256Hash (const T1 p1begin, const T1 p1end, return hash2; } -inline uint160 Hash160 (Blob const& vch) -{ - uint256 hash1; - SHA256 (&vch[0], vch.size (), (unsigned char*)&hash1); - uint160 hash2; - RIPEMD160 ((unsigned char*)&hash1, sizeof (hash1), (unsigned char*)&hash2); - return hash2; +uint160 Hash160 (Blob const& vch); + } -/* -#if BEAST_WIN32 -// This is used to attempt to keep keying material out of swap -// Note that VirtualLock does not provide this as a guarantee on Windows, -// but, in practice, memory that has been VirtualLock'd almost never gets written to -// the pagefile except in rare circumstances where memory is extremely low. -#include -#define mlock(p, n) VirtualLock((p), (n)); -#define munlock(p, n) VirtualUnlock((p), (n)); -#else -#include -#include -// This comes from limits.h if it's not defined there set a sane default -#ifndef PAGESIZE -#include -#define PAGESIZE sysconf(_SC_PAGESIZE) -#endif -#define mlock(a,b) \ - mlock(((void *)(((size_t)(a)) & (~((PAGESIZE)-1)))),\ - (((((size_t)(a)) + (b) - 1) | ((PAGESIZE) - 1)) + 1) - (((size_t)(a)) & (~((PAGESIZE) - 1)))) -#define munlock(a,b) \ - munlock(((void *)(((size_t)(a)) & (~((PAGESIZE)-1)))),\ - (((((size_t)(a)) + (b) - 1) | ((PAGESIZE) - 1)) + 1) - (((size_t)(a)) & (~((PAGESIZE) - 1)))) -#endif -*/ - #endif diff --git a/src/ripple/sslutil/api/bignum_error.h b/src/ripple/sslutil/api/bignum_error.h new file mode 100644 index 000000000..443e8905c --- /dev/null +++ b/src/ripple/sslutil/api/bignum_error.h @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2011 The Bitcoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file license.txt or http://www.opensource.org/licenses/mit-license.php. + +#ifndef RIPPLE_SSLUTIL_BIGNUM_ERROR_H_INCLUDED +#define RIPPLE_SSLUTIL_BIGNUM_ERROR_H_INCLUDED + +#include + +namespace ripple { + +class bignum_error : public std::runtime_error +{ +public: + explicit bignum_error (std::string const& str) + : std::runtime_error (str) + { + } +}; + +} + +#endif diff --git a/src/ripple_data/crypto/CBigNum.cpp b/src/ripple/sslutil/impl/CBigNum.cpp similarity index 99% rename from src/ripple_data/crypto/CBigNum.cpp rename to src/ripple/sslutil/impl/CBigNum.cpp index ba9412dd1..e05521ca4 100644 --- a/src/ripple_data/crypto/CBigNum.cpp +++ b/src/ripple/sslutil/impl/CBigNum.cpp @@ -9,6 +9,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. +namespace ripple { + CBigNum::CBigNum () { BN_init (this); @@ -641,3 +643,5 @@ uint64 BN_div_word64 (BIGNUM* a, uint64 w) } #endif + +} diff --git a/src/ripple_basics/utility/DiffieHellmanUtil.cpp b/src/ripple/sslutil/impl/DHUtil.cpp similarity index 85% rename from src/ripple_basics/utility/DiffieHellmanUtil.cpp rename to src/ripple/sslutil/impl/DHUtil.cpp index 269407ccf..0e763ae4a 100644 --- a/src/ripple_basics/utility/DiffieHellmanUtil.cpp +++ b/src/ripple/sslutil/impl/DHUtil.cpp @@ -4,6 +4,8 @@ */ //============================================================================== +namespace ripple { + std::string DH_der_gen (int iKeyLength) { DH* dh = 0; @@ -12,13 +14,13 @@ std::string DH_der_gen (int iKeyLength) do { - dh = DH_generate_parameters (iKeyLength, DH_GENERATOR_5, NULL, NULL); + dh = DH_generate_parameters (iKeyLength, DH_GENERATOR_5, nullptr, nullptr); iCodes = 0; DH_check (dh, &iCodes); } while (iCodes & (DH_CHECK_P_NOT_PRIME | DH_CHECK_P_NOT_SAFE_PRIME | DH_UNABLE_TO_CHECK_GENERATOR | DH_NOT_SUITABLE_GENERATOR)); - strDer.resize (i2d_DHparams (dh, NULL)); + strDer.resize (i2d_DHparams (dh, nullptr)); unsigned char* next = reinterpret_cast (&strDer[0]); @@ -31,7 +33,7 @@ DH* DH_der_load (const std::string& strDer) { const unsigned char* pbuf = reinterpret_cast (&strDer[0]); - return d2i_DHparams (NULL, &pbuf, strDer.size ()); + return d2i_DHparams (nullptr, &pbuf, strDer.size ()); } -// vim:ts=4 +} diff --git a/src/ripple/sslutil/impl/HashUtilities.cpp b/src/ripple/sslutil/impl/HashUtilities.cpp new file mode 100644 index 000000000..4118505a0 --- /dev/null +++ b/src/ripple/sslutil/impl/HashUtilities.cpp @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +namespace ripple { + +uint160 Hash160 (Blob const& vch) +{ + uint256 hash1; + SHA256 (&vch[0], vch.size (), (unsigned char*)&hash1); + uint160 hash2; + RIPEMD160 ((unsigned char*)&hash1, sizeof (hash1), (unsigned char*)&hash2); + return hash2; +} + +/* +#if BEAST_WIN32 +// This is used to attempt to keep keying material out of swap +// Note that VirtualLock does not provide this as a guarantee on Windows, +// but, in practice, memory that has been VirtualLock'd almost never gets written to +// the pagefile except in rare circumstances where memory is extremely low. +#include +#define mlock(p, n) VirtualLock((p), (n)); +#define munlock(p, n) VirtualUnlock((p), (n)); +#else +#include +#include +// This comes from limits.h if it's not defined there set a sane default +#ifndef PAGESIZE +#include +#define PAGESIZE sysconf(_SC_PAGESIZE) +#endif +#define mlock(a,b) \ + mlock(((void *)(((size_t)(a)) & (~((PAGESIZE)-1)))),\ + (((((size_t)(a)) + (b) - 1) | ((PAGESIZE) - 1)) + 1) - (((size_t)(a)) & (~((PAGESIZE) - 1)))) +#define munlock(a,b) \ + munlock(((void *)(((size_t)(a)) & (~((PAGESIZE)-1)))),\ + (((((size_t)(a)) + (b) - 1) | ((PAGESIZE) - 1)) + 1) - (((size_t)(a)) & (~((PAGESIZE) - 1)))) +#endif +*/ + +} diff --git a/src/ripple/sslutil/ripple_sslutil.cpp b/src/ripple/sslutil/ripple_sslutil.cpp new file mode 100644 index 000000000..30567f3ad --- /dev/null +++ b/src/ripple/sslutil/ripple_sslutil.cpp @@ -0,0 +1,13 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +#include "BeastConfig.h" + +#include "ripple_sslutil.h" + +#include "impl/CBigNum.cpp" +#include "impl/DHUtil.cpp" +#include "impl/HashUtilities.cpp" diff --git a/src/ripple/sslutil/ripple_sslutil.h b/src/ripple/sslutil/ripple_sslutil.h new file mode 100644 index 000000000..22534c049 --- /dev/null +++ b/src/ripple/sslutil/ripple_sslutil.h @@ -0,0 +1,29 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +#ifndef RIPPLE_SSLUTIL_H_INCLUDED +#define RIPPLE_SSLUTIL_H_INCLUDED + +#include "beast/modules/beast_core/beast_core.h" + +#include "../types/ripple_types.h" + +#include +#include +#include +#include + +namespace ripple { +using namespace beast; +} + +# include "api/bignum_error.h" +#include "api/CAutoBN_CTX.h" +#include "api/CBigNum.h" +#include "api/DHUtil.h" +#include "api/HashUtilities.h" + +#endif diff --git a/src/ripple/testoverlay/ripple_testoverlay.h b/src/ripple/testoverlay/ripple_testoverlay.h index 168403d63..c4fec0354 100644 --- a/src/ripple/testoverlay/ripple_testoverlay.h +++ b/src/ripple/testoverlay/ripple_testoverlay.h @@ -7,7 +7,7 @@ #ifndef RIPPLE_TESTOVERLAY_H_INCLUDED #define RIPPLE_TESTOVERLAY_H_INCLUDED -#include "beast/modules/beast_core/system/BeforeBoost.h" // must come first +#include "beast/modules/beast_core/system/BeforeBoost.h" #include #include "beast/modules/beast_core/beast_core.h" diff --git a/src/ripple_data/crypto/Base58.h b/src/ripple/types/api/Base58.h similarity index 85% rename from src/ripple_data/crypto/Base58.h rename to src/ripple/types/api/Base58.h index 7937e2178..cb741b8d6 100644 --- a/src/ripple_data/crypto/Base58.h +++ b/src/ripple/types/api/Base58.h @@ -16,11 +16,14 @@ // - E-mail usually won't line-break if there's no punctuation to break at. // - Doubleclicking selects the whole number as one word if it's all alphanumeric. // -#ifndef RIPPLE_BASE58_H -#define RIPPLE_BASE58_H +#ifndef RIPPLE_TYPES_BASE58_H +#define RIPPLE_TYPES_BASE58_H -/** Performs Base 58 encoding and decoding. -*/ +#include "Blob.h" + +namespace ripple { + +/** Performs Base 58 encoding and decoding. */ class Base58 { public: @@ -32,6 +35,12 @@ public: static char const* getRippleAlphabet (); static char const* getTestnetAlphabet (); + static std::string encode ( + const unsigned char* pbegin, + const unsigned char* pend, + char const* alphabet, + bool withCheck); + static std::string encode (const unsigned char* pbegin, const unsigned char* pend); static std::string encode (Blob const& vch); static std::string encodeWithCheck (Blob const& vchIn); @@ -45,5 +54,6 @@ private: static char const* s_currentAlphabet; }; +} + #endif -// vim:ts=4 diff --git a/src/ripple/types/api/Blob.h b/src/ripple/types/api/Blob.h new file mode 100644 index 000000000..c13efb23f --- /dev/null +++ b/src/ripple/types/api/Blob.h @@ -0,0 +1,21 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +#ifndef RIPPLE_TYPES_BLOB_H_INCLUDED +#define RIPPLE_TYPES_BLOB_H_INCLUDED + +#include + +namespace ripple { + +/** Storage for linear binary data. + Blocks of binary data appear often in various idioms and structures. +*/ +typedef std::vector Blob; + +} + +#endif diff --git a/src/ripple_basics/utility/ByteOrder.h b/src/ripple/types/api/ByteOrder.h similarity index 93% rename from src/ripple_basics/utility/ByteOrder.h rename to src/ripple/types/api/ByteOrder.h index 8556d018a..6602fb3fb 100644 --- a/src/ripple_basics/utility/ByteOrder.h +++ b/src/ripple/types/api/ByteOrder.h @@ -4,8 +4,10 @@ */ //============================================================================== -#ifndef RIPPLE_BYTEORDER_H -#define RIPPLE_BYTEORDER_H +#ifndef RIPPLE_TYPES_BYTEORDER_H +#define RIPPLE_TYPES_BYTEORDER_H + +namespace ripple { // Routines for converting endianness @@ -42,4 +44,6 @@ extern uint32_t be32toh (uint32_t value); #endif +} + #endif diff --git a/src/ripple_basics/types/HashMaps.h b/src/ripple/types/api/HashMaps.h similarity index 96% rename from src/ripple_basics/types/HashMaps.h rename to src/ripple/types/api/HashMaps.h index d71d06507..b08acf1d3 100644 --- a/src/ripple_basics/types/HashMaps.h +++ b/src/ripple/types/api/HashMaps.h @@ -4,8 +4,10 @@ */ //============================================================================== -#ifndef RIPPLE_HASHMAPS_H -#define RIPPLE_HASHMAPS_H +#ifndef RIPPLE_TYPES_HASHMAPS_H_INCLUDED +#define RIPPLE_TYPES_HASHMAPS_H_INCLUDED + +namespace ripple { /** Management helper of hash functions used in hash map containers. @@ -116,4 +118,6 @@ private: } }; +} + #endif diff --git a/src/ripple_basics/utility/RandomNumbers.h b/src/ripple/types/api/RandomNumbers.h similarity index 88% rename from src/ripple_basics/utility/RandomNumbers.h rename to src/ripple/types/api/RandomNumbers.h index d53ee3ba9..d96671a91 100644 --- a/src/ripple_basics/utility/RandomNumbers.h +++ b/src/ripple/types/api/RandomNumbers.h @@ -4,8 +4,10 @@ */ //============================================================================== -#ifndef RIPPLE_RANDOMNUMBERS_H -#define RIPPLE_RANDOMNUMBERS_H +#ifndef RIPPLE_TYPES_RANDOMNUMBERS_H +#define RIPPLE_TYPES_RANDOMNUMBERS_H + +namespace ripple { /** Cryptographically secure random number source. */ @@ -24,7 +26,7 @@ public: @return `true` if enough entropy could be retrieved. */ - bool initialize (); + bool initialize (Journal::Stream stream = Journal::Stream()); /** Generate secure random numbers. @@ -62,7 +64,7 @@ private: ~RandomNumbers (); - bool platformAddEntropy (); + bool platformAddEntropy (Journal::Stream stream); void platformAddPerformanceMonitorEntropy (); @@ -70,4 +72,6 @@ private: bool m_initialized; }; +} + #endif diff --git a/src/ripple/types/api/UInt128.h b/src/ripple/types/api/UInt128.h new file mode 100644 index 000000000..bb4cb66b6 --- /dev/null +++ b/src/ripple/types/api/UInt128.h @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2011 The Bitcoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file license.txt or http://www.opensource.org/licenses/mit-license.php. + +#ifndef RIPPLE_TYPES_UINT128_H_INCLUDED +#define RIPPLE_TYPES_UINT128_H_INCLUDED + +#include "base_uint.h" + +namespace ripple { + +class uint128 : public base_uint128 +{ +public: + typedef base_uint128 basetype; + + uint128 () + { + zero (); + } + + uint128 (const basetype& b) + { + *this = b; + } + + uint128& operator= (const basetype& b) + { + for (int i = 0; i < WIDTH; i++) + pn[i] = b.pn[i]; + + return *this; + } + + // VFALCO NOTE This looks dangerous and wouldn't be obvious at call + // sites what is being performed here. + // + explicit uint128 (const base_uint256& b) + { + for (int i = 0; i < WIDTH; i++) + pn[i] = b.pn[i]; + } + + explicit uint128 (Blob const& vch) + { + if (vch.size () == size ()) + memcpy (pn, &vch[0], size ()); + else + zero (); + } + +}; + +} + +#endif diff --git a/src/ripple/types/api/UInt160.h b/src/ripple/types/api/UInt160.h new file mode 100644 index 000000000..c7a843d40 --- /dev/null +++ b/src/ripple/types/api/UInt160.h @@ -0,0 +1,180 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2011 The Bitcoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file license.txt or http://www.opensource.org/licenses/mit-license.php. + +#ifndef RIPPLE_TYPES_UINT160_H_INCLUDED +#define RIPPLE_TYPES_UINT160_H_INCLUDED + +#include "base_uint.h" + +namespace ripple { + +class uint160 : public base_uint160 +{ +public: + typedef base_uint160 basetype; + + uint160 () + { + zero (); + } + + uint160 (const basetype& b) + { + *this = b; + } + + uint160& operator= (const basetype& b) + { + for (int i = 0; i < WIDTH; i++) + pn[i] = b.pn[i]; + + return *this; + } + + uint160 (uint64 b) + { + *this = b; + } + + uint160& operator= (uint64 uHost) + { + zero (); + + // Put in least significant bits. + ((uint64*) end ())[-1] = htobe64 (uHost); + + return *this; + } + + explicit uint160 (const std::string& str) + { + SetHex (str); + } + + explicit uint160 (Blob const& vch) + { + if (vch.size () == sizeof (pn)) + memcpy (pn, &vch[0], sizeof (pn)); + else + zero (); + } + + base_uint256 to256 () const; +}; + +inline bool operator== (const uint160& a, uint64 b) +{ + return (base_uint160)a == b; +} + +inline bool operator!= (const uint160& a, uint64 b) +{ + return (base_uint160)a != b; +} + +inline const uint160 operator^ (const base_uint160& a, const base_uint160& b) +{ + return uint160 (a) ^= b; +} + +inline const uint160 operator& (const base_uint160& a, const base_uint160& b) +{ + return uint160 (a) &= b; +} + +inline const uint160 operator| (const base_uint160& a, const base_uint160& b) +{ + return uint160 (a) |= b; +} + +inline bool operator== (const base_uint160& a, const uint160& b) +{ + return (base_uint160)a == (base_uint160)b; +} + +inline bool operator!= (const base_uint160& a, const uint160& b) +{ + return (base_uint160)a != (base_uint160)b; +} + +inline const uint160 operator^ (const base_uint160& a, const uint160& b) +{ + return (base_uint160)a ^ (base_uint160)b; +} + +inline const uint160 operator& (const base_uint160& a, const uint160& b) +{ + return (base_uint160)a & (base_uint160)b; +} + +inline const uint160 operator| (const base_uint160& a, const uint160& b) +{ + return (base_uint160)a | (base_uint160)b; +} + +inline bool operator== (const uint160& a, const base_uint160& b) +{ + return (base_uint160)a == (base_uint160)b; +} +inline bool operator!= (const uint160& a, const base_uint160& b) +{ + return (base_uint160)a != (base_uint160)b; +} +inline const uint160 operator^ (const uint160& a, const base_uint160& b) +{ + return (base_uint160)a ^ (base_uint160)b; +} + +inline const uint160 operator& (const uint160& a, const base_uint160& b) +{ + return (base_uint160)a & (base_uint160)b; +} + +inline const uint160 operator| (const uint160& a, const base_uint160& b) +{ + return (base_uint160)a | (base_uint160)b; +} + +inline bool operator== (const uint160& a, const uint160& b) +{ + return (base_uint160)a == (base_uint160)b; +} + +inline bool operator!= (const uint160& a, const uint160& b) +{ + return (base_uint160)a != (base_uint160)b; +} + +inline const uint160 operator^ (const uint160& a, const uint160& b) +{ + return (base_uint160)a ^ (base_uint160)b; +} + +inline const uint160 operator& (const uint160& a, const uint160& b) +{ + return (base_uint160)a & (base_uint160)b; +} + +inline const uint160 operator| (const uint160& a, const uint160& b) +{ + return (base_uint160)a | (base_uint160)b; +} + +inline const std::string strHex (const uint160& ui) +{ + return strHex (ui.begin (), ui.size ()); +} + +extern std::size_t hash_value (const uint160&); + +} + +#endif diff --git a/src/ripple/types/api/UInt256.h b/src/ripple/types/api/UInt256.h new file mode 100644 index 000000000..2856920c7 --- /dev/null +++ b/src/ripple/types/api/UInt256.h @@ -0,0 +1,333 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2011 The Bitcoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file license.txt or http://www.opensource.org/licenses/mit-license.php. + +#ifndef RIPPLE_TYPES_UINT256_H_INCLUDED +#define RIPPLE_TYPES_UINT256_H_INCLUDED + +#include "base_uint.h" + +namespace ripple { + +class uint256 : public base_uint256 +{ +public: + typedef base_uint256 basetype; + + uint256 () + { + zero (); + } + + uint256 (const basetype& b) + { + *this = b; + } + + uint256& operator= (const basetype& b) + { + if (pn != b.pn) + memcpy (pn, b.pn, sizeof (pn)); + + return *this; + } + + uint256 (uint64 b) + { + *this = b; + } + +private: + uint256 (void const* data, FromVoid) + : base_uint256 (data, FromVoid ()) + { + } +public: + static uint256 fromVoid (void const* data) + { + return uint256 (data, FromVoid ()); + } + + uint256& operator= (uint64 uHost) + { + zero (); + + // Put in least significant bits. + ((uint64*) end ())[-1] = htobe64 (uHost); + + return *this; + } + + explicit uint256 (const std::string& str) + { + SetHex (str); + } + + explicit uint256 (Blob const& vch) + { + if (vch.size () == sizeof (pn)) + memcpy (pn, &vch[0], sizeof (pn)); + else + { + assert (false); + zero (); + } + } +}; + +inline bool operator== (uint256 const& a, uint64 b) +{ + return (base_uint256)a == b; +} + +inline bool operator!= (uint256 const& a, uint64 b) +{ + return (base_uint256)a != b; +} + +inline const uint256 operator^ (const base_uint256& a, const base_uint256& b) +{ + return uint256 (a) ^= b; +} + +inline const uint256 operator& (const base_uint256& a, const base_uint256& b) +{ + return uint256 (a) &= b; +} + +inline const uint256 operator| (const base_uint256& a, const base_uint256& b) +{ + return uint256 (a) |= b; +} + +inline bool operator== (const base_uint256& a, uint256 const& b) +{ + return (base_uint256)a == (base_uint256)b; +} + +inline bool operator!= (const base_uint256& a, uint256 const& b) +{ + return (base_uint256)a != (base_uint256)b; +} + +inline const uint256 operator^ (const base_uint256& a, uint256 const& b) +{ + return (base_uint256)a ^ (base_uint256)b; +} + +inline const uint256 operator& (const base_uint256& a, uint256 const& b) +{ + return (base_uint256)a & (base_uint256)b; +} + +inline const uint256 operator| (const base_uint256& a, uint256 const& b) +{ + return (base_uint256)a | (base_uint256)b; +} + +inline bool operator== (uint256 const& a, const base_uint256& b) +{ + return (base_uint256)a == (base_uint256)b; +} + +inline bool operator!= (uint256 const& a, const base_uint256& b) +{ + return (base_uint256)a != (base_uint256)b; +} + +inline const uint256 operator^ (uint256 const& a, const base_uint256& b) +{ + return (base_uint256)a ^ (base_uint256)b; +} + +inline const uint256 operator& (uint256 const& a, const base_uint256& b) +{ + return uint256 (a) &= b; +} + +inline const uint256 operator| (uint256 const& a, const base_uint256& b) +{ + return (base_uint256)a | (base_uint256)b; +} + +inline bool operator== (uint256 const& a, uint256 const& b) +{ + return (base_uint256)a == (base_uint256)b; +} + +inline bool operator!= (uint256 const& a, uint256 const& b) +{ + return (base_uint256)a != (base_uint256)b; + +} + +inline const uint256 operator^ (uint256 const& a, uint256 const& b) +{ + return (base_uint256)a ^ (base_uint256)b; +} + +inline const uint256 operator& (uint256 const& a, uint256 const& b) +{ + return (base_uint256)a & (base_uint256)b; +} + +inline const uint256 operator| (uint256 const& a, uint256 const& b) +{ + return (base_uint256)a | (base_uint256)b; +} + +inline int Testuint256AdHoc (std::vector vArg) +{ + uint256 g (uint64 (0)); + + printf ("%s\n", g.ToString ().c_str ()); + --g; + printf ("--g\n"); + printf ("%s\n", g.ToString ().c_str ()); + g--; + printf ("g--\n"); + printf ("%s\n", g.ToString ().c_str ()); + g++; + printf ("g++\n"); + printf ("%s\n", g.ToString ().c_str ()); + ++g; + printf ("++g\n"); + printf ("%s\n", g.ToString ().c_str ()); + g++; + printf ("g++\n"); + printf ("%s\n", g.ToString ().c_str ()); + ++g; + printf ("++g\n"); + printf ("%s\n", g.ToString ().c_str ()); + + + + uint256 a (7); + printf ("a=7\n"); + printf ("%s\n", a.ToString ().c_str ()); + + uint256 b; + printf ("b undefined\n"); + printf ("%s\n", b.ToString ().c_str ()); + int c = 3; + + a = c; + a.pn[3] = 15; + printf ("%s\n", a.ToString ().c_str ()); + uint256 k (c); + + a = 5; + a.pn[3] = 15; + printf ("%s\n", a.ToString ().c_str ()); + b = 1; + // b <<= 52; + + a |= b; + + // a ^= 0x500; + + printf ("a %s\n", a.ToString ().c_str ()); + + a = a | b | (uint256)0x1000; + + + printf ("a %s\n", a.ToString ().c_str ()); + printf ("b %s\n", b.ToString ().c_str ()); + + a = 0xfffffffe; + a.pn[4] = 9; + + printf ("%s\n", a.ToString ().c_str ()); + a++; + printf ("%s\n", a.ToString ().c_str ()); + a++; + printf ("%s\n", a.ToString ().c_str ()); + a++; + printf ("%s\n", a.ToString ().c_str ()); + a++; + printf ("%s\n", a.ToString ().c_str ()); + + a--; + printf ("%s\n", a.ToString ().c_str ()); + a--; + printf ("%s\n", a.ToString ().c_str ()); + a--; + printf ("%s\n", a.ToString ().c_str ()); + uint256 d = a--; + printf ("%s\n", d.ToString ().c_str ()); + printf ("%s\n", a.ToString ().c_str ()); + a--; + printf ("%s\n", a.ToString ().c_str ()); + a--; + printf ("%s\n", a.ToString ().c_str ()); + + d = a; + + printf ("%s\n", d.ToString ().c_str ()); + + for (int i = uint256::WIDTH - 1; i >= 0; i--) printf ("%08x", d.pn[i]); + + printf ("\n"); + + uint256 neg = d; + neg = ~neg; + printf ("%s\n", neg.ToString ().c_str ()); + + + uint256 e = uint256 ("0xABCDEF123abcdef12345678909832180000011111111"); + printf ("\n"); + printf ("%s\n", e.ToString ().c_str ()); + + + printf ("\n"); + uint256 x1 = uint256 ("0xABCDEF123abcdef12345678909832180000011111111"); + uint256 x2; + printf ("%s\n", x1.ToString ().c_str ()); + + for (int i = 0; i < 270; i += 4) + { + // x2 = x1 << i; + printf ("%s\n", x2.ToString ().c_str ()); + } + + printf ("\n"); + printf ("%s\n", x1.ToString ().c_str ()); + + for (int i = 0; i < 270; i += 4) + { + x2 = x1; + // x2 >>= i; + printf ("%s\n", x2.ToString ().c_str ()); + } + +#if 0 + + for (int i = 0; i < 100; i++) + { + uint256 k = (~uint256 (0) >> i); + printf ("%s\n", k.ToString ().c_str ()); + } + + for (int i = 0; i < 100; i++) + { + uint256 k = (~uint256 (0) << i); + printf ("%s\n", k.ToString ().c_str ()); + } + +#endif + + return (0); +} + +extern std::size_t hash_value (uint256 const& ); + +} + +#endif diff --git a/src/ripple/types/api/base_uint.h b/src/ripple/types/api/base_uint.h new file mode 100644 index 000000000..838645167 --- /dev/null +++ b/src/ripple/types/api/base_uint.h @@ -0,0 +1,442 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2011 The Bitcoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file license.txt or http://www.opensource.org/licenses/mit-license.php. + +#ifndef RIPPLE_TYPES_BASE_UINT_H_INCLUDED +#define RIPPLE_TYPES_BASE_UINT_H_INCLUDED + +namespace ripple { + +class uint128; +class uint160; +class uint256; +inline int Testuint256AdHoc (std::vector vArg); + +// This class stores its values internally in big-endian form + +// We have to keep a separate base class without constructors +// so the compiler will let us use it in a union +// +// VFALCO NOTE This class produces undefined behavior when +// BITS is not a multiple of 32!!! +// +template +class base_uint +{ +protected: + enum { WIDTH = BITS / 32 }; + + // This is really big-endian in byte order. + // We sometimes use unsigned int for speed. + unsigned int pn[WIDTH]; + +public: + base_uint () + { + } + +protected: + // This is to disambiguate from other 1 parameter ctors + struct FromVoid { }; + + /** Construct from a raw pointer. + + The buffer pointed to by `data` must be at least 32 bytes. + */ + base_uint (void const* data, FromVoid) + { + // BITS must be a multiple of 32 + static_bassert ((BITS % 32) == 0); + + memcpy (&pn [0], data, BITS / 8); + } +public: + + bool isZero () const + { + for (int i = 0; i < WIDTH; i++) + if (pn[i] != 0) + return false; + + return true; + } + + bool isNonZero () const + { + return !isZero (); + } + + bool operator! () const + { + return isZero (); + } + + const base_uint operator~ () const + { + base_uint ret; + + for (int i = 0; i < WIDTH; i++) + ret.pn[i] = ~pn[i]; + + return ret; + } + + base_uint& operator= (uint64 uHost) + { + zero (); + + // Put in least significant bits. + ((uint64*) end ())[-1] = htobe64 (uHost); + + return *this; + } + + base_uint& operator^= (const base_uint& b) + { + for (int i = 0; i < WIDTH; i++) + pn[i] ^= b.pn[i]; + + return *this; + } + + base_uint& operator&= (const base_uint& b) + { + for (int i = 0; i < WIDTH; i++) + pn[i] &= b.pn[i]; + + return *this; + } + + base_uint& operator|= (const base_uint& b) + { + for (int i = 0; i < WIDTH; i++) + pn[i] |= b.pn[i]; + + return *this; + } + + base_uint& operator++ () + { + // prefix operator + for (int i = WIDTH - 1; i >= 0; --i) + { + pn[i] = htobe32 (be32toh (pn[i]) + 1); + + if (pn[i] != 0) + break; + } + + return *this; + } + + const base_uint operator++ (int) + { + // postfix operator + const base_uint ret = *this; + ++ (*this); + + return ret; + } + + base_uint& operator-- () + { + for (int i = WIDTH - 1; i >= 0; --i) + { + uint32 prev = pn[i]; + pn[i] = htobe32 (be32toh (pn[i]) - 1); + + if (prev != 0) + break; + } + + return *this; + } + + const base_uint operator-- (int) + { + // postfix operator + const base_uint ret = *this; + -- (*this); + + return ret; + } + + base_uint& operator+= (const base_uint& b) + { + uint64 carry = 0; + + for (int i = WIDTH; i--;) + { + uint64 n = carry + be32toh (pn[i]) + be32toh (b.pn[i]); + + pn[i] = htobe32 (n & 0xffffffff); + carry = n >> 32; + } + + return *this; + } + + std::size_t hash_combine (std::size_t& seed) const + { + for (int i = 0; i < WIDTH; ++i) + boost::hash_combine (seed, pn[i]); + + return seed; + } + + friend inline int compare (const base_uint& a, const base_uint& b) + { + const unsigned char* pA = a.begin (); + const unsigned char* pAEnd = a.end (); + const unsigned char* pB = b.begin (); + + while (*pA == *pB) + { + if (++pA == pAEnd) + return 0; + + ++pB; + } + + return (*pA < *pB) ? -1 : 1; + } + + friend inline bool operator< (const base_uint& a, const base_uint& b) + { + return compare (a, b) < 0; + } + + friend inline bool operator<= (const base_uint& a, const base_uint& b) + { + return compare (a, b) <= 0; + } + + friend inline bool operator> (const base_uint& a, const base_uint& b) + { + return compare (a, b) > 0; + } + + friend inline bool operator>= (const base_uint& a, const base_uint& b) + { + return compare (a, b) >= 0; + } + + friend inline bool operator== (const base_uint& a, const base_uint& b) + { + return memcmp (a.pn, b.pn, sizeof (a.pn)) == 0; + } + + friend inline bool operator!= (const base_uint& a, const base_uint& b) + { + return memcmp (a.pn, b.pn, sizeof (a.pn)) != 0; + } + + std::string GetHex () const + { + return strHex (begin (), size ()); + } + + void SetHexExact (const char* psz) + { + // must be precisely the correct number of hex digits + static signed char phexdigit[256] = + { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, + + -1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + }; + + char* pOut = reinterpret_cast (pn); + + for (int i = 0; i < sizeof (pn); ++i) + { + *pOut = phexdigit[*psz++] << 4; + *pOut++ |= phexdigit[*psz++]; + } + + assert (*psz == 0); + assert (pOut == reinterpret_cast (end ())); + } + + // Allow leading whitespace. + // Allow leading "0x". + // To be valid must be '\0' terminated. + bool SetHex (const char* psz, bool bStrict = false) + { + // skip leading spaces + if (!bStrict) + while (isspace (*psz)) + psz++; + + // skip 0x + if (!bStrict && psz[0] == '0' && tolower (psz[1]) == 'x') + psz += 2; + + // hex char to int + static signed char phexdigit[256] = + { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, + + -1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + }; + + const unsigned char* pEnd = reinterpret_cast (psz); + const unsigned char* pBegin = pEnd; + + // Find end. + while (phexdigit[*pEnd] >= 0) + pEnd++; + + // Take only last digits of over long string. + if ((unsigned int) (pEnd - pBegin) > 2 * size ()) + pBegin = pEnd - 2 * size (); + + unsigned char* pOut = end () - ((pEnd - pBegin + 1) / 2); + + zero (); + + if ((pEnd - pBegin) & 1) + *pOut++ = phexdigit[*pBegin++]; + + while (pBegin != pEnd) + { + unsigned char cHigh = phexdigit[*pBegin++] << 4; + unsigned char cLow = pBegin == pEnd + ? 0 + : phexdigit[*pBegin++]; + *pOut++ = cHigh | cLow; + } + + return !*pEnd; + } + + bool SetHex (const std::string& str, bool bStrict = false) + { + return SetHex (str.c_str (), bStrict); + } + + void SetHexExact (const std::string& str) + { + SetHexExact (str.c_str ()); + } + + std::string ToString () const + { + return GetHex (); + } + + unsigned char* begin () + { + return reinterpret_cast (pn); + } + + unsigned char* end () + { + return reinterpret_cast (pn + WIDTH); + } + + unsigned char const* cbegin () const noexcept + { + return reinterpret_cast (pn); + } + + unsigned char const* cend () const noexcept + { + return reinterpret_cast (pn + WIDTH); + } + + const unsigned char* begin () const noexcept + { + return cbegin (); + } + + const unsigned char* end () const noexcept + { + return cend (); + } + + unsigned int size () const + { + return sizeof (pn); + } + + void zero () + { + memset (&pn[0], 0, sizeof (pn)); + } + + unsigned int GetSerializeSize (int nType = 0) const + { + return sizeof (pn); + } + + template + void Serialize (Stream& s, int nType = 0) const + { + s.write ((char*)pn, sizeof (pn)); + } + + template + void Unserialize (Stream& s, int nType = 0) + { + s.read ((char*)pn, sizeof (pn)); + } + + friend class uint128; + friend class uint160; + friend class uint256; + friend inline int Testuint256AdHoc (std::vector vArg); +}; + +typedef base_uint<128> base_uint128; +typedef base_uint<160> base_uint160; +typedef base_uint<256> base_uint256; + +template +std::ostream& operator<< (std::ostream& out, const base_uint& u) +{ + return out << u.GetHex (); +} + +} + +#endif diff --git a/src/ripple/types/api/strHex.h b/src/ripple/types/api/strHex.h new file mode 100644 index 000000000..3bd928a2d --- /dev/null +++ b/src/ripple/types/api/strHex.h @@ -0,0 +1,39 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2011 The Bitcoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file license.txt or http://www.opensource.org/licenses/mit-license.php. + +#ifndef RIPPLE_TYPES_STRHEX_H_INCLUDED +#define RIPPLE_TYPES_STRHEX_H_INCLUDED + +namespace ripple { + +char charHex (int iDigit); + +template +std::string strHex (Iterator first, int iSize) +{ + std::string strDst; + + strDst.resize (iSize * 2); + + for (int i = 0; i < iSize; i++) + { + unsigned char c = *first++; + + strDst[i * 2] = charHex (c >> 4); + strDst[i * 2 + 1] = charHex (c & 15); + } + + return strDst; +} + +} + +#endif diff --git a/src/ripple_data/crypto/Base58.cpp b/src/ripple/types/impl/Base58.cpp similarity index 99% rename from src/ripple_data/crypto/Base58.cpp rename to src/ripple/types/impl/Base58.cpp index e00a39b0a..df00fa35b 100644 --- a/src/ripple_data/crypto/Base58.cpp +++ b/src/ripple/types/impl/Base58.cpp @@ -9,6 +9,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. +namespace ripple { + char const* Base58::s_currentAlphabet = Base58::getRippleAlphabet (); char const* Base58::getCurrentAlphabet () @@ -185,4 +187,5 @@ bool Base58::decodeWithCheck (const std::string& str, Blob& vchRet, const char* return decodeWithCheck (str.c_str (), vchRet, pAlphabet); } -// vim:ts=4 +} + diff --git a/src/ripple_basics/utility/ByteOrder.cpp b/src/ripple/types/impl/ByteOrder.cpp similarity index 97% rename from src/ripple_basics/utility/ByteOrder.cpp rename to src/ripple/types/impl/ByteOrder.cpp index 9882a1048..ba33eed08 100644 --- a/src/ripple_basics/utility/ByteOrder.cpp +++ b/src/ripple/types/impl/ByteOrder.cpp @@ -4,6 +4,8 @@ */ //============================================================================== +namespace ripple { + #if BEAST_WIN32 // from: http://stackoverflow.com/questions/3022552/is-there-any-standard-htonl-like-function-for-64-bits-integers-in-c @@ -42,3 +44,5 @@ uint32_t be32toh (uint32_t value) } #endif + +} diff --git a/src/ripple_basics/utility/RandomNumbers.cpp b/src/ripple/types/impl/RandomNumbers.cpp similarity index 81% rename from src/ripple_basics/utility/RandomNumbers.cpp rename to src/ripple/types/impl/RandomNumbers.cpp index a3bd8108b..e32379888 100644 --- a/src/ripple_basics/utility/RandomNumbers.cpp +++ b/src/ripple/types/impl/RandomNumbers.cpp @@ -4,6 +4,27 @@ */ //============================================================================== +// VFALCO TODO Replace OpenSSL randomness with a dependency-free implementation +// Perhaps Schneier's Fortuna or a variant. Abstract the collection of +// entropy and provide OS-specific implementation. We can re-use the +// BearShare source code for this. +// +// Add Random number generation to beast +// +#include +#if BEAST_WIN32 +# include +# include +#endif +#if BEAST_LINUX +# include +#else +# include +#endif +#include + +namespace ripple { + RandomNumbers::RandomNumbers () : m_initialized (false) { @@ -13,11 +34,11 @@ RandomNumbers::~RandomNumbers () { } -bool RandomNumbers::initialize () +bool RandomNumbers::initialize (Journal::Stream stream) { assert (!m_initialized); - bool success = platformAddEntropy (); + bool success = platformAddEntropy (stream); if (success) m_initialized = true; @@ -37,7 +58,6 @@ void RandomNumbers::fillBytes (void* destinationBuffer, int numberOfBytes) if (! initialize ()) { char const* message = "Unable to add system entropy"; - Log::out() << message; throw std::runtime_error (message); } } @@ -66,7 +86,7 @@ RandomNumbers& RandomNumbers::getInstance () #if BEAST_WIN32 // Get entropy from the Windows crypto provider -bool RandomNumbers::platformAddEntropy () +bool RandomNumbers::platformAddEntropy (Journal::Stream stream) { char name[512], rand[128]; DWORD count = 500; @@ -74,25 +94,19 @@ bool RandomNumbers::platformAddEntropy () if (!CryptGetDefaultProviderA (PROV_RSA_FULL, NULL, CRYPT_MACHINE_DEFAULT, name, &count)) { -#ifdef BEAST_DEBUG - Log::out() << "Unable to get default crypto provider"; -#endif + stream << "Unable to get default crypto provider"; return false; } if (!CryptAcquireContextA (&cryptoHandle, NULL, name, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) { -#ifdef BEAST_DEBUG - Log::out() << "Unable to acquire crypto provider"; -#endif + stream << "Unable to acquire crypto provider"; return false; } if (!CryptGenRandom (cryptoHandle, 128, reinterpret_cast (rand))) { -#ifdef BEAST_DEBUG - Log::out() << "Unable to get entropy from crypto provider"; -#endif + stream << "Unable to get entropy from crypto provider"; CryptReleaseContext (cryptoHandle, 0); return false; } @@ -105,7 +119,7 @@ bool RandomNumbers::platformAddEntropy () #else -bool RandomNumbers::platformAddEntropy () +bool RandomNumbers::platformAddEntropy (Journal::Stream stream) { char rand[128]; std::ifstream reader; @@ -115,7 +129,7 @@ bool RandomNumbers::platformAddEntropy () if (!reader.is_open ()) { #ifdef BEAST_DEBUG - Log::out() << "Unable to open random source"; + stream << "Unable to open random source"; #endif return false; } @@ -127,7 +141,7 @@ bool RandomNumbers::platformAddEntropy () if (bytesRead == 0) { #ifdef BEAST_DEBUG - Log::out() << "Unable to read from random source"; + stream << "Unable to read from random source"; #endif return false; } @@ -215,3 +229,5 @@ void RandomNumbers::platformAddPerformanceMonitorEntropy () #endif } + +} diff --git a/src/ripple/types/impl/UInt128.cpp b/src/ripple/types/impl/UInt128.cpp new file mode 100644 index 000000000..13bb65167 --- /dev/null +++ b/src/ripple/types/impl/UInt128.cpp @@ -0,0 +1,16 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +namespace ripple { + +std::size_t hash_value (const uint160& u) +{ + std::size_t seed = HashMaps::getInstance ().getNonce (); + + return u.hash_combine (seed); +} + +} diff --git a/src/ripple/types/impl/UInt160.cpp b/src/ripple/types/impl/UInt160.cpp new file mode 100644 index 000000000..67bd1d639 --- /dev/null +++ b/src/ripple/types/impl/UInt160.cpp @@ -0,0 +1,16 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +namespace ripple { + +base_uint256 uint160::to256 () const +{ + uint256 m; + memcpy (m.begin (), begin (), size ()); + return m; +} + +} diff --git a/src/ripple_basics/types/UInt256.cpp b/src/ripple/types/impl/UInt256.cpp similarity index 71% rename from src/ripple_basics/types/UInt256.cpp rename to src/ripple/types/impl/UInt256.cpp index 8be487997..2e4e5dcf2 100644 --- a/src/ripple_basics/types/UInt256.cpp +++ b/src/ripple/types/impl/UInt256.cpp @@ -4,6 +4,8 @@ */ //============================================================================== +namespace ripple { + std::size_t hash_value (uint256 const& u) { std::size_t seed = HashMaps::getInstance ().getNonce (); @@ -11,10 +13,4 @@ std::size_t hash_value (uint256 const& u) return u.hash_combine (seed); } -std::size_t hash_value (const uint160& u) -{ - std::size_t seed = HashMaps::getInstance ().getNonce (); - - return u.hash_combine (seed); } - diff --git a/src/ripple/types/impl/strHex.cpp b/src/ripple/types/impl/strHex.cpp new file mode 100644 index 000000000..1189b8e5b --- /dev/null +++ b/src/ripple/types/impl/strHex.cpp @@ -0,0 +1,14 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +namespace ripple { + +char charHex (int iDigit) +{ + return iDigit < 10 ? '0' + iDigit : 'A' - 10 + iDigit; +} + +} diff --git a/src/ripple/types/ripple_types.cpp b/src/ripple/types/ripple_types.cpp new file mode 100644 index 000000000..5ae4bc61a --- /dev/null +++ b/src/ripple/types/ripple_types.cpp @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +#include "BeastConfig.h" + +#include "ripple_types.h" +#include "../ripple/sslutil/ripple_sslutil.h" + +#ifdef BEAST_WIN32 +# include // for ByteOrder.cpp +// defines 'max' and does other stupid things +# ifdef max +# undef max +# endif +#endif + +#include "impl/Base58.cpp" +#include "impl/ByteOrder.cpp" +#include "impl/RandomNumbers.cpp" +#include "impl/strHex.cpp" +#include "impl/UInt128.cpp" +#include "impl/UInt160.cpp" +#include "impl/UInt256.cpp" diff --git a/src/ripple/types/ripple_types.h b/src/ripple/types/ripple_types.h new file mode 100644 index 000000000..3e191b12f --- /dev/null +++ b/src/ripple/types/ripple_types.h @@ -0,0 +1,40 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +#ifndef RIPPLE_TYPES_H_INCLUDED +#define RIPPLE_TYPES_H_INCLUDED + +#include "beast/modules/beast_core/beast_core.h" + +#include "beast/modules/beast_core/system/BeforeBoost.h" +#include + +// For ByteOrder +#if BEAST_WIN32 +// (nothing) +#elif __APPLE__ +# include +#elif defined(__FreeBSD__) || defined(__NetBSD__) +# include +#elif defined(__OpenBSD__) +# include +#endif + +namespace ripple { +using namespace beast; +} + +# include "api/Blob.h" +# include "api/Base58.h" +# include "api/ByteOrder.h" +# include "api/strHex.h" +# include "api/UInt128.h" +# include "api/UInt160.h" +# include "api/UInt256.h" +# include "api/RandomNumbers.h" +#include "api/HashMaps.h" + +#endif diff --git a/src/ripple/validators/impl/Logic.h b/src/ripple/validators/impl/Logic.h index 1ede0046a..ce244dd9a 100644 --- a/src/ripple/validators/impl/Logic.h +++ b/src/ripple/validators/impl/Logic.h @@ -312,17 +312,20 @@ public: Json::Value entries (Json::arrayValue); ChosenList::Ptr list (m_chosenList); - for (ChosenList::MapType::const_iterator iter (list->map().begin()); - iter != list->map().end(); ++iter) + if (list != nullptr) { - Json::Value entry (Json::objectValue); - /* - ChosenList::MapType::key_type const& key (iter->first); - ChosenList::MapType::mapped_type const& value (iter->second); - entry ["key"] = key; - entry ["value"] = value; - */ - entries.append (entry); + for (ChosenList::MapType::const_iterator iter (list->map().begin()); + iter != list->map().end(); ++iter) + { + Json::Value entry (Json::objectValue); + /* + ChosenList::MapType::key_type const& key (iter->first); + ChosenList::MapType::mapped_type const& value (iter->second); + entry ["key"] = key; + entry ["value"] = value; + */ + entries.append (entry); + } } result ["chosen_list"] = entries; @@ -343,6 +346,17 @@ public: SourceDesc const& desc (*iter); entry ["name"] = desc.source->name(); entry ["param"] = desc.source->createParam(); + + Json::Value results (Json::arrayValue); + for (int i = 0; i < desc.result.list.size(); ++i) + { + Json::Value info (Json::objectValue); + info ["key"] = "publicKey"; + info ["label"] = desc.result.list[i].label; + results.append (info); + } + entry ["result"] = results; + entries.append (entry); } result ["sources"] = entries; diff --git a/src/ripple/validators/impl/Manager.cpp b/src/ripple/validators/impl/Manager.cpp index 0c3e240d5..50472f449 100644 --- a/src/ripple/validators/impl/Manager.cpp +++ b/src/ripple/validators/impl/Manager.cpp @@ -135,7 +135,7 @@ public: Json::Value rpcRebuild (Json::Value const& args) { - m_thread.call (&Logic::dirtyChosen, &m_logic); + m_thread.call (&Logic::buildChosen, &m_logic); Json::Value result; result ["chosen_list"] = "rebuilding"; return result; diff --git a/src/ripple/validators/ripple_validators.cpp b/src/ripple/validators/ripple_validators.cpp index 9f8d88140..706c90591 100644 --- a/src/ripple/validators/ripple_validators.cpp +++ b/src/ripple/validators/ripple_validators.cpp @@ -8,7 +8,7 @@ #include "ripple_validators.h" -#include "beast/modules/beast_core/system/BeforeBoost.h" // must come first +#include "beast/modules/beast_core/system/BeforeBoost.h" #include #include diff --git a/src/ripple_app/data/Database.h b/src/ripple_app/data/Database.h index 22a8b8398..c20a8646a 100644 --- a/src/ripple_app/data/Database.h +++ b/src/ripple_app/data/Database.h @@ -4,8 +4,8 @@ */ //============================================================================== -#ifndef RIPPLE_DATABASE_RIPPLEHEADER -#define RIPPLE_DATABASE_RIPPLEHEADER +#ifndef RIPPLE_DATABASE_H_INCLUDED +#define RIPPLE_DATABASE_H_INCLUDED // VFALCO Get rid of these macros // diff --git a/src/ripple_app/data/SqliteDatabase.h b/src/ripple_app/data/SqliteDatabase.h index d28b301b9..3df23f8a7 100644 --- a/src/ripple_app/data/SqliteDatabase.h +++ b/src/ripple_app/data/SqliteDatabase.h @@ -4,8 +4,8 @@ */ //============================================================================== -#ifndef RIPPLE_SQLITEDATABASE_RIPPLEHEADER -#define RIPPLE_SQLITEDATABASE_RIPPLEHEADER +#ifndef RIPPLE_SQLITEDATABASE_H_INCLUDED +#define RIPPLE_SQLITEDATABASE_H_INCLUDED class SqliteDatabase : public Database diff --git a/src/ripple_app/misc/IHashRouter.h b/src/ripple_app/misc/IHashRouter.h index 48f06cc9f..83b484dd7 100644 --- a/src/ripple_app/misc/IHashRouter.h +++ b/src/ripple_app/misc/IHashRouter.h @@ -4,8 +4,8 @@ */ //============================================================================== -#ifndef RIPPLE_HASHROUTER_RIPPLEHEADER -#define RIPPLE_HASHROUTER_RIPPLEHEADER +#ifndef RIPPLE_HASHROUTER_H_INCLUDED +#define RIPPLE_HASHROUTER_H_INCLUDED // VFALCO NOTE Are these the flags?? Why aren't we using a packed struct? // VFALCO TODO convert these macros to int constants diff --git a/src/ripple_data/protocol/PackedMessage.cpp b/src/ripple_app/peers/PackedMessage.cpp similarity index 100% rename from src/ripple_data/protocol/PackedMessage.cpp rename to src/ripple_app/peers/PackedMessage.cpp diff --git a/src/ripple_data/protocol/PackedMessage.h b/src/ripple_app/peers/PackedMessage.h similarity index 85% rename from src/ripple_data/protocol/PackedMessage.h rename to src/ripple_app/peers/PackedMessage.h index 978127646..82228537c 100644 --- a/src/ripple_data/protocol/PackedMessage.h +++ b/src/ripple_app/peers/PackedMessage.h @@ -3,13 +3,21 @@ Copyright (c) 2011-2013, OpenCoin, Inc. */ //============================================================================== -// + +#ifndef RIPPLE_PACKEDMESSAGE_H_INCLUDED +#define RIPPLE_PACKEDMESSAGE_H_INCLUDED + +#include "ripple.pb.h" + +#include "beast/modules/beast_core/system/BeforeBoost.h" +#include +#include + +namespace ripple { + // packaging of messages into length/type-prepended buffers // ready for transmission. - -#ifndef RIPPLE_PACKEDMESSAGE_H -#define RIPPLE_PACKEDMESSAGE_H - +// // PackedMessage implements simple "packing" of protocol buffers Messages into // a string prepended by a header specifying the message length. // MessageType should be a Message class generated by the protobuf compiler. @@ -56,5 +64,8 @@ private: std::vector mBuffer; }; -#endif /* PACKEDMESSAGE_H */ +} + +#endif + diff --git a/src/ripple_app/ripple_app.cpp b/src/ripple_app/ripple_app.cpp index c11c4c123..879c82ac4 100644 --- a/src/ripple_app/ripple_app.cpp +++ b/src/ripple_app/ripple_app.cpp @@ -6,7 +6,7 @@ #include "BeastConfig.h" -#include "beast/modules/beast_core/system/BeforeBoost.h" // must come first +#include "beast/modules/beast_core/system/BeforeBoost.h" #include #include #include diff --git a/src/ripple_app/ripple_app.h b/src/ripple_app/ripple_app.h index 67a2490c4..a5133272f 100644 --- a/src/ripple_app/ripple_app.h +++ b/src/ripple_app/ripple_app.h @@ -17,7 +17,7 @@ // purely abstract and move implementation into .cpp files. // -#include "beast/modules/beast_core/system/BeforeBoost.h" // must come first +#include "beast/modules/beast_core/system/BeforeBoost.h" #include #include #include @@ -42,6 +42,12 @@ #include "beast/modules/beast_sqdb/beast_sqdb.h" #include "beast/modules/beast_sqlite/beast_sqlite.h" +// VFALCO NOTE If we forward declare PackedMessage and write out shared_ptr +// instead of using the in-class typedef, we can remove the entire +// ripple.pb.h from the main headers. +// +#include "peers/PackedMessage.h" + namespace ripple { diff --git a/src/ripple_app/ripple_app_pt1.cpp b/src/ripple_app/ripple_app_pt1.cpp index e3db6bc5b..8eb8dae72 100644 --- a/src/ripple_app/ripple_app_pt1.cpp +++ b/src/ripple_app/ripple_app_pt1.cpp @@ -6,7 +6,7 @@ #include "BeastConfig.h" -#include "beast/modules/beast_core/system/BeforeBoost.h" // must come first +#include "beast/modules/beast_core/system/BeforeBoost.h" #include #include #include diff --git a/src/ripple_app/ripple_app_pt4.cpp b/src/ripple_app/ripple_app_pt4.cpp index a1aede97a..0204c09f6 100644 --- a/src/ripple_app/ripple_app_pt4.cpp +++ b/src/ripple_app/ripple_app_pt4.cpp @@ -10,6 +10,8 @@ #include "../ripple_net/ripple_net.h" +#include // for UniqueNodeList.cpp + namespace ripple { diff --git a/src/ripple_app/ripple_app_pt5.cpp b/src/ripple_app/ripple_app_pt5.cpp index 1d9f5c99a..35de5f52e 100644 --- a/src/ripple_app/ripple_app_pt5.cpp +++ b/src/ripple_app/ripple_app_pt5.cpp @@ -25,5 +25,6 @@ namespace ripple # include "misc/ProofOfWork.h" # include "misc/ProofOfWorkFactory.h" #include "peers/Peer.cpp" +#include "peers/PackedMessage.cpp" } diff --git a/src/ripple_app/websocket/WSDoor.h b/src/ripple_app/websocket/WSDoor.h index 166a52fe2..e0ec6feb8 100644 --- a/src/ripple_app/websocket/WSDoor.h +++ b/src/ripple_app/websocket/WSDoor.h @@ -4,8 +4,8 @@ */ //============================================================================== -#ifndef RIPPLE_WSDOOR_RIPPLEHEADER -#define RIPPLE_WSDOOR_RIPPLEHEADER +#ifndef RIPPLE_WSDOOR_H_INCLUDED +#define RIPPLE_WSDOOR_H_INCLUDED /** Handles accepting incoming WebSocket connections. */ class WSDoor : public Stoppable diff --git a/src/ripple_basics/containers/KeyCache.h b/src/ripple_basics/containers/KeyCache.h index 6d2dbe656..e9bc1f0c7 100644 --- a/src/ripple_basics/containers/KeyCache.h +++ b/src/ripple_basics/containers/KeyCache.h @@ -8,9 +8,7 @@ #define RIPPLE_KEYCACHE_H_INCLUDED // This tag is for helping track the locks -struct KeyCacheBase -{ -}; +struct KeyCacheBase { }; /** Maintains a cache of keys with no associated data. @@ -23,8 +21,6 @@ struct KeyCacheBase @code static int getElapsedSeconds (); @endcode - - @ingroup ripple_basics */ template class KeyCache : public KeyCacheBase diff --git a/src/ripple_basics/containers/SecureAllocator.h b/src/ripple_basics/containers/SecureAllocator.h deleted file mode 100644 index 0c8e0d766..000000000 --- a/src/ripple_basics/containers/SecureAllocator.h +++ /dev/null @@ -1,59 +0,0 @@ -//------------------------------------------------------------------------------ -/* - Copyright (c) 2011-2013, OpenCoin, Inc. -*/ -//============================================================================== - -#ifndef RIPPLE_SECUREALLOCATOR_H_INCLUDED -#define RIPPLE_SECUREALLOCATOR_H_INCLUDED - -// -// Allocator that locks its contents from being paged -// out of memory and clears its contents before deletion. -// -template -struct secure_allocator : public std::allocator -{ - // MSVC8 default copy constructor is broken - typedef std::allocator base; - typedef typename base::size_type size_type; - typedef typename base::difference_type difference_type; - typedef typename base::pointer pointer; - typedef typename base::const_pointer const_pointer; - typedef typename base::reference reference; - typedef typename base::const_reference const_reference; - typedef typename base::value_type value_type; - secure_allocator () throw () {} - secure_allocator (const secure_allocator& a) throw () : base (a) {} - template - secure_allocator (const secure_allocator& a) throw () : base (a) {} - ~secure_allocator () throw () {} - template struct rebind - { - typedef secure_allocator<_Other> other; - }; - - T* allocate (std::size_t n, const void* hint = 0) - { - T* p; - p = std::allocator::allocate (n, hint); - - if (p != NULL) - mlock (p, sizeof (T) * n); - - return p; - } - - void deallocate (T* p, std::size_t n) - { - if (p != NULL) - { - memset (p, 0, sizeof (T) * n); - munlock (p, sizeof (T) * n); - } - - std::allocator::deallocate (p, n); - } -}; - -#endif diff --git a/src/ripple_basics/ripple_basics.cpp b/src/ripple_basics/ripple_basics.cpp index e9f718cce..7a6cb2748 100644 --- a/src/ripple_basics/ripple_basics.cpp +++ b/src/ripple_basics/ripple_basics.cpp @@ -4,16 +4,15 @@ */ //============================================================================== -/** Add this to get the @ref ripple_basics module. - - @file ripple_basics.cpp - @ingroup ripple_basics -*/ - #include "BeastConfig.h" #include "ripple_basics.h" +#include "beast/modules/beast_core/system/BeforeBoost.h" +#include // For StringUtilities.cpp + +#include // for Log files + //------------------------------------------------------------------------------ // For Sustain Linux variants @@ -31,29 +30,6 @@ //------------------------------------------------------------------------------ -// For random numbers -// -// VFALCO TODO Replace OpenSSL randomness with a dependency-free implementation -// Perhaps Schneier's Fortuna or a variant. Abstract the collection of -// entropy and provide OS-specific implementation. We can re-use the -// BearShare source code for this. -// -// Add Random number generation to beast -// -#include // Because of ripple_RandomNumbers.cpp - -#ifdef BEAST_WIN32 -# include // for ripple_RandomNumbers.cpp -# include // for ripple_RandomNumbers.cpp -# include // for ripple_ByteOrder.cpp -// defines 'max' and does other stupid things -# ifdef max -# undef max -# endif -#endif - -//------------------------------------------------------------------------------ - namespace ripple { @@ -66,9 +42,7 @@ namespace ripple #include "log/LogPartition.cpp" #include "log/LogSink.cpp" -#include "utility/ByteOrder.cpp" #include "utility/CountedObject.cpp" -#include "utility/DiffieHellmanUtil.cpp" #include "utility/IniFile.cpp" #include "utility/StringUtilities.cpp" #include "utility/Sustain.cpp" @@ -76,8 +50,4 @@ namespace ripple #include "utility/Time.cpp" #include "utility/UptimeTimer.cpp" -#include "utility/RandomNumbers.cpp" // has Win32/Posix dependencies - -#include "types/UInt256.cpp" - } diff --git a/src/ripple_basics/ripple_basics.h b/src/ripple_basics/ripple_basics.h index d65aa02a7..8ef953552 100644 --- a/src/ripple_basics/ripple_basics.h +++ b/src/ripple_basics/ripple_basics.h @@ -4,33 +4,15 @@ */ //============================================================================== -/** Include this to get the @ref ripple_basics module. - - @file ripple_basics.h - @ingroup ripple_basics -*/ - -/** Basic classes. - - This module provides utility classes and types used in the Ripple system. - - @defgroup ripple_basics -*/ - -#ifndef RIPPLE_BASICS_RIPPLEHEADER -#define RIPPLE_BASICS_RIPPLEHEADER - -#include "system/StandardIncludes.h" - -//------------------------------------------------------------------------------ - -#include "beast/modules/beast_core/system/BeforeBoost.h" // must come first -#include "system/BoostIncludes.h" - -#include "system/OpenSSLIncludes.h" +#ifndef RIPPLE_BASICS_H_INCLUDED +#define RIPPLE_BASICS_H_INCLUDED +#include "beast/modules/beast_core/beast_core.h" #include "beast/modules/beast_crypto/beast_crypto.h" +#include "beast/modules/beast_core/system/BeforeBoost.h" +#include "system/BoostIncludes.h" + #include "../../beast/beast/Utility.h" #ifndef RIPPLE_TRACK_MUTEXES @@ -59,20 +41,7 @@ namespace boost } #endif -//------------------------------------------------------------------------------ - -// ByteOrder -#if BEAST_WIN32 -// (nothing) -#elif __APPLE__ -# include -#elif defined(__FreeBSD__) || defined(__NetBSD__) -# include -#elif defined(__OpenBSD__) -# include -#endif - -#include "beast/modules/beast_core/beast_core.h" +#include "../ripple/types/ripple_types.h" namespace ripple { @@ -80,6 +49,8 @@ namespace ripple using namespace beast; #include "types/BasicTypes.h" +#include "types/RipplePublicKey.h" +#include "types/RipplePublicKeyHash.h" # include "log/LogSeverity.h" # include "log/LogFile.h" @@ -89,25 +60,17 @@ using namespace beast; #include "log/LogJournal.h" #include "log/LoggedTimings.h" -#include "utility/ByteOrder.h" #include "utility/CountedObject.h" -#include "utility/DiffieHellmanUtil.h" #include "utility/IniFile.h" #include "utility/PlatformMacros.h" -#include "utility/RandomNumbers.h" #include "utility/StringUtilities.h" #include "utility/Sustain.h" #include "utility/ThreadName.h" #include "utility/Time.h" #include "utility/UptimeTimer.h" -#include "types/UInt256.h" -#include "utility/HashUtilities.h" // requires UInt256 -#include "types/HashMaps.h" - #include "containers/KeyCache.h" #include "containers/RangeSet.h" -#include "containers/SecureAllocator.h" #include "containers/TaggedCache.h" } diff --git a/src/ripple_basics/system/BoostIncludes.h b/src/ripple_basics/system/BoostIncludes.h index 3b802cbd2..6247e215b 100644 --- a/src/ripple_basics/system/BoostIncludes.h +++ b/src/ripple_basics/system/BoostIncludes.h @@ -4,8 +4,8 @@ */ //============================================================================== -#ifndef RIPPLE_BOOSTINCLUDES_RIPPLEHEADER -#define RIPPLE_BOOSTINCLUDES_RIPPLEHEADER +#ifndef RIPPLE_BOOSTINCLUDES_H_INCLUDED +#define RIPPLE_BOOSTINCLUDES_H_INCLUDED // All Boost includes used throughout Ripple. // @@ -27,17 +27,13 @@ #define BOOST_FILESYSTEM_NO_DEPRECATED #include -#include -#include #include -#include #include #include #include #include #include #include -#include #include #include // VFALCO NOTE this looks like junk #include diff --git a/src/ripple_basics/system/OpenSSLIncludes.h b/src/ripple_basics/system/OpenSSLIncludes.h deleted file mode 100644 index eddb8c8da..000000000 --- a/src/ripple_basics/system/OpenSSLIncludes.h +++ /dev/null @@ -1,23 +0,0 @@ -//------------------------------------------------------------------------------ -/* - Copyright (c) 2011-2013, OpenCoin, Inc. -*/ -//============================================================================== - -#ifndef RIPPLE_OPENSSLINCLUDES_RIPPLEHEADER -#define RIPPLE_OPENSSLINCLUDES_RIPPLEHEADER - -// All OpenSSL includes we need - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif diff --git a/src/ripple_basics/system/StandardIncludes.h b/src/ripple_basics/system/StandardIncludes.h deleted file mode 100644 index e21f229e7..000000000 --- a/src/ripple_basics/system/StandardIncludes.h +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -/* - Copyright (c) 2011-2013, OpenCoin, Inc. -*/ -//============================================================================== - -#ifndef RIPPLE_STANDARDINCLUDES_RIPPLEHEADER -#define RIPPLE_STANDARDINCLUDES_RIPPLEHEADER - -// All required Standard C++ Library includes - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif diff --git a/src/ripple_basics/types/BasicTypes.h b/src/ripple_basics/types/BasicTypes.h index b5d756d52..d70cc79b8 100644 --- a/src/ripple_basics/types/BasicTypes.h +++ b/src/ripple_basics/types/BasicTypes.h @@ -7,12 +7,6 @@ #ifndef RIPPLE_BASICTYPES_H #define RIPPLE_BASICTYPES_H -/** Storage for linear binary data. - - Blocks of binary data appear often in various idioms and structures. -*/ -typedef std::vector Blob; - /** Synchronization primitives. This lets us switch between tracked and untracked mutexes. */ @@ -29,12 +23,6 @@ typedef DeprecatedRecursiveMutex::scoped_lock DeprecatedScopedLock; //------------------------------------------------------------------------------ -/** A container used to hold a public key in binary format. */ -typedef UnsignedInteger <33> RipplePublicKey; - -/** A container holding the hash of a public key in binary format. */ -typedef UnsignedInteger <20> RipplePublicKeyHash; - /** A callback used to check for canceling an operation. */ typedef SharedFunction CancelCallback; diff --git a/src/ripple_basics/types/RipplePublicKey.h b/src/ripple_basics/types/RipplePublicKey.h new file mode 100644 index 000000000..8de6be46d --- /dev/null +++ b/src/ripple_basics/types/RipplePublicKey.h @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +#ifndef RIPPLE_BASICS_RIPPLEPUBLICKEY_H_INCLUDED +#define RIPPLE_BASICS_RIPPLEPUBLICKEY_H_INCLUDED + +/** A container used to hold a public key in binary format. */ +typedef UnsignedInteger <33> RipplePublicKey; +#if 0 +class RipplePublicKey +{ +private: + typedef UnsignedInteger <33> integer_type; + +public: + enum + { + size = integer_type::sizeInBytes + }; + + typedef integer_type::value_type value_type; + typedef integer_type::iterator iterator; + typedef integer_type::const_iterator const_iterator; + + class HashFunction + { + public: + HashFunction (HashValue seedToUse = Random::getSystemRandom().nextInt()) + : m_hash (seedToUse) + { + } + + HashValue operator() (RipplePublicKey const& value) const + { + return m_hash (value); + } + + private: + integer_type::HashFunction m_hash; + }; + + iterator begin() + { + return m_value.begin(); + } + + iterator end() + { + return m_value.end(); + } + + const_iterator begin() const + { + return m_value.begin(); + } + + const_iterator end() const + { + return m_value.end(); + } + + const_iterator cbegin() const + { + return m_value.cbegin(); + } + + const_iterator cend() const + { + return m_value.cend(); + } + +private: + integer_type m_value; +}; +#endif + +#endif diff --git a/src/ripple_basics/types/RipplePublicKeyHash.h b/src/ripple_basics/types/RipplePublicKeyHash.h new file mode 100644 index 000000000..3464567b6 --- /dev/null +++ b/src/ripple_basics/types/RipplePublicKeyHash.h @@ -0,0 +1,13 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +#ifndef RIPPLE_BASICS_RIPPLEPUBLICKEYHASH_H_INCLUDED +#define RIPPLE_BASICS_RIPPLEPUBLICKEYHASH_H_INCLUDED + +/** A container holding the hash of a public key in binary format. */ +typedef UnsignedInteger <20> RipplePublicKeyHash; + +#endif diff --git a/src/ripple_basics/types/UInt256.h b/src/ripple_basics/types/UInt256.h deleted file mode 100644 index f3786ac7e..000000000 --- a/src/ripple_basics/types/UInt256.h +++ /dev/null @@ -1,942 +0,0 @@ -//------------------------------------------------------------------------------ -/* - Copyright (c) 2011-2013, OpenCoin, Inc. -*/ -//============================================================================== - -// Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2011 The Bitcoin developers -// Distributed under the MIT/X11 software license, see the accompanying -// file license.txt or http://www.opensource.org/licenses/mit-license.php. - -#ifndef RIPPLE_UINT256_H -#define RIPPLE_UINT256_H - -// These classes all store their values internally -// in big-endian form - -inline int Testuint256AdHoc (std::vector vArg); - -// We have to keep a separate base class without constructors -// so the compiler will let us use it in a union -// -// VFALCO NOTE This class produces undefined behavior when -// BITS is not a multiple of 32!!! -// -template -class base_uint -{ -protected: - enum { WIDTH = BITS / 32 }; - - // This is really big-endian in byte order. - // We sometimes use unsigned int for speed. - unsigned int pn[WIDTH]; - -public: - base_uint () - { - } - -protected: - // This is to disambiguate from other 1 parameter ctors - struct FromVoid { }; - - /** Construct from a raw pointer. - - The buffer pointed to by `data` must be at least 32 bytes. - */ - base_uint (void const* data, FromVoid) - { - // BITS must be a multiple of 32 - static_bassert ((BITS % 32) == 0); - - memcpy (&pn [0], data, BITS / 8); - } -public: - - bool isZero () const - { - for (int i = 0; i < WIDTH; i++) - if (pn[i] != 0) - return false; - - return true; - } - - bool isNonZero () const - { - return !isZero (); - } - - bool operator! () const - { - return isZero (); - } - - const base_uint operator~ () const - { - base_uint ret; - - for (int i = 0; i < WIDTH; i++) - ret.pn[i] = ~pn[i]; - - return ret; - } - - base_uint& operator= (uint64 uHost) - { - zero (); - - // Put in least significant bits. - ((uint64*) end ())[-1] = htobe64 (uHost); - - return *this; - } - - base_uint& operator^= (const base_uint& b) - { - for (int i = 0; i < WIDTH; i++) - pn[i] ^= b.pn[i]; - - return *this; - } - - base_uint& operator&= (const base_uint& b) - { - for (int i = 0; i < WIDTH; i++) - pn[i] &= b.pn[i]; - - return *this; - } - - base_uint& operator|= (const base_uint& b) - { - for (int i = 0; i < WIDTH; i++) - pn[i] |= b.pn[i]; - - return *this; - } - - base_uint& operator++ () - { - // prefix operator - for (int i = WIDTH - 1; i >= 0; --i) - { - pn[i] = htobe32 (be32toh (pn[i]) + 1); - - if (pn[i] != 0) - break; - } - - return *this; - } - - const base_uint operator++ (int) - { - // postfix operator - const base_uint ret = *this; - ++ (*this); - - return ret; - } - - base_uint& operator-- () - { - for (int i = WIDTH - 1; i >= 0; --i) - { - uint32 prev = pn[i]; - pn[i] = htobe32 (be32toh (pn[i]) - 1); - - if (prev != 0) - break; - } - - return *this; - } - - const base_uint operator-- (int) - { - // postfix operator - const base_uint ret = *this; - -- (*this); - - return ret; - } - - base_uint& operator+= (const base_uint& b) - { - uint64 carry = 0; - - for (int i = WIDTH; i--;) - { - uint64 n = carry + be32toh (pn[i]) + be32toh (b.pn[i]); - - pn[i] = htobe32 (n & 0xffffffff); - carry = n >> 32; - } - - return *this; - } - - std::size_t hash_combine (std::size_t& seed) const - { - for (int i = 0; i < WIDTH; ++i) - boost::hash_combine (seed, pn[i]); - - return seed; - } - - friend inline int compare (const base_uint& a, const base_uint& b) - { - const unsigned char* pA = a.begin (); - const unsigned char* pAEnd = a.end (); - const unsigned char* pB = b.begin (); - - while (*pA == *pB) - { - if (++pA == pAEnd) - return 0; - - ++pB; - } - - return (*pA < *pB) ? -1 : 1; - } - - friend inline bool operator< (const base_uint& a, const base_uint& b) - { - return compare (a, b) < 0; - } - - friend inline bool operator<= (const base_uint& a, const base_uint& b) - { - return compare (a, b) <= 0; - } - - friend inline bool operator> (const base_uint& a, const base_uint& b) - { - return compare (a, b) > 0; - } - - friend inline bool operator>= (const base_uint& a, const base_uint& b) - { - return compare (a, b) >= 0; - } - - friend inline bool operator== (const base_uint& a, const base_uint& b) - { - return memcmp (a.pn, b.pn, sizeof (a.pn)) == 0; - } - - friend inline bool operator!= (const base_uint& a, const base_uint& b) - { - return memcmp (a.pn, b.pn, sizeof (a.pn)) != 0; - } - - std::string GetHex () const - { - return strHex (begin (), size ()); - } - - void SetHexExact (const char* psz) - { - // must be precisely the correct number of hex digits - static signed char phexdigit[256] = - { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, - - -1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - }; - - char* pOut = reinterpret_cast (pn); - - for (int i = 0; i < sizeof (pn); ++i) - { - *pOut = phexdigit[*psz++] << 4; - *pOut++ |= phexdigit[*psz++]; - } - - assert (*psz == 0); - assert (pOut == reinterpret_cast (end ())); - } - - // Allow leading whitespace. - // Allow leading "0x". - // To be valid must be '\0' terminated. - bool SetHex (const char* psz, bool bStrict = false) - { - // skip leading spaces - if (!bStrict) - while (isspace (*psz)) - psz++; - - // skip 0x - if (!bStrict && psz[0] == '0' && tolower (psz[1]) == 'x') - psz += 2; - - // hex char to int - static signed char phexdigit[256] = - { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, - - -1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - }; - - const unsigned char* pEnd = reinterpret_cast (psz); - const unsigned char* pBegin = pEnd; - - // Find end. - while (phexdigit[*pEnd] >= 0) - pEnd++; - - // Take only last digits of over long string. - if ((unsigned int) (pEnd - pBegin) > 2 * size ()) - pBegin = pEnd - 2 * size (); - - unsigned char* pOut = end () - ((pEnd - pBegin + 1) / 2); - - zero (); - - if ((pEnd - pBegin) & 1) - *pOut++ = phexdigit[*pBegin++]; - - while (pBegin != pEnd) - { - unsigned char cHigh = phexdigit[*pBegin++] << 4; - unsigned char cLow = pBegin == pEnd - ? 0 - : phexdigit[*pBegin++]; - *pOut++ = cHigh | cLow; - } - - return !*pEnd; - } - - bool SetHex (const std::string& str, bool bStrict = false) - { - return SetHex (str.c_str (), bStrict); - } - - void SetHexExact (const std::string& str) - { - SetHexExact (str.c_str ()); - } - - std::string ToString () const - { - return GetHex (); - } - - unsigned char* begin () - { - return reinterpret_cast (pn); - } - - unsigned char* end () - { - return reinterpret_cast (pn + WIDTH); - } - - unsigned char const* cbegin () const noexcept - { - return reinterpret_cast (pn); - } - - unsigned char const* cend () const noexcept - { - return reinterpret_cast (pn + WIDTH); - } - - const unsigned char* begin () const noexcept - { - return cbegin (); - } - - const unsigned char* end () const noexcept - { - return cend (); - } - - unsigned int size () const - { - return sizeof (pn); - } - - void zero () - { - memset (&pn[0], 0, sizeof (pn)); - } - - unsigned int GetSerializeSize (int nType = 0) const - { - return sizeof (pn); - } - - template - void Serialize (Stream& s, int nType = 0) const - { - s.write ((char*)pn, sizeof (pn)); - } - - template - void Unserialize (Stream& s, int nType = 0) - { - s.read ((char*)pn, sizeof (pn)); - } - - friend class uint128; - friend class uint160; - friend class uint256; - friend inline int Testuint256AdHoc (std::vector vArg); -}; - -typedef base_uint<128> base_uint128; -typedef base_uint<160> base_uint160; -typedef base_uint<256> base_uint256; - -// -// uint128, uint160, & uint256 could be implemented as templates, but to keep -// compile errors and debugging cleaner, they're copy and pasted. -// - -////////////////////////////////////////////////////////////////////////////// -// -// uint128 -// - -class uint128 : public base_uint128 -{ -public: - typedef base_uint128 basetype; - - uint128 () - { - zero (); - } - - uint128 (const basetype& b) - { - *this = b; - } - - uint128& operator= (const basetype& b) - { - for (int i = 0; i < WIDTH; i++) - pn[i] = b.pn[i]; - - return *this; - } - - explicit uint128 (const base_uint256& b) - { - for (int i = 0; i < WIDTH; i++) - pn[i] = b.pn[i]; - } - - explicit uint128 (Blob const& vch) - { - if (vch.size () == size ()) - memcpy (pn, &vch[0], size ()); - else - zero (); - } - -}; - -////////////////////////////////////////////////////////////////////////////// -// -// uint256 -// - -class uint256 : public base_uint256 -{ -public: - typedef base_uint256 basetype; - - uint256 () - { - zero (); - } - - uint256 (const basetype& b) - { - *this = b; - } - - uint256& operator= (const basetype& b) - { - if (pn != b.pn) - memcpy (pn, b.pn, sizeof (pn)); - - return *this; - } - - uint256 (uint64 b) - { - *this = b; - } - -private: - uint256 (void const* data, FromVoid) - : base_uint256 (data, FromVoid ()) - { - } -public: - static uint256 fromVoid (void const* data) - { - return uint256 (data, FromVoid ()); - } - - uint256& operator= (uint64 uHost) - { - zero (); - - // Put in least significant bits. - ((uint64*) end ())[-1] = htobe64 (uHost); - - return *this; - } - - explicit uint256 (const std::string& str) - { - SetHex (str); - } - - explicit uint256 (Blob const& vch) - { - if (vch.size () == sizeof (pn)) - memcpy (pn, &vch[0], sizeof (pn)); - else - { - assert (false); - zero (); - } - } -}; - - -inline bool operator== (uint256 const& a, uint64 b) -{ - return (base_uint256)a == b; -} -inline bool operator!= (uint256 const& a, uint64 b) -{ - return (base_uint256)a != b; -} -inline const uint256 operator^ (const base_uint256& a, const base_uint256& b) -{ - return uint256 (a) ^= b; -} -inline const uint256 operator& (const base_uint256& a, const base_uint256& b) -{ - return uint256 (a) &= b; -} -inline const uint256 operator| (const base_uint256& a, const base_uint256& b) -{ - return uint256 (a) |= b; -} -inline bool operator== (const base_uint256& a, uint256 const& b) -{ - return (base_uint256)a == (base_uint256)b; -} -inline bool operator!= (const base_uint256& a, uint256 const& b) -{ - return (base_uint256)a != (base_uint256)b; -} -inline const uint256 operator^ (const base_uint256& a, uint256 const& b) -{ - return (base_uint256)a ^ (base_uint256)b; -} -inline const uint256 operator& (const base_uint256& a, uint256 const& b) -{ - return (base_uint256)a & (base_uint256)b; -} -inline const uint256 operator| (const base_uint256& a, uint256 const& b) -{ - return (base_uint256)a | (base_uint256)b; -} -inline bool operator== (uint256 const& a, const base_uint256& b) -{ - return (base_uint256)a == (base_uint256)b; -} -inline bool operator!= (uint256 const& a, const base_uint256& b) -{ - return (base_uint256)a != (base_uint256)b; -} -inline const uint256 operator^ (uint256 const& a, const base_uint256& b) -{ - return (base_uint256)a ^ (base_uint256)b; -} -inline const uint256 operator& (uint256 const& a, const base_uint256& b) -{ - return uint256 (a) &= b; -} -inline const uint256 operator| (uint256 const& a, const base_uint256& b) -{ - return (base_uint256)a | (base_uint256)b; -} -inline bool operator== (uint256 const& a, uint256 const& b) -{ - return (base_uint256)a == (base_uint256)b; -} -inline bool operator!= (uint256 const& a, uint256 const& b) -{ - return (base_uint256)a != (base_uint256)b; -} -inline const uint256 operator^ (uint256 const& a, uint256 const& b) -{ - return (base_uint256)a ^ (base_uint256)b; -} -inline const uint256 operator& (uint256 const& a, uint256 const& b) -{ - return (base_uint256)a & (base_uint256)b; -} -inline const uint256 operator| (uint256 const& a, uint256 const& b) -{ - return (base_uint256)a | (base_uint256)b; -} - -template inline std::ostream& operator<< (std::ostream& out, const base_uint& u) -{ - return out << u.GetHex (); -} - -inline int Testuint256AdHoc (std::vector vArg) -{ - uint256 g (uint64 (0)); - - printf ("%s\n", g.ToString ().c_str ()); - --g; - printf ("--g\n"); - printf ("%s\n", g.ToString ().c_str ()); - g--; - printf ("g--\n"); - printf ("%s\n", g.ToString ().c_str ()); - g++; - printf ("g++\n"); - printf ("%s\n", g.ToString ().c_str ()); - ++g; - printf ("++g\n"); - printf ("%s\n", g.ToString ().c_str ()); - g++; - printf ("g++\n"); - printf ("%s\n", g.ToString ().c_str ()); - ++g; - printf ("++g\n"); - printf ("%s\n", g.ToString ().c_str ()); - - - - uint256 a (7); - printf ("a=7\n"); - printf ("%s\n", a.ToString ().c_str ()); - - uint256 b; - printf ("b undefined\n"); - printf ("%s\n", b.ToString ().c_str ()); - int c = 3; - - a = c; - a.pn[3] = 15; - printf ("%s\n", a.ToString ().c_str ()); - uint256 k (c); - - a = 5; - a.pn[3] = 15; - printf ("%s\n", a.ToString ().c_str ()); - b = 1; - // b <<= 52; - - a |= b; - - // a ^= 0x500; - - printf ("a %s\n", a.ToString ().c_str ()); - - a = a | b | (uint256)0x1000; - - - printf ("a %s\n", a.ToString ().c_str ()); - printf ("b %s\n", b.ToString ().c_str ()); - - a = 0xfffffffe; - a.pn[4] = 9; - - printf ("%s\n", a.ToString ().c_str ()); - a++; - printf ("%s\n", a.ToString ().c_str ()); - a++; - printf ("%s\n", a.ToString ().c_str ()); - a++; - printf ("%s\n", a.ToString ().c_str ()); - a++; - printf ("%s\n", a.ToString ().c_str ()); - - a--; - printf ("%s\n", a.ToString ().c_str ()); - a--; - printf ("%s\n", a.ToString ().c_str ()); - a--; - printf ("%s\n", a.ToString ().c_str ()); - uint256 d = a--; - printf ("%s\n", d.ToString ().c_str ()); - printf ("%s\n", a.ToString ().c_str ()); - a--; - printf ("%s\n", a.ToString ().c_str ()); - a--; - printf ("%s\n", a.ToString ().c_str ()); - - d = a; - - printf ("%s\n", d.ToString ().c_str ()); - - for (int i = uint256::WIDTH - 1; i >= 0; i--) printf ("%08x", d.pn[i]); - - printf ("\n"); - - uint256 neg = d; - neg = ~neg; - printf ("%s\n", neg.ToString ().c_str ()); - - - uint256 e = uint256 ("0xABCDEF123abcdef12345678909832180000011111111"); - printf ("\n"); - printf ("%s\n", e.ToString ().c_str ()); - - - printf ("\n"); - uint256 x1 = uint256 ("0xABCDEF123abcdef12345678909832180000011111111"); - uint256 x2; - printf ("%s\n", x1.ToString ().c_str ()); - - for (int i = 0; i < 270; i += 4) - { - // x2 = x1 << i; - printf ("%s\n", x2.ToString ().c_str ()); - } - - printf ("\n"); - printf ("%s\n", x1.ToString ().c_str ()); - - for (int i = 0; i < 270; i += 4) - { - x2 = x1; - // x2 >>= i; - printf ("%s\n", x2.ToString ().c_str ()); - } - -#if 0 - - for (int i = 0; i < 100; i++) - { - uint256 k = (~uint256 (0) >> i); - printf ("%s\n", k.ToString ().c_str ()); - } - - for (int i = 0; i < 100; i++) - { - uint256 k = (~uint256 (0) << i); - printf ("%s\n", k.ToString ().c_str ()); - } - -#endif - - return (0); -} - -////////////////////////////////////////////////////////////////////////////// -// -// uint160 -// - -class uint160 : public base_uint160 -{ -public: - typedef base_uint160 basetype; - - uint160 () - { - zero (); - } - - uint160 (const basetype& b) - { - *this = b; - } - - uint160& operator= (const basetype& b) - { - for (int i = 0; i < WIDTH; i++) - pn[i] = b.pn[i]; - - return *this; - } - - uint160 (uint64 b) - { - *this = b; - } - - uint160& operator= (uint64 uHost) - { - zero (); - - // Put in least significant bits. - ((uint64*) end ())[-1] = htobe64 (uHost); - - return *this; - } - - explicit uint160 (const std::string& str) - { - SetHex (str); - } - - explicit uint160 (Blob const& vch) - { - if (vch.size () == sizeof (pn)) - memcpy (pn, &vch[0], sizeof (pn)); - else - zero (); - } - - base_uint256 to256 () const - { - uint256 m; - memcpy (m.begin (), begin (), size ()); - return m; - } - -}; - -inline bool operator== (const uint160& a, uint64 b) -{ - return (base_uint160)a == b; -} -inline bool operator!= (const uint160& a, uint64 b) -{ - return (base_uint160)a != b; -} - -inline const uint160 operator^ (const base_uint160& a, const base_uint160& b) -{ - return uint160 (a) ^= b; -} -inline const uint160 operator& (const base_uint160& a, const base_uint160& b) -{ - return uint160 (a) &= b; -} -inline const uint160 operator| (const base_uint160& a, const base_uint160& b) -{ - return uint160 (a) |= b; -} - -inline bool operator== (const base_uint160& a, const uint160& b) -{ - return (base_uint160)a == (base_uint160)b; -} -inline bool operator!= (const base_uint160& a, const uint160& b) -{ - return (base_uint160)a != (base_uint160)b; -} -inline const uint160 operator^ (const base_uint160& a, const uint160& b) -{ - return (base_uint160)a ^ (base_uint160)b; -} -inline const uint160 operator& (const base_uint160& a, const uint160& b) -{ - return (base_uint160)a & (base_uint160)b; -} -inline const uint160 operator| (const base_uint160& a, const uint160& b) -{ - return (base_uint160)a | (base_uint160)b; -} - -inline bool operator== (const uint160& a, const base_uint160& b) -{ - return (base_uint160)a == (base_uint160)b; -} -inline bool operator!= (const uint160& a, const base_uint160& b) -{ - return (base_uint160)a != (base_uint160)b; -} -inline const uint160 operator^ (const uint160& a, const base_uint160& b) -{ - return (base_uint160)a ^ (base_uint160)b; -} -inline const uint160 operator& (const uint160& a, const base_uint160& b) -{ - return (base_uint160)a & (base_uint160)b; -} -inline const uint160 operator| (const uint160& a, const base_uint160& b) -{ - return (base_uint160)a | (base_uint160)b; -} -inline bool operator== (const uint160& a, const uint160& b) -{ - return (base_uint160)a == (base_uint160)b; -} -inline bool operator!= (const uint160& a, const uint160& b) -{ - return (base_uint160)a != (base_uint160)b; -} -inline const uint160 operator^ (const uint160& a, const uint160& b) -{ - return (base_uint160)a ^ (base_uint160)b; -} -inline const uint160 operator& (const uint160& a, const uint160& b) -{ - return (base_uint160)a & (base_uint160)b; -} -inline const uint160 operator| (const uint160& a, const uint160& b) -{ - return (base_uint160)a | (base_uint160)b; -} - -inline const std::string strHex (const uint160& ui) -{ - return strHex (ui.begin (), ui.size ()); -} - -extern std::size_t hash_value (const uint160&); - -extern std::size_t hash_value (uint256 const& ); - -#endif - -// vim:ts=4 - -// vim:ts=4 diff --git a/src/ripple_basics/utility/CountedObject.h b/src/ripple_basics/utility/CountedObject.h index ada9c932c..b86f33f4c 100644 --- a/src/ripple_basics/utility/CountedObject.h +++ b/src/ripple_basics/utility/CountedObject.h @@ -4,8 +4,8 @@ */ //============================================================================== -#ifndef RIPPLE_COUNTEDOBJECT_RIPPLEHEADER -#define RIPPLE_COUNTEDOBJECT_RIPPLEHEADER +#ifndef RIPPLE_COUNTEDOBJECT_H_INCLUDED +#define RIPPLE_COUNTEDOBJECT_H_INCLUDED //------------------------------------------------------------------------------ diff --git a/src/ripple_basics/utility/IniFile.h b/src/ripple_basics/utility/IniFile.h index d8e27abb9..33e46347d 100644 --- a/src/ripple_basics/utility/IniFile.h +++ b/src/ripple_basics/utility/IniFile.h @@ -4,8 +4,8 @@ */ //============================================================================== -#ifndef RIPPLE_INIFILE_RIPPLEHEADER -#define RIPPLE_INIFILE_RIPPLEHEADER +#ifndef RIPPLE_INIFILE_H_INCLUDED +#define RIPPLE_INIFILE_H_INCLUDED // VFALCO TODO Rename to IniFile and clean up typedef std::map > Section; diff --git a/src/ripple_basics/utility/StringUtilities.cpp b/src/ripple_basics/utility/StringUtilities.cpp index 2ff99307e..b698bf396 100644 --- a/src/ripple_basics/utility/StringUtilities.cpp +++ b/src/ripple_basics/utility/StringUtilities.cpp @@ -45,11 +45,6 @@ std::string strprintf (const char* format, ...) return str; } -char charHex (int iDigit) -{ - return iDigit < 10 ? '0' + iDigit : 'A' - 10 + iDigit; -} - int charUnHex (char cDigit) { return cDigit >= '0' && cDigit <= '9' diff --git a/src/ripple_basics/utility/StringUtilities.h b/src/ripple_basics/utility/StringUtilities.h index 014c3d842..0e5258f73 100644 --- a/src/ripple_basics/utility/StringUtilities.h +++ b/src/ripple_basics/utility/StringUtilities.h @@ -81,26 +81,6 @@ std::string strJoin (Iterator first, Iterator last, std::string strSeperator) return ossValues.str (); } -char charHex (int iDigit); - -template -std::string strHex (Iterator first, int iSize) -{ - std::string strDst; - - strDst.resize (iSize * 2); - - for (int i = 0; i < iSize; i++) - { - unsigned char c = *first++; - - strDst[i * 2] = charHex (c >> 4); - strDst[i * 2 + 1] = charHex (c & 15); - } - - return strDst; -} - inline const std::string strHex (const std::string& strSrc) { return strHex (strSrc.begin (), strSrc.size ()); diff --git a/src/ripple_core/functional/ILoadFeeTrack.h b/src/ripple_core/functional/ILoadFeeTrack.h index f7fa1b2ab..26c022a19 100644 --- a/src/ripple_core/functional/ILoadFeeTrack.h +++ b/src/ripple_core/functional/ILoadFeeTrack.h @@ -4,8 +4,8 @@ */ //============================================================================== -#ifndef RIPPLE_ILOADFEETRACK_RIPPLEHEADER -#define RIPPLE_ILOADFEETRACK_RIPPLEHEADER +#ifndef RIPPLE_ILOADFEETRACK_H_INCLUDED +#define RIPPLE_ILOADFEETRACK_H_INCLUDED /** Manages the current fee schedule. diff --git a/src/ripple_core/functional/LoadFeeTrack.h b/src/ripple_core/functional/LoadFeeTrack.h index d5c3cba36..ea749201f 100644 --- a/src/ripple_core/functional/LoadFeeTrack.h +++ b/src/ripple_core/functional/LoadFeeTrack.h @@ -4,8 +4,8 @@ */ //============================================================================== -#ifndef RIPPLE_LOADFEETRACK_RIPPLEHEADER -#define RIPPLE_LOADFEETRACK_RIPPLEHEADER +#ifndef RIPPLE_LOADFEETRACK_H_INCLUDED +#define RIPPLE_LOADFEETRACK_H_INCLUDED // PRIVATE HEADER class LoadManager; diff --git a/src/ripple_core/functional/LoadMonitor.h b/src/ripple_core/functional/LoadMonitor.h index a70ac9713..f07b0d703 100644 --- a/src/ripple_core/functional/LoadMonitor.h +++ b/src/ripple_core/functional/LoadMonitor.h @@ -4,8 +4,8 @@ */ //============================================================================== -#ifndef RIPPLE_LOADMONITOR_RIPPLEHEADER -#define RIPPLE_LOADMONITOR_RIPPLEHEADER +#ifndef RIPPLE_LOADMONITOR_H_INCLUDED +#define RIPPLE_LOADMONITOR_H_INCLUDED // Monitors load levels and response times diff --git a/src/ripple_core/ripple_core.cpp b/src/ripple_core/ripple_core.cpp index f662309a9..6f237cb37 100644 --- a/src/ripple_core/ripple_core.cpp +++ b/src/ripple_core/ripple_core.cpp @@ -8,19 +8,16 @@ #include "ripple_core.h" -// Needed for InputParser -#include "beast/modules/beast_asio/beast_asio.h" - #include +#include +#include -#include "beast/modules/beast_core/system/BeforeBoost.h" // must come first +#include "beast/modules/beast_core/system/BeforeBoost.h" #include #include #include #include - - #include "nodestore/NodeStore.cpp" namespace ripple diff --git a/src/ripple_data/protocol/RippleAddress.h b/src/ripple_data/protocol/RippleAddress.h index 56a5cb43d..504d33dc4 100644 --- a/src/ripple_data/protocol/RippleAddress.h +++ b/src/ripple_data/protocol/RippleAddress.h @@ -210,4 +210,3 @@ public: }; #endif -// vim:ts=4 diff --git a/src/ripple_data/ripple_data.cpp b/src/ripple_data/ripple_data.cpp index dd85930bf..810a72faf 100644 --- a/src/ripple_data/ripple_data.cpp +++ b/src/ripple_data/ripple_data.cpp @@ -10,7 +10,7 @@ //#include -#include "beast/modules/beast_core/system/BeforeBoost.h" // must come first +#include "beast/modules/beast_core/system/BeforeBoost.h" #include #include #include @@ -28,9 +28,10 @@ #include #include #include -//#include // includes and causes errors due to #define GetMessage #include +#include "../ripple/sslutil/ripple_sslutil.h" + // VFALCO TODO fix these warnings! #if BEAST_MSVC #pragma warning (push) @@ -44,22 +45,18 @@ namespace ripple { -#include "crypto/Base58.h" // for RippleAddress #include "crypto/CKey.h" // needs RippleAddress VFALCO TODO remove this dependency cycle #include "crypto/RFC1751.h" -#include "crypto/CBigNum.cpp" #include "crypto/CKey.cpp" #include "crypto/CKeyDeterministic.cpp" #include "crypto/CKeyECIES.cpp" -#include "crypto/Base58.cpp" #include "crypto/Base58Data.cpp" #include "crypto/RFC1751.cpp" #include "protocol/BuildInfo.cpp" #include "protocol/FieldNames.cpp" #include "protocol/LedgerFormats.cpp" -#include "protocol/PackedMessage.cpp" #include "protocol/RippleAddress.cpp" #include "protocol/SerializedTypes.cpp" #include "protocol/Serializer.cpp" diff --git a/src/ripple_data/ripple_data.h b/src/ripple_data/ripple_data.h index 69934085f..8d68cc16c 100644 --- a/src/ripple_data/ripple_data.h +++ b/src/ripple_data/ripple_data.h @@ -4,43 +4,23 @@ */ //============================================================================== -/** Include this to get the @ref ripple_data module. +#ifndef RIPPLE_DATA_H_INCLUDED +#define RIPPLE_DATA_H_INCLUDED - @file ripple_data.h - @ingroup ripple_data -*/ - -/** Ripple specific data representation and manipulation. - - These form the building blocks of Ripple data. - - @defgroup ripple_data -*/ - -#ifndef RIPPLE_DATA_RIPPLEHEADER -#define RIPPLE_DATA_RIPPLEHEADER - -// VFALCO TODO try to reduce these dependencies #include "../ripple_basics/ripple_basics.h" - -// VFALCO TODO figure out a good place for this file, perhaps give it some -// additional hierarchy via directories. -#include "ripple.pb.h" - #include "../ripple/json/ripple_json.h" -namespace ripple -{ +struct bignum_st; +typedef struct bignum_st BIGNUM; + +namespace ripple { -#include "crypto/CBigNum.h" -#include "crypto/Base58.h" // VFALCO TODO Can be moved to .cpp if we clean up setAlphabet stuff #include "crypto/Base58Data.h" #include "crypto/RFC1751.h" #include "protocol/BuildInfo.h" #include "protocol/FieldNames.h" #include "protocol/HashPrefix.h" -#include "protocol/PackedMessage.h" #include "protocol/Protocol.h" #include "protocol/RippleAddress.h" #include "protocol/RippleSystem.h" diff --git a/src/ripple_hyperleveldb/ripple_hyperleveldb.h b/src/ripple_hyperleveldb/ripple_hyperleveldb.h index 5caa4e204..689a9f12d 100644 --- a/src/ripple_hyperleveldb/ripple_hyperleveldb.h +++ b/src/ripple_hyperleveldb/ripple_hyperleveldb.h @@ -4,8 +4,8 @@ */ //============================================================================== -#ifndef RIPPLE_HYPERLEVELDB_RIPPLEHEADER -#define RIPPLE_HYPERLEVELDB_RIPPLEHEADER +#ifndef RIPPLE_HYPERLEVELDB_H_INCLUDED +#define RIPPLE_HYPERLEVELDB_H_INCLUDED #include "beast/beast/Config.h" diff --git a/src/ripple_leveldb/ripple_leveldb.h b/src/ripple_leveldb/ripple_leveldb.h index eac1af663..e0fa35f03 100644 --- a/src/ripple_leveldb/ripple_leveldb.h +++ b/src/ripple_leveldb/ripple_leveldb.h @@ -4,8 +4,8 @@ */ //============================================================================== -#ifndef RIPPLE_LEVELDB_RIPPLEHEADER -#define RIPPLE_LEVELDB_RIPPLEHEADER +#ifndef RIPPLE_LEVELDB_H_INCLUDED +#define RIPPLE_LEVELDB_H_INCLUDED #include "leveldb/cache.h" #include "leveldb/filter_policy.h" diff --git a/src/ripple_net/ripple_net.cpp b/src/ripple_net/ripple_net.cpp index 05c4139a3..4d5581981 100644 --- a/src/ripple_net/ripple_net.cpp +++ b/src/ripple_net/ripple_net.cpp @@ -12,7 +12,7 @@ #include "BeastConfig.h" -#include "beast/modules/beast_core/system/BeforeBoost.h" // must come first +#include "beast/modules/beast_core/system/BeforeBoost.h" #include #include #include diff --git a/src/ripple_net/ripple_net.h b/src/ripple_net/ripple_net.h index 84e6d8ea4..4001c4b21 100644 --- a/src/ripple_net/ripple_net.h +++ b/src/ripple_net/ripple_net.h @@ -7,7 +7,7 @@ #ifndef RIPPLE_NET_H_INCLUDED #define RIPPLE_NET_H_INCLUDED -#include "beast/modules/beast_core/system/BeforeBoost.h" // must come first +#include "beast/modules/beast_core/system/BeforeBoost.h" #include // For InfoSub #include "beast/modules/beast_asio/beast_asio.h" diff --git a/src/ripple_websocket/ripple_websocket.h b/src/ripple_websocket/ripple_websocket.h index 35fc3b8df..65e77ad09 100644 --- a/src/ripple_websocket/ripple_websocket.h +++ b/src/ripple_websocket/ripple_websocket.h @@ -4,43 +4,23 @@ */ //============================================================================== -#ifndef RIPPLE_WEBSOCKET_RIPPLEHEADER -#define RIPPLE_WEBSOCKET_RIPPLEHEADER - -/** Include this to get the @ref ripple_websocket module. - - This module provides support for websockets. It requires both - boost::asio and OpenSSL. It is a fork of the original websocketpp project - written in C++. - - @note This code contains bugs including one known deadlock. It's a terrible - mess and it needs to be replaced. - - @file ripple_websocket.h - @ingroup ripple_websocket - @deprecated -*/ +#ifndef RIPPLE_WEBSOCKET_H_INCLUDED +#define RIPPLE_WEBSOCKET_H_INCLUDED // needed before inclusion of stdint.h for INT32_MIN/INT32_MAX macros #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS #endif -// VFALCO NOTE Log dependencies have wormed their way into websocketpp, -// which needs the ripple_basic module to compile. -// -// TODO Remove the dependency on ripple_basics and Log. -// Perhaps by using an adapter. -// #include "../ripple_basics/ripple_basics.h" -//------------------------------------------------------------------------------ +#include "beast/modules/beast_core/system/BeforeBoost.h" +#include +#include #include "websocket/src/common.hpp" #include "websocket/src/sockets/socket_base.hpp" - -#include "autosocket/AutoSocket.h" // must come before autotls.hp - +#include "autosocket/AutoSocket.h" // must come before autotls.hpp #include "websocket/src/sockets/autotls.hpp" #include "websocket/src/websocketpp.hpp" #include "websocket/src/logger/logger.hpp"