Skip to content

Commit 76568a3

Browse files
committed
[net processing] Move addr relay data and logic into net processing
1 parent caba7ae commit 76568a3

File tree

4 files changed

+112
-138
lines changed

4 files changed

+112
-138
lines changed

src/net.cpp

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

2929-
if (RelayAddrsWithConn()) {
2930-
m_addr_known = std::make_unique<CRollingBloomFilter>(5000, 0.001);
2931-
}
2932-
29332929
for (const std::string &msg : getAllNetMessageTypes())
29342930
mapRecvBytesPerMsgCmd[msg] = 0;
29352931
mapRecvBytesPerMsgCmd[NET_MESSAGE_COMMAND_OTHER] = 0;

src/net.h

Lines changed: 0 additions & 56 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) {

0 commit comments

Comments
 (0)