mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01: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:
@@ -1531,7 +1531,7 @@ static void RelayAddress(const CAddress& addr, bool fReachable, const CConnman&
|
||||
assert(nRelayNodes <= best.size());
|
||||
|
||||
auto sortfunc = [&best, &hasher, nRelayNodes](CNode* pnode) {
|
||||
if (pnode->IsAddrRelayPeer()) {
|
||||
if (pnode->RelayAddrsWithConn()) {
|
||||
uint64_t hashKey = CSipHasher(hasher).Write(pnode->GetId()).Finalize();
|
||||
for (unsigned int i = 0; i < nRelayNodes; i++) {
|
||||
if (hashKey > best[i].first) {
|
||||
@@ -2458,9 +2458,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
|
||||
UpdatePreferredDownload(pfrom, State(pfrom.GetId()));
|
||||
}
|
||||
|
||||
if (!pfrom.IsInboundConn() && pfrom.IsAddrRelayPeer())
|
||||
{
|
||||
// Advertise our address
|
||||
if (!pfrom.IsInboundConn() && !pfrom.IsBlockOnlyConn()) {
|
||||
if (fListen && !::ChainstateActive().IsInitialBlockDownload())
|
||||
{
|
||||
CAddress addr = GetLocalAddress(&pfrom.addr, pfrom.GetLocalServices());
|
||||
@@ -2479,6 +2477,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
|
||||
// Get recent addresses
|
||||
m_connman.PushMessage(&pfrom, CNetMsgMaker(nSendVersion).Make(NetMsgType::GETADDR));
|
||||
pfrom.fGetAddr = true;
|
||||
|
||||
m_connman.MarkAddressGood(pfrom.addr);
|
||||
}
|
||||
|
||||
@@ -2584,7 +2583,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
|
||||
std::vector<CAddress> vAddr;
|
||||
vRecv >> vAddr;
|
||||
|
||||
if (!pfrom.IsAddrRelayPeer()) {
|
||||
if (!pfrom.RelayAddrsWithConn()) {
|
||||
return;
|
||||
}
|
||||
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());
|
||||
return;
|
||||
}
|
||||
if (!pfrom.IsAddrRelayPeer()) {
|
||||
if (!pfrom.RelayAddrsWithConn()) {
|
||||
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from block-relay-only connection. peer=%d\n", pfrom.GetId());
|
||||
return;
|
||||
}
|
||||
@@ -4122,7 +4121,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
|
||||
int64_t nNow = GetTimeMicros();
|
||||
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);
|
||||
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
|
||||
//
|
||||
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);
|
||||
std::vector<CAddress> vAddr;
|
||||
vAddr.reserve(pto->vAddrToSend.size());
|
||||
|
||||
Reference in New Issue
Block a user