aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.cpp
diff options
context:
space:
mode:
authorAmiti Uttarwar <amiti@uttarwar.org>2021-09-24 14:14:39 -0600
committerAmiti Uttarwar <amiti@uttarwar.org>2021-09-28 14:46:02 -0400
commit5faa7dd6d871eac1a0ec5c4a93f2ad7577781a56 (patch)
treedeeec23512fef5de5ba1b6d3bb37978c0fcc0f32 /src/addrman.cpp
parentefa227f5df5f5a9669dec5f1d574cf22d3c0903f (diff)
downloadbitcoin-5faa7dd6d871eac1a0ec5c4a93f2ad7577781a56.tar.xz
[move-only] Move CAddrMan function definitions to cpp
In preparation for introducing the pimpl pattern to addrman, move all function bodies out of the header file. Review hint: use git diff --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
Diffstat (limited to 'src/addrman.cpp')
-rw-r--r--src/addrman.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp
index 7c6b8fe64d..0fa8edd316 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -119,6 +119,11 @@ CAddrMan::CAddrMan(std::vector<bool> asmap, bool deterministic, int32_t consiste
}
}
+CAddrMan::~CAddrMan()
+{
+ nKey.SetNull();
+}
+
template <typename Stream>
void CAddrMan::Serialize(Stream& s_) const
{
@@ -1017,3 +1022,97 @@ CAddrInfo CAddrMan::SelectTriedCollision_()
return mapInfo[id_old];
}
+
+size_t CAddrMan::size() const
+{
+ LOCK(cs); // TODO: Cache this in an atomic to avoid this overhead
+ return vRandom.size();
+}
+
+bool CAddrMan::Add(const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t nTimePenalty)
+{
+ LOCK(cs);
+ int nAdd = 0;
+ Check();
+ for (std::vector<CAddress>::const_iterator it = vAddr.begin(); it != vAddr.end(); it++)
+ nAdd += Add_(*it, source, nTimePenalty) ? 1 : 0;
+ Check();
+ if (nAdd) {
+ LogPrint(BCLog::ADDRMAN, "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString(), nTried, nNew);
+ }
+ return nAdd > 0;
+}
+
+void CAddrMan::Good(const CService &addr, int64_t nTime)
+{
+ LOCK(cs);
+ Check();
+ Good_(addr, /* test_before_evict */ true, nTime);
+ Check();
+}
+
+void CAddrMan::Attempt(const CService &addr, bool fCountFailure, int64_t nTime)
+{
+ LOCK(cs);
+ Check();
+ Attempt_(addr, fCountFailure, nTime);
+ Check();
+}
+
+
+void CAddrMan::ResolveCollisions()
+{
+ LOCK(cs);
+ Check();
+ ResolveCollisions_();
+ Check();
+}
+
+CAddrInfo CAddrMan::SelectTriedCollision()
+{
+ LOCK(cs);
+ Check();
+ const CAddrInfo ret = SelectTriedCollision_();
+ Check();
+ return ret;
+}
+
+CAddrInfo CAddrMan::Select(bool newOnly) const
+{
+ LOCK(cs);
+ Check();
+ const CAddrInfo addrRet = Select_(newOnly);
+ Check();
+ return addrRet;
+}
+
+std::vector<CAddress> CAddrMan::GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network) const
+{
+ LOCK(cs);
+ Check();
+ std::vector<CAddress> vAddr;
+ GetAddr_(vAddr, max_addresses, max_pct, network);
+ Check();
+ return vAddr;
+}
+
+void CAddrMan::Connected(const CService &addr, int64_t nTime)
+{
+ LOCK(cs);
+ Check();
+ Connected_(addr, nTime);
+ Check();
+}
+
+void CAddrMan::SetServices(const CService &addr, ServiceFlags nServices)
+{
+ LOCK(cs);
+ Check();
+ SetServices_(addr, nServices);
+ Check();
+}
+
+const std::vector<bool>& CAddrMan::GetAsmap() const
+{
+ return m_asmap;
+}