aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.h
diff options
context:
space:
mode:
authorAmiti Uttarwar <amiti@uttarwar.org>2021-12-09 18:25:22 +0000
committerMartin Zumsande <mzumsande@gmail.com>2021-12-28 17:26:24 +0100
commitdad5f760211df314d650999e0a76edb0151b4fe1 (patch)
tree8e2ea058429dcf71f4729f572d83e5dbf375ad98 /src/addrman.h
parent7551ae81e1a9d5bf14b434bce7528ac000d8afe1 (diff)
downloadbitcoin-dad5f760211df314d650999e0a76edb0151b4fe1.tar.xz
addrman: Introduce a test-only function to lookup addresses
Co-Authored-By: Martin Zumsande <mzumsande@gmail.com>
Diffstat (limited to 'src/addrman.h')
-rw-r--r--src/addrman.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/addrman.h b/src/addrman.h
index e9bc372380..1181bdd300 100644
--- a/src/addrman.h
+++ b/src/addrman.h
@@ -22,6 +22,31 @@ class AddrManImpl;
/** Default for -checkaddrman */
static constexpr int32_t DEFAULT_ADDRMAN_CONSISTENCY_CHECKS{0};
+/** Test-only struct, capturing info about an address in AddrMan */
+struct AddressPosition {
+ // Whether the address is in the new or tried table
+ const bool tried;
+
+ // Addresses in the tried table should always have a multiplicity of 1.
+ // Addresses in the new table can have multiplicity between 1 and
+ // ADDRMAN_NEW_BUCKETS_PER_ADDRESS
+ const int multiplicity;
+
+ // If the address is in the new table, the bucket and position are
+ // populated based on the first source who sent the address.
+ // In certain edge cases, this may not be where the address is currently
+ // located.
+ const int bucket;
+ const int position;
+
+ bool operator==(AddressPosition other) {
+ return std::tie(tried, multiplicity, bucket, position) ==
+ std::tie(other.tried, other.multiplicity, other.bucket, other.position);
+ }
+ explicit AddressPosition(bool tried_in, int multiplicity_in, int bucket_in, int position_in)
+ : tried{tried_in}, multiplicity{multiplicity_in}, bucket{bucket_in}, position{position_in} {}
+};
+
/** Stochastic address manager
*
* Design goals:
@@ -142,6 +167,15 @@ public:
void SetServices(const CService& addr, ServiceFlags nServices);
const std::vector<bool>& GetAsmap() const;
+
+ /** Test-only function
+ * Find the address record in AddrMan and return information about its
+ * position.
+ * @param[in] addr The address record to look up.
+ * @return Information about the address record in AddrMan
+ * or nullopt if address is not found.
+ */
+ std::optional<AddressPosition> FindAddressEntry(const CAddress& addr);
};
#endif // BITCOIN_ADDRMAN_H