mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Merge bitcoin/bitcoin#21186: net/net processing: Move addr data into net_processing
0829516d1f[refactor] Remove unused ForEachNodeThen() template (John Newbery)09cc66c00escripted-diff: rename address relay fields (John Newbery)76568a3351[net processing] Move addr relay data and logic into net processing (John Newbery)caba7ae8a5[net processing] Make RelayAddress() a member function of PeerManagerImpl (John Newbery)86acc96469[net processing] Take NodeId instead of CNode* as originator for RelayAddress() (John Newbery) Pull request description: This continues the work of moving application layer data into net_processing, by moving all addr data into the new Peer object added in #19607. For motivation, see #19398. ACKs for top commit: laanwj: Code review ACK0829516d1fmzumsande: ACK0829516d1f, reviewed the code and ran tests. sipa: utACK0829516d1fhebasto: re-ACK0829516d1fTree-SHA512: efe0410fac288637f203eb37d1999910791e345872d37e1bd5cde50e25bb3cb1c369ab86b3a166ffd5e06ee72e4508aa2c46d658be6a54e20b4f220d2f57d0a6
This commit is contained in:
78
src/net.h
78
src/net.h
@@ -54,8 +54,6 @@ static const int TIMEOUT_INTERVAL = 20 * 60;
|
||||
static constexpr auto FEELER_INTERVAL = 2min;
|
||||
/** Run the extra block-relay-only connection loop once every 5 minutes. **/
|
||||
static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL = 5min;
|
||||
/** The maximum number of addresses from our addrman to return in response to a getaddr message. */
|
||||
static constexpr size_t MAX_ADDR_TO_SEND = 1000;
|
||||
/** Maximum length of incoming protocol messages (no message over 4 MB is currently acceptable). */
|
||||
static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000;
|
||||
/** Maximum length of the user agent string in `version` message */
|
||||
@@ -447,17 +445,11 @@ public:
|
||||
}
|
||||
bool fClient{false}; // set by version message
|
||||
bool m_limited_node{false}; //after BIP159, set by version message
|
||||
/**
|
||||
* Whether the peer has signaled support for receiving ADDRv2 (BIP155)
|
||||
* messages, implying a preference to receive ADDRv2 instead of ADDR ones.
|
||||
*/
|
||||
std::atomic_bool m_wants_addrv2{false};
|
||||
/** fSuccessfullyConnected is set to true on receiving VERACK from the peer. */
|
||||
std::atomic_bool fSuccessfullyConnected{false};
|
||||
// Setting fDisconnect to true will cause the node to be disconnected the
|
||||
// next time DisconnectNodes() runs
|
||||
std::atomic_bool fDisconnect{false};
|
||||
bool fSentAddr{false};
|
||||
CSemaphoreGrant grantOutbound;
|
||||
std::atomic<int> nRefCount{0};
|
||||
|
||||
@@ -504,15 +496,6 @@ public:
|
||||
return m_conn_type == ConnectionType::INBOUND;
|
||||
}
|
||||
|
||||
/* Whether we send addr messages over this connection */
|
||||
bool RelayAddrsWithConn() const
|
||||
{
|
||||
// Don't relay addr messages to peers that we connect to as block-relay-only
|
||||
// peers (to prevent adversaries from inferring these links from addr
|
||||
// traffic).
|
||||
return m_conn_type != ConnectionType::BLOCK_RELAY;
|
||||
}
|
||||
|
||||
bool ExpectServicesFromConn() const {
|
||||
switch (m_conn_type) {
|
||||
case ConnectionType::INBOUND:
|
||||
@@ -545,14 +528,6 @@ public:
|
||||
// Peer selected us as (compact blocks) high-bandwidth peer (BIP152)
|
||||
std::atomic<bool> m_bip152_highbandwidth_from{false};
|
||||
|
||||
// flood relay
|
||||
std::vector<CAddress> vAddrToSend;
|
||||
std::unique_ptr<CRollingBloomFilter> m_addr_known{nullptr};
|
||||
bool fGetAddr{false};
|
||||
Mutex m_addr_send_times_mutex;
|
||||
std::chrono::microseconds m_next_addr_send GUARDED_BY(m_addr_send_times_mutex){0};
|
||||
std::chrono::microseconds m_next_local_addr_send GUARDED_BY(m_addr_send_times_mutex){0};
|
||||
|
||||
struct TxRelay {
|
||||
mutable RecursiveMutex cs_filter;
|
||||
// We use fRelayTxes for two purposes -
|
||||
@@ -657,37 +632,6 @@ public:
|
||||
nRefCount--;
|
||||
}
|
||||
|
||||
void AddAddressKnown(const CAddress& _addr)
|
||||
{
|
||||
assert(m_addr_known);
|
||||
m_addr_known->insert(_addr.GetKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the peer supports the address. For example, a peer that does not
|
||||
* implement BIP155 cannot receive Tor v3 addresses because it requires
|
||||
* ADDRv2 (BIP155) encoding.
|
||||
*/
|
||||
bool IsAddrCompatible(const CAddress& addr) const
|
||||
{
|
||||
return m_wants_addrv2 || addr.IsAddrV1Compatible();
|
||||
}
|
||||
|
||||
void PushAddress(const CAddress& _addr, FastRandomContext &insecure_rand)
|
||||
{
|
||||
// Known checking here is only to save space from duplicates.
|
||||
// SendMessages will filter it again for knowns that were added
|
||||
// after addresses were pushed.
|
||||
assert(m_addr_known);
|
||||
if (_addr.IsValid() && !m_addr_known->contains(_addr.GetKey()) && IsAddrCompatible(_addr)) {
|
||||
if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
|
||||
vAddrToSend[insecure_rand.randrange(vAddrToSend.size())] = _addr;
|
||||
} else {
|
||||
vAddrToSend.push_back(_addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AddKnownTx(const uint256& hash)
|
||||
{
|
||||
if (m_tx_relay != nullptr) {
|
||||
@@ -900,28 +844,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Callable, typename CallableAfter>
|
||||
void ForEachNodeThen(Callable&& pre, CallableAfter&& post)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (auto&& node : vNodes) {
|
||||
if (NodeFullyConnected(node))
|
||||
pre(node);
|
||||
}
|
||||
post();
|
||||
};
|
||||
|
||||
template<typename Callable, typename CallableAfter>
|
||||
void ForEachNodeThen(Callable&& pre, CallableAfter&& post) const
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (auto&& node : vNodes) {
|
||||
if (NodeFullyConnected(node))
|
||||
pre(node);
|
||||
}
|
||||
post();
|
||||
};
|
||||
|
||||
// Addrman functions
|
||||
/**
|
||||
* Return all or many randomly selected addresses, optionally by network.
|
||||
|
||||
Reference in New Issue
Block a user