mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-10 10:52:31 -05:00
[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
This commit is contained in:
parent
a6ab1e81f9
commit
dff16b184b
4 changed files with 17 additions and 11 deletions
|
@ -2784,6 +2784,9 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
|
||||||
hashContinue = uint256();
|
hashContinue = uint256();
|
||||||
if (conn_type_in != ConnectionType::BLOCK_RELAY) {
|
if (conn_type_in != ConnectionType::BLOCK_RELAY) {
|
||||||
m_tx_relay = MakeUnique<TxRelay>();
|
m_tx_relay = MakeUnique<TxRelay>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RelayAddrsWithConn()) {
|
||||||
m_addr_known = MakeUnique<CRollingBloomFilter>(5000, 0.001);
|
m_addr_known = MakeUnique<CRollingBloomFilter>(5000, 0.001);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -861,6 +861,12 @@ public:
|
||||||
return m_conn_type == ConnectionType::INBOUND;
|
return m_conn_type == ConnectionType::INBOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Whether we send addr messages over this connection */
|
||||||
|
bool RelayAddrsWithConn() const
|
||||||
|
{
|
||||||
|
return m_conn_type != ConnectionType::BLOCK_RELAY;
|
||||||
|
}
|
||||||
|
|
||||||
bool ExpectServicesFromConn() const {
|
bool ExpectServicesFromConn() const {
|
||||||
switch(m_conn_type) {
|
switch(m_conn_type) {
|
||||||
case ConnectionType::INBOUND:
|
case ConnectionType::INBOUND:
|
||||||
|
@ -891,8 +897,6 @@ public:
|
||||||
std::chrono::microseconds m_next_addr_send GUARDED_BY(cs_sendProcessing){0};
|
std::chrono::microseconds m_next_addr_send GUARDED_BY(cs_sendProcessing){0};
|
||||||
std::chrono::microseconds m_next_local_addr_send GUARDED_BY(cs_sendProcessing){0};
|
std::chrono::microseconds m_next_local_addr_send GUARDED_BY(cs_sendProcessing){0};
|
||||||
|
|
||||||
bool IsAddrRelayPeer() const { return m_addr_known != nullptr; }
|
|
||||||
|
|
||||||
// List of block ids we still have announce.
|
// List of block ids we still have announce.
|
||||||
// There is no final sorting before sending, as they are always sent immediately
|
// There is no final sorting before sending, as they are always sent immediately
|
||||||
// and in the order requested.
|
// and in the order requested.
|
||||||
|
|
|
@ -1531,7 +1531,7 @@ static void RelayAddress(const CAddress& addr, bool fReachable, const CConnman&
|
||||||
assert(nRelayNodes <= best.size());
|
assert(nRelayNodes <= best.size());
|
||||||
|
|
||||||
auto sortfunc = [&best, &hasher, nRelayNodes](CNode* pnode) {
|
auto sortfunc = [&best, &hasher, nRelayNodes](CNode* pnode) {
|
||||||
if (pnode->IsAddrRelayPeer()) {
|
if (pnode->RelayAddrsWithConn()) {
|
||||||
uint64_t hashKey = CSipHasher(hasher).Write(pnode->GetId()).Finalize();
|
uint64_t hashKey = CSipHasher(hasher).Write(pnode->GetId()).Finalize();
|
||||||
for (unsigned int i = 0; i < nRelayNodes; i++) {
|
for (unsigned int i = 0; i < nRelayNodes; i++) {
|
||||||
if (hashKey > best[i].first) {
|
if (hashKey > best[i].first) {
|
||||||
|
@ -2458,9 +2458,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
|
||||||
UpdatePreferredDownload(pfrom, State(pfrom.GetId()));
|
UpdatePreferredDownload(pfrom, State(pfrom.GetId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pfrom.IsInboundConn() && pfrom.IsAddrRelayPeer())
|
if (!pfrom.IsInboundConn() && !pfrom.IsBlockOnlyConn()) {
|
||||||
{
|
|
||||||
// Advertise our address
|
|
||||||
if (fListen && !::ChainstateActive().IsInitialBlockDownload())
|
if (fListen && !::ChainstateActive().IsInitialBlockDownload())
|
||||||
{
|
{
|
||||||
CAddress addr = GetLocalAddress(&pfrom.addr, pfrom.GetLocalServices());
|
CAddress addr = GetLocalAddress(&pfrom.addr, pfrom.GetLocalServices());
|
||||||
|
@ -2479,6 +2477,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
|
||||||
// Get recent addresses
|
// Get recent addresses
|
||||||
m_connman.PushMessage(&pfrom, CNetMsgMaker(nSendVersion).Make(NetMsgType::GETADDR));
|
m_connman.PushMessage(&pfrom, CNetMsgMaker(nSendVersion).Make(NetMsgType::GETADDR));
|
||||||
pfrom.fGetAddr = true;
|
pfrom.fGetAddr = true;
|
||||||
|
|
||||||
m_connman.MarkAddressGood(pfrom.addr);
|
m_connman.MarkAddressGood(pfrom.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2584,7 +2583,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
|
||||||
std::vector<CAddress> vAddr;
|
std::vector<CAddress> vAddr;
|
||||||
vRecv >> vAddr;
|
vRecv >> vAddr;
|
||||||
|
|
||||||
if (!pfrom.IsAddrRelayPeer()) {
|
if (!pfrom.RelayAddrsWithConn()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (vAddr.size() > MAX_ADDR_TO_SEND)
|
if (vAddr.size() > MAX_ADDR_TO_SEND)
|
||||||
|
@ -3522,7 +3521,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
|
||||||
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from outbound connection. peer=%d\n", pfrom.GetId());
|
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from outbound connection. peer=%d\n", pfrom.GetId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!pfrom.IsAddrRelayPeer()) {
|
if (!pfrom.RelayAddrsWithConn()) {
|
||||||
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from block-relay-only connection. peer=%d\n", pfrom.GetId());
|
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from block-relay-only connection. peer=%d\n", pfrom.GetId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -4122,7 +4121,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
|
||||||
int64_t nNow = GetTimeMicros();
|
int64_t nNow = GetTimeMicros();
|
||||||
auto current_time = GetTime<std::chrono::microseconds>();
|
auto current_time = GetTime<std::chrono::microseconds>();
|
||||||
|
|
||||||
if (pto->IsAddrRelayPeer() && !::ChainstateActive().IsInitialBlockDownload() && pto->m_next_local_addr_send < current_time) {
|
if (pto->RelayAddrsWithConn() && !::ChainstateActive().IsInitialBlockDownload() && pto->m_next_local_addr_send < current_time) {
|
||||||
AdvertiseLocal(pto);
|
AdvertiseLocal(pto);
|
||||||
pto->m_next_local_addr_send = PoissonNextSend(current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
|
pto->m_next_local_addr_send = PoissonNextSend(current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
|
||||||
}
|
}
|
||||||
|
@ -4130,7 +4129,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
|
||||||
//
|
//
|
||||||
// Message: addr
|
// Message: addr
|
||||||
//
|
//
|
||||||
if (pto->IsAddrRelayPeer() && pto->m_next_addr_send < current_time) {
|
if (pto->RelayAddrsWithConn() && pto->m_next_addr_send < current_time) {
|
||||||
pto->m_next_addr_send = PoissonNextSend(current_time, AVG_ADDRESS_BROADCAST_INTERVAL);
|
pto->m_next_addr_send = PoissonNextSend(current_time, AVG_ADDRESS_BROADCAST_INTERVAL);
|
||||||
std::vector<CAddress> vAddr;
|
std::vector<CAddress> vAddr;
|
||||||
vAddr.reserve(pto->vAddrToSend.size());
|
vAddr.reserve(pto->vAddrToSend.size());
|
||||||
|
|
|
@ -147,7 +147,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||||
const int ref_count = node.GetRefCount();
|
const int ref_count = node.GetRefCount();
|
||||||
assert(ref_count >= 0);
|
assert(ref_count >= 0);
|
||||||
(void)node.GetSendVersion();
|
(void)node.GetSendVersion();
|
||||||
(void)node.IsAddrRelayPeer();
|
(void)node.RelayAddrsWithConn();
|
||||||
|
|
||||||
const NetPermissionFlags net_permission_flags = fuzzed_data_provider.ConsumeBool() ?
|
const NetPermissionFlags net_permission_flags = fuzzed_data_provider.ConsumeBool() ?
|
||||||
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}) :
|
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}) :
|
||||||
|
|
Loading…
Add table
Reference in a new issue