20 #include <ripple/shamap/SHAMapInnerNode.h>
22 #include <ripple/basics/ByteUtilities.h>
23 #include <ripple/basics/Log.h>
24 #include <ripple/basics/Slice.h>
25 #include <ripple/basics/contract.h>
26 #include <ripple/basics/safe_cast.h>
27 #include <ripple/beast/core/LexicalCast.h>
28 #include <ripple/protocol/HashPrefix.h>
29 #include <ripple/protocol/digest.h>
30 #include <ripple/shamap/SHAMapTreeNode.h>
32 #include <openssl/sha.h>
48 auto p = std::make_shared<SHAMapInnerNode>(
cowid);
54 for (
int i = 0; i < 16; ++i)
65 if (data.size() != 512)
66 Throw<std::runtime_error>(
"Invalid FI node");
68 auto ret = std::make_shared<SHAMapInnerNode>(0);
72 for (
int i = 0; i < 16; ++i)
76 if (ret->mHashes[i].isNonZero())
77 ret->mIsBranch |= (1 << i);
94 auto ret = std::make_shared<SHAMapInnerNode>(0);
96 for (
int i = 0; i < (len / 33); ++i)
100 if (!s.
get8(pos, 32 + (i * 33)))
101 Throw<std::runtime_error>(
"short CI node");
103 if ((pos < 0) || (pos >= 16))
104 Throw<std::runtime_error>(
"invalid CI node");
108 if (ret->mHashes[pos].isNonZero())
109 ret->mIsBranch |= (1 << pos);
136 for (
auto pos = 0; pos < 16; ++pos)
153 for (
int i = 0; i <
mHashes.size(); ++i)
194 for (
int i = 0; i < 16; ++i)
205 for (
int i = 0; i <
mHashes.size(); ++i)
222 assert((m >= 0) && (m < 16));
224 assert(child.get() !=
this);
238 assert((m >= 0) && (m < 16));
241 assert(child.get() !=
this);
249 assert(branch >= 0 && branch < 16);
258 assert(branch >= 0 && branch < 16);
269 assert(branch >= 0 && branch < 16);
271 assert(node->getHash() ==
mHashes[branch]);
291 for (
int i = 0; i < 16; ++i)
std::uint32_t cowid() const
Returns the SHAMap that owns this node.
void serializeWithPrefix(Serializer &) const override
Serialize the node in a format appropriate for hashing.
void setChild(int m, std::shared_ptr< SHAMapTreeNode > const &child)
std::shared_ptr< SHAMapTreeNode > clone(std::uint32_t cowid) const override
Make a copy of this node, setting the owner.
std::array< SHAMapHash, 16 > mHashes
Returns the SHA512-Half digest of a message.
std::shared_ptr< SHAMapTreeNode > getChild(int branch)
An immutable linear range of bytes.
static std::shared_ptr< SHAMapTreeNode > makeFullInner(Slice data, SHAMapHash const &hash, bool hashValid)
virtual std::shared_ptr< SHAMapTreeNode > canonicalizeChild(int branch, std::shared_ptr< SHAMapTreeNode > node)
std::uint32_t cowid_
Determines the owning SHAMap, if any.
std::uint32_t mFullBelowGen
int add8(unsigned char i)
void updateHash() override
Recalculate the hash of this node.
void shareChild(int m, std::shared_ptr< SHAMapTreeNode > const &child)
static constexpr unsigned const char wireTypeInner
std::string to_string(ListDisposition disposition)
Identifies a node inside a SHAMap.
virtual std::string getString(SHAMapNodeID const &) const
bool isEmptyBranch(int m) const
std::string getString(SHAMapNodeID const &) const override
@ innerNode
inner node in V1 tree
bool get8(int &, int offset) const
void updateHashDeep()
Recalculate the hash of all children and this node.
int getBranchCount() const
static constexpr unsigned const char wireTypeCompressedInner
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void serializeForWire(Serializer &) const override
Serialize the node in a format appropriate for sending over the wire.
int addBitString(base_uint< Bits, Tag > const &v)
bool getBitString(base_uint< Bits, Tag > &data, int offset) const
std::enable_if_t< is_contiguously_hashable< T, Hasher >::value > hash_append(Hasher &h, T const &t) noexcept
Logically concatenate input data to a Hasher.
void hash_append(Hasher &h, Slice const &v)
static std::mutex childLock
int add32(std::uint32_t i)
static std::shared_ptr< SHAMapTreeNode > makeCompressedInner(Slice data)
SHAMapTreeNode * getChildPointer(int branch)
void invariants(bool is_root=false) const override
std::shared_ptr< SHAMapTreeNode > mChildren[16]