From 3aaf6d785766cf37a6731ea28fa2b174ac1b28f5 Mon Sep 17 00:00:00 2001 From: "Nikolaos D. Bougalis" Date: Mon, 7 May 2018 21:24:22 -0700 Subject: [PATCH] Use Boost.Endian instead of custom wrappers --- src/ripple/app/ledger/LedgerMaster.h | 2 +- src/ripple/app/misc/NetworkOPs.h | 2 +- src/ripple/basics/ByteOrder.h | 77 ------ src/ripple/basics/StringUtilities.h | 4 +- src/ripple/basics/base_uint.h | 32 +-- src/ripple/beast/core/ByteOrder.h | 306 ---------------------- src/ripple/beast/core/core.unity.cpp | 3 - src/ripple/nodestore/impl/DecodedBlob.cpp | 1 - src/ripple/overlay/Message.h | 2 +- src/ripple/overlay/impl/ConnectAttempt.h | 2 +- src/ripple/overlay/impl/PeerImp.h | 6 +- src/ripple/overlay/impl/ProtocolMessage.h | 2 +- src/ripple/overlay/impl/TMHello.h | 2 +- src/ripple/overlay/impl/TrafficCount.h | 2 +- src/ripple/protocol/impl/ByteOrder.cpp | 74 ------ src/ripple/protocol/impl/Indexes.cpp | 5 +- src/ripple/protocol/impl/PublicKey.cpp | 1 - src/ripple/protocol/messages.h | 37 +++ src/ripple/unity/protocol.cpp | 1 - src/test/protocol/STTx_test.cpp | 2 +- 20 files changed, 61 insertions(+), 502 deletions(-) delete mode 100644 src/ripple/basics/ByteOrder.h delete mode 100644 src/ripple/beast/core/ByteOrder.h delete mode 100644 src/ripple/protocol/impl/ByteOrder.cpp create mode 100644 src/ripple/protocol/messages.h diff --git a/src/ripple/app/ledger/LedgerMaster.h b/src/ripple/app/ledger/LedgerMaster.h index bcbe9f033..864c80128 100644 --- a/src/ripple/app/ledger/LedgerMaster.h +++ b/src/ripple/app/ledger/LedgerMaster.h @@ -41,7 +41,7 @@ #include #include -#include "ripple.pb.h" +#include namespace ripple { diff --git a/src/ripple/app/misc/NetworkOPs.h b/src/ripple/app/misc/NetworkOPs.h index 26a8965e6..162bcd259 100644 --- a/src/ripple/app/misc/NetworkOPs.h +++ b/src/ripple/app/misc/NetworkOPs.h @@ -32,7 +32,7 @@ #include #include -#include "ripple.pb.h" +#include namespace ripple { diff --git a/src/ripple/basics/ByteOrder.h b/src/ripple/basics/ByteOrder.h deleted file mode 100644 index 72161d208..000000000 --- a/src/ripple/basics/ByteOrder.h +++ /dev/null @@ -1,77 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef RIPPLE_BASICS_BYTEORDER_H_INCLUDED -#define RIPPLE_BASICS_BYTEORDER_H_INCLUDED - -#include - -// For ByteOrder -#if BEAST_WIN32 -// (nothing) -#elif __APPLE__ -#include -#elif defined(__FreeBSD__) || defined(__NetBSD__) -#include -#elif defined(__OpenBSD__) -#include -#endif -#include - -namespace ripple { - -// VFALCO These are all deprecated please use the ones in -// Routines for converting endianness - -// Reference: http://www.mail-archive.com/licq-commits@googlegroups.com/msg02334.html - -#ifdef _MSC_VER -extern std::uint64_t htobe64 (uint64_t value); -extern std::uint64_t be64toh (uint64_t value); -extern std::uint32_t htobe32 (uint32_t value); -extern std::uint32_t be32toh (uint32_t value); - -#elif __APPLE__ -#define htobe16(x) OSSwapHostToBigInt16(x) -#define htole16(x) OSSwapHostToLittleInt16(x) -#define be16toh(x) OSSwapBigToHostInt16(x) -#define le16toh(x) OSSwapLittleToHostInt16(x) - -#define htobe32(x) OSSwapHostToBigInt32(x) -#define htole32(x) OSSwapHostToLittleInt32(x) -#define be32toh(x) OSSwapBigToHostInt32(x) -#define le32toh(x) OSSwapLittleToHostInt32(x) - -#define htobe64(x) OSSwapHostToBigInt64(x) -#define htole64(x) OSSwapHostToLittleInt64(x) -#define be64toh(x) OSSwapBigToHostInt64(x) -#define le64toh(x) OSSwapLittleToHostInt64(x) - -#elif defined(__FreeBSD__) || defined(__NetBSD__) - -#elif defined(__OpenBSD__) -#define be16toh(x) betoh16(x) -#define be32toh(x) betoh32(x) -#define be64toh(x) betoh64(x) - -#endif - -} - -#endif diff --git a/src/ripple/basics/StringUtilities.h b/src/ripple/basics/StringUtilities.h index 0bb6c59c1..18e718fca 100644 --- a/src/ripple/basics/StringUtilities.h +++ b/src/ripple/basics/StringUtilities.h @@ -20,9 +20,9 @@ #ifndef RIPPLE_BASICS_STRINGUTILITIES_H_INCLUDED #define RIPPLE_BASICS_STRINGUTILITIES_H_INCLUDED -#include #include #include +#include #include #include #include @@ -43,7 +43,7 @@ inline std::string strHex (Blob const& vucData) inline std::string strHex (const std::uint64_t uiHost) { - uint64_t uBig = htobe64 (uiHost); + uint64_t uBig = boost::endian::native_to_big (uiHost); return strHex ((unsigned char*) &uBig, sizeof (uBig)); } diff --git a/src/ripple/basics/base_uint.h b/src/ripple/basics/base_uint.h index bfffe34a6..9cc93e91b 100644 --- a/src/ripple/basics/base_uint.h +++ b/src/ripple/basics/base_uint.h @@ -25,11 +25,11 @@ #ifndef RIPPLE_BASICS_BASE_UINT_H_INCLUDED #define RIPPLE_BASICS_BASE_UINT_H_INCLUDED -#include #include #include #include #include +#include #include #include #include @@ -85,6 +85,7 @@ public: pointer data() { return reinterpret_cast(pn.data ()); } const_pointer data() const { return reinterpret_cast(pn.data ()); } + iterator begin() { return data(); } iterator end() { return data()+bytes; } const_iterator begin() const { return data(); } @@ -97,18 +98,6 @@ public: */ using hasher = hardened_hash <>; - /** Container equality testing function. */ - class key_equal - { - public: - explicit key_equal() = default; - - bool operator() (base_uint const& lhs, base_uint const& rhs) const - { - return lhs == rhs; - } - }; - //-------------------------------------------------------------------------- private: @@ -203,7 +192,7 @@ public: std::uint64_t ul; }; // Put in least significant bits. - ul = htobe64 (uHost); + ul = boost::endian::native_to_big(uHost); pn[WIDTH-2] = u[0]; pn[WIDTH-1] = u[1]; return *this; @@ -233,17 +222,12 @@ public: return *this; } - // be32toh and htobe32 are macros that somehow cause shadowing - // warnings in this header file, so we hide them... - static uint32_t bigendToHost (uint32_t x) { return be32toh(x); } - static uint32_t hostToBigend (uint32_t x) { return htobe32(x); } - base_uint& operator++ () { // prefix operator for (int i = WIDTH - 1; i >= 0; --i) { - pn[i] = hostToBigend (bigendToHost (pn[i]) + 1); + pn[i] = boost::endian::native_to_big (boost::endian::big_to_native(pn[i]) + 1); if (pn[i] != 0) break; @@ -266,7 +250,7 @@ public: for (int i = WIDTH - 1; i >= 0; --i) { auto prev = pn[i]; - pn[i] = hostToBigend (bigendToHost (pn[i]) - 1); + pn[i] = boost::endian::native_to_big (boost::endian::big_to_native(pn[i]) - 1); if (prev != 0) break; @@ -290,10 +274,10 @@ public: for (int i = WIDTH; i--;) { - std::uint64_t n = carry + bigendToHost (pn[i]) + - bigendToHost (b.pn[i]); + std::uint64_t n = carry + boost::endian::big_to_native(pn[i]) + + boost::endian::big_to_native(b.pn[i]); - pn[i] = hostToBigend (n & 0xffffffff); + pn[i] = boost::endian::native_to_big (static_cast(n)); carry = n >> 32; } diff --git a/src/ripple/beast/core/ByteOrder.h b/src/ripple/beast/core/ByteOrder.h deleted file mode 100644 index 8d2945d25..000000000 --- a/src/ripple/beast/core/ByteOrder.h +++ /dev/null @@ -1,306 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Portions of this file are from JUCE. - Copyright (c) 2013 - Raw Material Software Ltd. - Please visit http://www.juce.com - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef BEAST_BYTEORDER_H_INCLUDED -#define BEAST_BYTEORDER_H_INCLUDED - -#include - -#include - -namespace beast { - -//============================================================================== -/** Contains static methods for converting the byte order between different - endiannesses. -*/ -class ByteOrder -{ -public: - //============================================================================== - /** Swaps the upper and lower bytes of a 16-bit integer. */ - static std::uint16_t swap (std::uint16_t value); - - /** Reverses the order of the 4 bytes in a 32-bit integer. */ - static std::uint32_t swap (std::uint32_t value); - - /** Reverses the order of the 8 bytes in a 64-bit integer. */ - static std::uint64_t swap (std::uint64_t value); - - //============================================================================== - /** Swaps the byte order of a 16-bit int if the CPU is big-endian */ - static std::uint16_t swapIfBigEndian (std::uint16_t value); - - /** Swaps the byte order of a 32-bit int if the CPU is big-endian */ - static std::uint32_t swapIfBigEndian (std::uint32_t value); - - /** Swaps the byte order of a 64-bit int if the CPU is big-endian */ - static std::uint64_t swapIfBigEndian (std::uint64_t value); - - /** Swaps the byte order of a 16-bit int if the CPU is little-endian */ - static std::uint16_t swapIfLittleEndian (std::uint16_t value); - - /** Swaps the byte order of a 32-bit int if the CPU is little-endian */ - static std::uint32_t swapIfLittleEndian (std::uint32_t value); - - /** Swaps the byte order of a 64-bit int if the CPU is little-endian */ - static std::uint64_t swapIfLittleEndian (std::uint64_t value); - - //============================================================================== - /** Turns 2 bytes into a little-endian integer. */ - static std::uint16_t littleEndianShort (const void* bytes); - - /** Turns 4 bytes into a little-endian integer. */ - static std::uint32_t littleEndianInt (const void* bytes); - - /** Turns 4 bytes into a little-endian integer. */ - static std::uint64_t littleEndianInt64 (const void* bytes); - - /** Turns 2 bytes into a big-endian integer. */ - static std::uint16_t bigEndianShort (const void* bytes); - - /** Turns 4 bytes into a big-endian integer. */ - static std::uint32_t bigEndianInt (const void* bytes); - - /** Turns 4 bytes into a big-endian integer. */ - static std::uint64_t bigEndianInt64 (const void* bytes); - - //============================================================================== - /** Converts 3 little-endian bytes into a signed 24-bit value (which is sign-extended to 32 bits). */ - static int littleEndian24Bit (const char* bytes); - - /** Converts 3 big-endian bytes into a signed 24-bit value (which is sign-extended to 32 bits). */ - static int bigEndian24Bit (const char* bytes); - - /** Copies a 24-bit number to 3 little-endian bytes. */ - static void littleEndian24BitToChars (int value, char* destBytes); - - /** Copies a 24-bit number to 3 big-endian bytes. */ - static void bigEndian24BitToChars (int value, char* destBytes); - - //============================================================================== - /** Returns true if the current CPU is big-endian. */ - static bool isBigEndian(); - -private: - ByteOrder(); - ByteOrder(ByteOrder const&) = delete; - ByteOrder& operator= (ByteOrder const&) = delete; -}; - -//============================================================================== -#if BEAST_USE_INTRINSICS && ! defined (__INTEL_COMPILER) - #pragma intrinsic (_byteswap_ulong) -#endif - -inline std::uint16_t ByteOrder::swap (std::uint16_t n) -{ - #if BEAST_USE_INTRINSICSxxx // agh - the MS compiler has an internal error when you try to use this intrinsic! - return static_cast (_byteswap_ushort (n)); - #else - return static_cast ((n << 8) | (n >> 8)); - #endif -} - -inline std::uint32_t ByteOrder::swap (std::uint32_t n) -{ - #if BEAST_MAC || BEAST_IOS - return OSSwapInt32 (n); - #elif BEAST_GCC && BEAST_INTEL && ! BEAST_NO_INLINE_ASM - asm("bswap %%eax" : "=a"(n) : "a"(n)); - return n; - #elif BEAST_USE_INTRINSICS - return _byteswap_ulong (n); - #elif BEAST_MSVC && ! BEAST_NO_INLINE_ASM - __asm { - mov eax, n - bswap eax - mov n, eax - } - return n; - #elif BEAST_ANDROID - return bswap_32 (n); - #else - return (n << 24) | (n >> 24) | ((n & 0xff00) << 8) | ((n & 0xff0000) >> 8); - #endif -} - -inline std::uint64_t ByteOrder::swap (std::uint64_t value) -{ - #if BEAST_MAC || BEAST_IOS - return OSSwapInt64 (value); - #elif BEAST_USE_INTRINSICS - return _byteswap_uint64 (value); - #else - return (((std::int64_t) swap ((std::uint32_t) value)) << 32) | swap ((std::uint32_t) (value >> 32)); - #endif -} - -#if BEAST_LITTLE_ENDIAN - inline std::uint16_t ByteOrder::swapIfBigEndian (const std::uint16_t v) { return v; } - inline std::uint32_t ByteOrder::swapIfBigEndian (const std::uint32_t v) { return v; } - inline std::uint64_t ByteOrder::swapIfBigEndian (const std::uint64_t v) { return v; } - inline std::uint16_t ByteOrder::swapIfLittleEndian (const std::uint16_t v) { return swap (v); } - inline std::uint32_t ByteOrder::swapIfLittleEndian (const std::uint32_t v) { return swap (v); } - inline std::uint64_t ByteOrder::swapIfLittleEndian (const std::uint64_t v) { return swap (v); } - inline std::uint16_t ByteOrder::littleEndianShort (const void* const bytes) { return *static_cast (bytes); } - inline std::uint32_t ByteOrder::littleEndianInt (const void* const bytes) { return *static_cast (bytes); } - inline std::uint64_t ByteOrder::littleEndianInt64 (const void* const bytes) { return *static_cast (bytes); } - inline std::uint16_t ByteOrder::bigEndianShort (const void* const bytes) { return swap (*static_cast (bytes)); } - inline std::uint32_t ByteOrder::bigEndianInt (const void* const bytes) { return swap (*static_cast (bytes)); } - inline std::uint64_t ByteOrder::bigEndianInt64 (const void* const bytes) { return swap (*static_cast (bytes)); } - inline bool ByteOrder::isBigEndian() { return false; } -#else - inline std::uint16_t ByteOrder::swapIfBigEndian (const std::uint16_t v) { return swap (v); } - inline std::uint32_t ByteOrder::swapIfBigEndian (const std::uint32_t v) { return swap (v); } - inline std::uint64_t ByteOrder::swapIfBigEndian (const std::uint64_t v) { return swap (v); } - inline std::uint16_t ByteOrder::swapIfLittleEndian (const std::uint16_t v) { return v; } - inline std::uint32_t ByteOrder::swapIfLittleEndian (const std::uint32_t v) { return v; } - inline std::uint64_t ByteOrder::swapIfLittleEndian (const std::uint64_t v) { return v; } - inline std::uint32_t ByteOrder::littleEndianInt (const void* const bytes) { return swap (*static_cast (bytes)); } - inline std::uint16_t ByteOrder::littleEndianShort (const void* const bytes) { return swap (*static_cast (bytes)); } - inline std::uint16_t ByteOrder::bigEndianShort (const void* const bytes) { return *static_cast (bytes); } - inline std::uint32_t ByteOrder::bigEndianInt (const void* const bytes) { return *static_cast (bytes); } - inline std::uint64_t ByteOrder::bigEndianInt64 (const void* const bytes) { return *static_cast (bytes); } - inline bool ByteOrder::isBigEndian() { return true; } -#endif - -inline int ByteOrder::littleEndian24Bit (const char* const bytes) { return (((int) bytes[2]) << 16) | (((int) (std::uint8_t) bytes[1]) << 8) | ((int) (std::uint8_t) bytes[0]); } -inline int ByteOrder::bigEndian24Bit (const char* const bytes) { return (((int) bytes[0]) << 16) | (((int) (std::uint8_t) bytes[1]) << 8) | ((int) (std::uint8_t) bytes[2]); } -inline void ByteOrder::littleEndian24BitToChars (const int value, char* const destBytes) { destBytes[0] = (char)(value & 0xff); destBytes[1] = (char)((value >> 8) & 0xff); destBytes[2] = (char)((value >> 16) & 0xff); } -inline void ByteOrder::bigEndian24BitToChars (const int value, char* const destBytes) { destBytes[0] = (char)((value >> 16) & 0xff); destBytes[1] = (char)((value >> 8) & 0xff); destBytes[2] = (char)(value & 0xff); } - -namespace detail -{ - -/** Specialized helper class template for swapping bytes. - - Normally you won't use this directly, use the helper function - byteSwap instead. You can specialize this class for your - own user defined types, as was done for uint24. - - @see swapBytes, uint24 -*/ -template -struct SwapBytes -{ - explicit SwapBytes() = default; - - inline IntegralType operator() (IntegralType value) const noexcept - { - return ByteOrder::swap (value); - } -}; - -// Specializations for signed integers - -template <> -struct SwapBytes -{ - explicit SwapBytes() = default; - - inline std::int16_t operator() (std::int16_t value) const noexcept - { - return static_cast (ByteOrder::swap (static_cast (value))); - } -}; - -template <> -struct SwapBytes -{ - explicit SwapBytes() = default; - - inline std::int32_t operator() (std::int32_t value) const noexcept - { - return static_cast (ByteOrder::swap (static_cast (value))); - } -}; - -template <> -struct SwapBytes -{ - explicit SwapBytes() = default; - - inline std::int64_t operator() (std::int64_t value) const noexcept - { - return static_cast (ByteOrder::swap (static_cast (value))); - } -}; - -} - -//------------------------------------------------------------------------------ - -/** Returns a type with the bytes swapped. - Little endian becomes big endian and vice versa. The underlying - type must be an integral type or behave like one. -*/ -template -inline IntegralType swapBytes (IntegralType value) noexcept -{ - return detail::SwapBytes () (value); -} - -/** Returns the machine byte-order value to little-endian byte order. */ -template -inline IntegralType toLittleEndian (IntegralType value) noexcept -{ -#if BEAST_LITTLE_ENDIAN - return value; -#else - return swapBytes (value); -#endif -} - -/** Returns the machine byte-order value to big-endian byte order. */ -template -inline IntegralType toBigEndian (IntegralType value) noexcept -{ -#if BEAST_LITTLE_ENDIAN - return swapBytes (value); -#else - return value; -#endif -} - -/** Returns the machine byte-order value to network byte order. */ -template -inline IntegralType toNetworkByteOrder (IntegralType value) noexcept -{ - return toBigEndian (value); -} - -/** Converts from network byte order to machine byte order. */ -template -inline IntegralType fromNetworkByteOrder (IntegralType value) noexcept -{ -#if BEAST_LITTLE_ENDIAN - return swapBytes (value); -#else - return value; -#endif -} - -} - -#endif diff --git a/src/ripple/beast/core/core.unity.cpp b/src/ripple/beast/core/core.unity.cpp index 555031c59..ca7178c5f 100644 --- a/src/ripple/beast/core/core.unity.cpp +++ b/src/ripple/beast/core/core.unity.cpp @@ -41,9 +41,6 @@ //------------------------------------------------------------------------------ -// New header-only library modeled more closely according to boost -#include - #include // Order matters, since headers don't have their own #include lines. diff --git a/src/ripple/nodestore/impl/DecodedBlob.cpp b/src/ripple/nodestore/impl/DecodedBlob.cpp index 6419a52f1..f1ffbf3f6 100644 --- a/src/ripple/nodestore/impl/DecodedBlob.cpp +++ b/src/ripple/nodestore/impl/DecodedBlob.cpp @@ -18,7 +18,6 @@ //============================================================================== #include -#include #include #include diff --git a/src/ripple/overlay/Message.h b/src/ripple/overlay/Message.h index 3c255437f..bb8cfe8a7 100644 --- a/src/ripple/overlay/Message.h +++ b/src/ripple/overlay/Message.h @@ -20,7 +20,7 @@ #ifndef RIPPLE_OVERLAY_MESSAGE_H_INCLUDED #define RIPPLE_OVERLAY_MESSAGE_H_INCLUDED -#include "ripple.pb.h" +#include #include #include #include diff --git a/src/ripple/overlay/impl/ConnectAttempt.h b/src/ripple/overlay/impl/ConnectAttempt.h index 80b5c941b..bf16694f0 100644 --- a/src/ripple/overlay/impl/ConnectAttempt.h +++ b/src/ripple/overlay/impl/ConnectAttempt.h @@ -20,7 +20,7 @@ #ifndef RIPPLE_OVERLAY_CONNECTATTEMPT_H_INCLUDED #define RIPPLE_OVERLAY_CONNECTATTEMPT_H_INCLUDED -#include "ripple.pb.h" +#include #include #include diff --git a/src/ripple/overlay/impl/PeerImp.h b/src/ripple/overlay/impl/PeerImp.h index 3e3377e88..ac8888f67 100644 --- a/src/ripple/overlay/impl/PeerImp.h +++ b/src/ripple/overlay/impl/PeerImp.h @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -32,6 +31,7 @@ #include #include +#include #include #include #include @@ -519,8 +519,8 @@ PeerImp::sendEndpoints (FwdIt first, FwdIt last) protocol::TMEndpoint& tme (*tm.add_endpoints()); if (ep.address.is_v4()) tme.mutable_ipv4()->set_ipv4( - beast::toNetworkByteOrder ( - ep.address.to_v4().to_ulong())); + boost::endian::native_to_big( + static_cast(ep.address.to_v4().to_ulong()))); else tme.mutable_ipv4()->set_ipv4(0); tme.mutable_ipv4()->set_ipv4port (ep.address.port()); diff --git a/src/ripple/overlay/impl/ProtocolMessage.h b/src/ripple/overlay/impl/ProtocolMessage.h index 837ba1f63..f4c093d56 100644 --- a/src/ripple/overlay/impl/ProtocolMessage.h +++ b/src/ripple/overlay/impl/ProtocolMessage.h @@ -20,7 +20,7 @@ #ifndef RIPPLE_OVERLAY_PROTOCOLMESSAGE_H_INCLUDED #define RIPPLE_OVERLAY_PROTOCOLMESSAGE_H_INCLUDED -#include "ripple.pb.h" +#include #include #include #include diff --git a/src/ripple/overlay/impl/TMHello.h b/src/ripple/overlay/impl/TMHello.h index 9deba3474..ae0afee74 100644 --- a/src/ripple/overlay/impl/TMHello.h +++ b/src/ripple/overlay/impl/TMHello.h @@ -20,7 +20,7 @@ #ifndef RIPPLE_OVERLAY_TMHELLO_H_INCLUDED #define RIPPLE_OVERLAY_TMHELLO_H_INCLUDED -#include "ripple.pb.h" +#include #include #include #include diff --git a/src/ripple/overlay/impl/TrafficCount.h b/src/ripple/overlay/impl/TrafficCount.h index 85fa6a22d..39df856da 100644 --- a/src/ripple/overlay/impl/TrafficCount.h +++ b/src/ripple/overlay/impl/TrafficCount.h @@ -20,7 +20,7 @@ #ifndef RIPPLE_OVERLAY_TRAFFIC_H_INCLUDED #define RIPPLE_OVERLAY_TRAFFIC_H_INCLUDED -#include "ripple.pb.h" +#include #include #include diff --git a/src/ripple/protocol/impl/ByteOrder.cpp b/src/ripple/protocol/impl/ByteOrder.cpp deleted file mode 100644 index 3d396bf79..000000000 --- a/src/ripple/protocol/impl/ByteOrder.cpp +++ /dev/null @@ -1,74 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - - -#ifdef _MSC_VER -#include -#include -// defines min, max and does other stupid things -# ifdef max -# undef max -# endif -# ifdef min -# undef min -# endif -#endif - -namespace ripple { - -#if _MSC_VER - -// from: http://stackoverflow.com/questions/3022552/is-there-any-standard-htonl-like-function-for-64-bits-integers-in-c -// but we don't need to check the endianness -std::uint64_t htobe64 (uint64_t value) -{ - // The answer is 42 - //static const int num = 42; - - // Check the endianness - //if (*reinterpret_cast(&num) == num) - //{ - const uint32_t high_part = htonl (static_cast (value >> 32)); - const uint32_t low_part = htonl (static_cast (value & 0xFFFFFFFFLL)); - - return (static_cast (low_part) << 32) | high_part; - //} else - //{ - // return value; - //} -} - -std::uint64_t be64toh (uint64_t value) -{ - return (_byteswap_uint64 (value)); -} - -std::uint32_t htobe32 (uint32_t value) -{ - return (htonl (value)); -} - -std::uint32_t be32toh (uint32_t value) -{ - return ( _byteswap_ulong (value)); -} - -#endif - -} diff --git a/src/ripple/protocol/impl/Indexes.cpp b/src/ripple/protocol/impl/Indexes.cpp index 31773d65b..2afd44e93 100644 --- a/src/ripple/protocol/impl/Indexes.cpp +++ b/src/ripple/protocol/impl/Indexes.cpp @@ -19,6 +19,7 @@ #include #include +#include #include namespace ripple { @@ -125,7 +126,7 @@ getQualityIndex (uint256 const& uBase, const std::uint64_t uNodeDir) // TODO(tom): there must be a better way. // VFALCO [base_uint] This assumes a certain storage format - ((std::uint64_t*) uNode.end ())[-1] = htobe64 (uNodeDir); + ((std::uint64_t*) uNode.end ())[-1] = boost::endian::native_to_big (uNodeDir); return uNode; } @@ -142,7 +143,7 @@ std::uint64_t getQuality (uint256 const& uBase) { // VFALCO [base_uint] This assumes a certain storage format - return be64toh (((std::uint64_t*) uBase.end ())[-1]); + return boost::endian::big_to_native (((std::uint64_t*) uBase.end ())[-1]); } uint256 diff --git a/src/ripple/protocol/impl/PublicKey.cpp b/src/ripple/protocol/impl/PublicKey.cpp index 5e7e887e0..3a4b1f4c5 100644 --- a/src/ripple/protocol/impl/PublicKey.cpp +++ b/src/ripple/protocol/impl/PublicKey.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include diff --git a/src/ripple/protocol/messages.h b/src/ripple/protocol/messages.h new file mode 100644 index 000000000..24c8f8429 --- /dev/null +++ b/src/ripple/protocol/messages.h @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2012, 2013 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef RIPPLE_PROTOCOL_MESSAGES_H_INCLUDED +#define RIPPLE_PROTOCOL_MESSAGES_H_INCLUDED + +// Some versions of protobuf generate code that will produce errors during +// compilation. See https://github.com/google/protobuf/issues/549 for more +// details. We work around this by undefining this macro. +// +// TODO: Remove this after the protoc we use is upgraded to not generate +// code that conflicts with the TYPE_BOOL macro. + +#ifdef TYPE_BOOL +#undef TYPE_BOOL +#endif + +#include "ripple.pb.h" + +#endif + diff --git a/src/ripple/unity/protocol.cpp b/src/ripple/unity/protocol.cpp index 57a89e710..867557f82 100644 --- a/src/ripple/unity/protocol.cpp +++ b/src/ripple/unity/protocol.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include diff --git a/src/test/protocol/STTx_test.cpp b/src/test/protocol/STTx_test.cpp index f9e884ad4..32a590869 100644 --- a/src/test/protocol/STTx_test.cpp +++ b/src/test/protocol/STTx_test.cpp @@ -24,7 +24,7 @@ #include #include #include -#include "ripple.pb.h" +#include namespace ripple {