MCPcopy Create free account
hub / github.com/ElementsProject/elements / operator==

Method operator==

src/test/fuzz/addrman.cpp:140–223  ·  view source on GitHub ↗

* Compare with another AddrMan. * This compares: * - the values in `mapInfo` (the keys aka ids are ignored) * - vvNew entries refer to the same addresses * - vvTried entries refer to the same addresses */

Source from the content-addressed store, hash-verified

138 * - vvTried entries refer to the same addresses
139 */
140 bool operator==(const AddrManDeterministic& other) const
141 {
142 LOCK2(m_impl->cs, other.m_impl->cs);
143
144 if (m_impl->mapInfo.size() != other.m_impl->mapInfo.size() || m_impl->nNew != other.m_impl->nNew ||
145 m_impl->nTried != other.m_impl->nTried) {
146 return false;
147 }
148
149 // Check that all values in `mapInfo` are equal to all values in `other.mapInfo`.
150 // Keys may be different.
151
152 auto addrinfo_hasher = [](const AddrInfo& a) {
153 CSipHasher hasher(0, 0);
154 auto addr_key = a.GetKey();
155 auto source_key = a.source.GetAddrBytes();
156 hasher.Write(a.nLastSuccess);
157 hasher.Write(a.nAttempts);
158 hasher.Write(a.nRefCount);
159 hasher.Write(a.fInTried);
160 hasher.Write(a.GetNetwork());
161 hasher.Write(a.source.GetNetwork());
162 hasher.Write(addr_key.size());
163 hasher.Write(source_key.size());
164 hasher.Write(addr_key.data(), addr_key.size());
165 hasher.Write(source_key.data(), source_key.size());
166 return (size_t)hasher.Finalize();
167 };
168
169 auto addrinfo_eq = [](const AddrInfo& lhs, const AddrInfo& rhs) {
170 return std::tie(static_cast<const CService&>(lhs), lhs.source, lhs.nLastSuccess, lhs.nAttempts, lhs.nRefCount, lhs.fInTried) ==
171 std::tie(static_cast<const CService&>(rhs), rhs.source, rhs.nLastSuccess, rhs.nAttempts, rhs.nRefCount, rhs.fInTried);
172 };
173
174 using Addresses = std::unordered_set<AddrInfo, decltype(addrinfo_hasher), decltype(addrinfo_eq)>;
175
176 const size_t num_addresses{m_impl->mapInfo.size()};
177
178 Addresses addresses{num_addresses, addrinfo_hasher, addrinfo_eq};
179 for (const auto& [id, addr] : m_impl->mapInfo) {
180 addresses.insert(addr);
181 }
182
183 Addresses other_addresses{num_addresses, addrinfo_hasher, addrinfo_eq};
184 for (const auto& [id, addr] : other.m_impl->mapInfo) {
185 other_addresses.insert(addr);
186 }
187
188 if (addresses != other_addresses) {
189 return false;
190 }
191
192 auto IdsReferToSameAddress = [&](nid_type id, nid_type other_id) EXCLUSIVE_LOCKS_REQUIRED(m_impl->cs, other.m_impl->cs) {
193 if (id == -1 && other_id == -1) {
194 return true;
195 }
196 if ((id == -1 && other_id != -1) || (id != -1 && other_id == -1)) {
197 return false;

Callers

nothing calls this directly

Calls 9

GetAddrBytesMethod · 0.80
GetNetworkMethod · 0.80
EXCLUSIVE_LOCKS_REQUIREDFunction · 0.50
sizeMethod · 0.45
GetKeyMethod · 0.45
WriteMethod · 0.45
dataMethod · 0.45
FinalizeMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected