Skip to content

Commit d3fa42c

Browse files
committed
Merge bitcoin/bitcoin#21186: net/net processing: Move addr data into net_processing
0829516 [refactor] Remove unused ForEachNodeThen() template (John Newbery) 09cc66c scripted-diff: rename address relay fields (John Newbery) 76568a3 [net processing] Move addr relay data and logic into net processing (John Newbery) caba7ae [net processing] Make RelayAddress() a member function of PeerManagerImpl (John Newbery) 86acc96 [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 ACK 0829516 mzumsande: ACK 0829516, reviewed the code and ran tests. sipa: utACK 0829516 hebasto: re-ACK 0829516 Tree-SHA512: efe0410fac288637f203eb37d1999910791e345872d37e1bd5cde50e25bb3cb1c369ab86b3a166ffd5e06ee72e4508aa2c46d658be6a54e20b4f220d2f57d0a6
2 parents ce4a852 + 0829516 commit d3fa42c

File tree

5 files changed

+133
-183
lines changed

5 files changed

+133
-183
lines changed

src/net.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,10 +2929,6 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const
29292929
m_tx_relay = std::make_unique<TxRelay>();
29302930
}
29312931

2932-
if (RelayAddrsWithConn()) {
2933-
m_addr_known = std::make_unique<CRollingBloomFilter>(5000, 0.001);
2934-
}
2935-
29362932
for (const std::string &msg : getAllNetMessageTypes())
29372933
mapRecvBytesPerMsgCmd[msg] = 0;
29382934
mapRecvBytesPerMsgCmd[NET_MESSAGE_COMMAND_OTHER] = 0;

src/net.h

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ static const int TIMEOUT_INTERVAL = 20 * 60;
5454
static constexpr auto FEELER_INTERVAL = 2min;
5555
/** Run the extra block-relay-only connection loop once every 5 minutes. **/
5656
static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL = 5min;
57-
/** The maximum number of addresses from our addrman to return in response to a getaddr message. */
58-
static constexpr size_t MAX_ADDR_TO_SEND = 1000;
5957
/** Maximum length of incoming protocol messages (no message over 4 MB is currently acceptable). */
6058
static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000;
6159
/** Maximum length of the user agent string in `version` message */
@@ -447,17 +445,11 @@ class CNode
447445
}
448446
bool fClient{false}; // set by version message
449447
bool m_limited_node{false}; //after BIP159, set by version message
450-
/**
451-
* Whether the peer has signaled support for receiving ADDRv2 (BIP155)
452-
* messages, implying a preference to receive ADDRv2 instead of ADDR ones.
453-
*/
454-
std::atomic_bool m_wants_addrv2{false};
455448
/** fSuccessfullyConnected is set to true on receiving VERACK from the peer. */
456449
std::atomic_bool fSuccessfullyConnected{false};
457450
// Setting fDisconnect to true will cause the node to be disconnected the
458451
// next time DisconnectNodes() runs
459452
std::atomic_bool fDisconnect{false};
460-
bool fSentAddr{false};
461453
CSemaphoreGrant grantOutbound;
462454
std::atomic<int> nRefCount{0};
463455

@@ -504,15 +496,6 @@ class CNode
504496
return m_conn_type == ConnectionType::INBOUND;
505497
}
506498

507-
/* Whether we send addr messages over this connection */
508-
bool RelayAddrsWithConn() const
509-
{
510-
// Don't relay addr messages to peers that we connect to as block-relay-only
511-
// peers (to prevent adversaries from inferring these links from addr
512-
// traffic).
513-
return m_conn_type != ConnectionType::BLOCK_RELAY;
514-
}
515-
516499
bool ExpectServicesFromConn() const {
517500
switch (m_conn_type) {
518501
case ConnectionType::INBOUND:
@@ -545,14 +528,6 @@ class CNode
545528
// Peer selected us as (compact blocks) high-bandwidth peer (BIP152)
546529
std::atomic<bool> m_bip152_highbandwidth_from{false};
547530

548-
// flood relay
549-
std::vector<CAddress> vAddrToSend;
550-
std::unique_ptr<CRollingBloomFilter> m_addr_known{nullptr};
551-
bool fGetAddr{false};
552-
Mutex m_addr_send_times_mutex;
553-
std::chrono::microseconds m_next_addr_send GUARDED_BY(m_addr_send_times_mutex){0};
554-
std::chrono::microseconds m_next_local_addr_send GUARDED_BY(m_addr_send_times_mutex){0};
555-
556531
struct TxRelay {
557532
mutable RecursiveMutex cs_filter;
558533
// We use fRelayTxes for two purposes -
@@ -657,37 +632,6 @@ class CNode
657632
nRefCount--;
658633
}
659634

660-
void AddAddressKnown(const CAddress& _addr)
661-
{
662-
assert(m_addr_known);
663-
m_addr_known->insert(_addr.GetKey());
664-
}
665-
666-
/**
667-
* Whether the peer supports the address. For example, a peer that does not
668-
* implement BIP155 cannot receive Tor v3 addresses because it requires
669-
* ADDRv2 (BIP155) encoding.
670-
*/
671-
bool IsAddrCompatible(const CAddress& addr) const
672-
{
673-
return m_wants_addrv2 || addr.IsAddrV1Compatible();
674-
}
675-
676-
void PushAddress(const CAddress& _addr, FastRandomContext &insecure_rand)
677-
{
678-
// Known checking here is only to save space from duplicates.
679-
// SendMessages will filter it again for knowns that were added
680-
// after addresses were pushed.
681-
assert(m_addr_known);
682-
if (_addr.IsValid() && !m_addr_known->contains(_addr.GetKey()) && IsAddrCompatible(_addr)) {
683-
if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
684-
vAddrToSend[insecure_rand.randrange(vAddrToSend.size())] = _addr;
685-
} else {
686-
vAddrToSend.push_back(_addr);
687-
}
688-
}
689-
}
690-
691635
void AddKnownTx(const uint256& hash)
692636
{
693637
if (m_tx_relay != nullptr) {
@@ -900,28 +844,6 @@ class CConnman
900844
}
901845
};
902846

903-
template<typename Callable, typename CallableAfter>
904-
void ForEachNodeThen(Callable&& pre, CallableAfter&& post)
905-
{
906-
LOCK(cs_vNodes);
907-
for (auto&& node : vNodes) {
908-
if (NodeFullyConnected(node))
909-
pre(node);
910-
}
911-
post();
912-
};
913-
914-
template<typename Callable, typename CallableAfter>
915-
void ForEachNodeThen(Callable&& pre, CallableAfter&& post) const
916-
{
917-
LOCK(cs_vNodes);
918-
for (auto&& node : vNodes) {
919-
if (NodeFullyConnected(node))
920-
pre(node);
921-
}
922-
post();
923-
};
924-
925847
// Addrman functions
926848
/**
927849
* Return all or many randomly selected addresses, optionally by network.

0 commit comments

Comments
 (0)