Skip to content

Commit dff16b1

Browse files
committed
[refactor] Restructure logic to check for addr relay.
We previously identified if we relay addresses to the connection by checking for the existence of the m_addr_known data structure. With this commit, we answer this question based on the connection type. IsAddrRelayPeer() checked for the existence of the m_addr_known
1 parent a6ab1e8 commit dff16b1

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

src/net.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,6 +2784,9 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
27842784
hashContinue = uint256();
27852785
if (conn_type_in != ConnectionType::BLOCK_RELAY) {
27862786
m_tx_relay = MakeUnique<TxRelay>();
2787+
}
2788+
2789+
if (RelayAddrsWithConn()) {
27872790
m_addr_known = MakeUnique<CRollingBloomFilter>(5000, 0.001);
27882791
}
27892792

src/net.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,12 @@ class CNode
861861
return m_conn_type == ConnectionType::INBOUND;
862862
}
863863

864+
/* Whether we send addr messages over this connection */
865+
bool RelayAddrsWithConn() const
866+
{
867+
return m_conn_type != ConnectionType::BLOCK_RELAY;
868+
}
869+
864870
bool ExpectServicesFromConn() const {
865871
switch(m_conn_type) {
866872
case ConnectionType::INBOUND:
@@ -891,8 +897,6 @@ class CNode
891897
std::chrono::microseconds m_next_addr_send GUARDED_BY(cs_sendProcessing){0};
892898
std::chrono::microseconds m_next_local_addr_send GUARDED_BY(cs_sendProcessing){0};
893899

894-
bool IsAddrRelayPeer() const { return m_addr_known != nullptr; }
895-
896900
// List of block ids we still have announce.
897901
// There is no final sorting before sending, as they are always sent immediately
898902
// and in the order requested.

src/net_processing.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@ static void RelayAddress(const CAddress& addr, bool fReachable, const CConnman&
15311531
assert(nRelayNodes <= best.size());
15321532

15331533
auto sortfunc = [&best, &hasher, nRelayNodes](CNode* pnode) {
1534-
if (pnode->IsAddrRelayPeer()) {
1534+
if (pnode->RelayAddrsWithConn()) {
15351535
uint64_t hashKey = CSipHasher(hasher).Write(pnode->GetId()).Finalize();
15361536
for (unsigned int i = 0; i < nRelayNodes; i++) {
15371537
if (hashKey > best[i].first) {
@@ -2458,9 +2458,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
24582458
UpdatePreferredDownload(pfrom, State(pfrom.GetId()));
24592459
}
24602460

2461-
if (!pfrom.IsInboundConn() && pfrom.IsAddrRelayPeer())
2462-
{
2463-
// Advertise our address
2461+
if (!pfrom.IsInboundConn() && !pfrom.IsBlockOnlyConn()) {
24642462
if (fListen && !::ChainstateActive().IsInitialBlockDownload())
24652463
{
24662464
CAddress addr = GetLocalAddress(&pfrom.addr, pfrom.GetLocalServices());
@@ -2479,6 +2477,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
24792477
// Get recent addresses
24802478
m_connman.PushMessage(&pfrom, CNetMsgMaker(nSendVersion).Make(NetMsgType::GETADDR));
24812479
pfrom.fGetAddr = true;
2480+
24822481
m_connman.MarkAddressGood(pfrom.addr);
24832482
}
24842483

@@ -2584,7 +2583,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
25842583
std::vector<CAddress> vAddr;
25852584
vRecv >> vAddr;
25862585

2587-
if (!pfrom.IsAddrRelayPeer()) {
2586+
if (!pfrom.RelayAddrsWithConn()) {
25882587
return;
25892588
}
25902589
if (vAddr.size() > MAX_ADDR_TO_SEND)
@@ -3522,7 +3521,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
35223521
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from outbound connection. peer=%d\n", pfrom.GetId());
35233522
return;
35243523
}
3525-
if (!pfrom.IsAddrRelayPeer()) {
3524+
if (!pfrom.RelayAddrsWithConn()) {
35263525
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from block-relay-only connection. peer=%d\n", pfrom.GetId());
35273526
return;
35283527
}
@@ -4122,15 +4121,15 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
41224121
int64_t nNow = GetTimeMicros();
41234122
auto current_time = GetTime<std::chrono::microseconds>();
41244123

4125-
if (pto->IsAddrRelayPeer() && !::ChainstateActive().IsInitialBlockDownload() && pto->m_next_local_addr_send < current_time) {
4124+
if (pto->RelayAddrsWithConn() && !::ChainstateActive().IsInitialBlockDownload() && pto->m_next_local_addr_send < current_time) {
41264125
AdvertiseLocal(pto);
41274126
pto->m_next_local_addr_send = PoissonNextSend(current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
41284127
}
41294128

41304129
//
41314130
// Message: addr
41324131
//
4133-
if (pto->IsAddrRelayPeer() && pto->m_next_addr_send < current_time) {
4132+
if (pto->RelayAddrsWithConn() && pto->m_next_addr_send < current_time) {
41344133
pto->m_next_addr_send = PoissonNextSend(current_time, AVG_ADDRESS_BROADCAST_INTERVAL);
41354134
std::vector<CAddress> vAddr;
41364135
vAddr.reserve(pto->vAddrToSend.size());

src/test/fuzz/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
147147
const int ref_count = node.GetRefCount();
148148
assert(ref_count >= 0);
149149
(void)node.GetSendVersion();
150-
(void)node.IsAddrRelayPeer();
150+
(void)node.RelayAddrsWithConn();
151151

152152
const NetPermissionFlags net_permission_flags = fuzzed_data_provider.ConsumeBool() ?
153153
fuzzed_data_provider.PickValueInArray<NetPermissionFlags>({NetPermissionFlags::PF_NONE, NetPermissionFlags::PF_BLOOMFILTER, NetPermissionFlags::PF_RELAY, NetPermissionFlags::PF_FORCERELAY, NetPermissionFlags::PF_NOBAN, NetPermissionFlags::PF_MEMPOOL, NetPermissionFlags::PF_ISIMPLICIT, NetPermissionFlags::PF_ALL}) :

0 commit comments

Comments
 (0)