MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ProcessAddrs

Method ProcessAddrs

src/net_processing.cpp:5729–5814  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5727}
5728
5729void PeerManagerImpl::ProcessAddrs(std::string_view msg_type, CNode& pfrom, Peer& peer, std::vector<CAddress>&& vAddr, const std::atomic<bool>& interruptMsgProc)
5730{
5731 AssertLockNotHeld(m_peer_mutex);
5732 AssertLockHeld(g_msgproc_mutex);
5733
5734 if (!SetupAddressRelay(pfrom, peer)) {
5735 LogDebug(BCLog::NET, "ignoring %s message from %s peer=%d\n", msg_type, pfrom.ConnectionTypeAsString(), pfrom.GetId());
5736 return;
5737 }
5738
5739 if (vAddr.size() > MAX_ADDR_TO_SEND)
5740 {
5741 Misbehaving(peer, strprintf("%s message size = %u", msg_type, vAddr.size()));
5742 return;
5743 }
5744
5745 // Store the new addresses
5746 std::vector<CAddress> vAddrOk;
5747
5748 // Update/increment addr rate limiting bucket.
5749 const auto current_time{NodeClock::now()};
5750 if (peer.m_addr_token_bucket < MAX_ADDR_PROCESSING_TOKEN_BUCKET) {
5751 // Don't increment bucket if it's already full
5752 const auto time_diff{current_time - peer.m_addr_token_timestamp};
5753 const double increment{std::max(Ticks<SecondsDouble>(time_diff), 0.0) * MAX_ADDR_RATE_PER_SECOND};
5754 peer.m_addr_token_bucket = std::min<double>(peer.m_addr_token_bucket + increment, MAX_ADDR_PROCESSING_TOKEN_BUCKET);
5755 }
5756 peer.m_addr_token_timestamp = current_time;
5757
5758 const bool rate_limited = !pfrom.HasPermission(NetPermissionFlags::Addr);
5759 uint64_t num_proc = 0;
5760 uint64_t num_rate_limit = 0;
5761 std::shuffle(vAddr.begin(), vAddr.end(), m_rng);
5762 for (CAddress& addr : vAddr)
5763 {
5764 if (interruptMsgProc)
5765 return;
5766
5767 // Apply rate limiting.
5768 if (peer.m_addr_token_bucket < 1.0) {
5769 if (rate_limited) {
5770 ++num_rate_limit;
5771 continue;
5772 }
5773 } else {
5774 peer.m_addr_token_bucket -= 1.0;
5775 }
5776 // We only bother storing full nodes, though this may include
5777 // things which we would not make an outbound connection to, in
5778 // part because we may make feeler connections to them.
5779 if (!MayHaveUsefulAddressDB(addr.nServices) && !HasAllDesirableServiceFlags(addr.nServices))
5780 continue;
5781
5782 if (addr.nTime <= NodeSeconds{100000000s} || addr.nTime > current_time + 10min) {
5783 addr.nTime = std::chrono::time_point_cast<std::chrono::seconds>(current_time - 5 * 24h);
5784 }
5785 AddAddressKnown(peer, addr);
5786 if (m_banman && (m_banman->IsDiscouraged(addr) || m_banman->IsBanned(addr))) {

Callers

nothing calls this directly

Calls 15

MayHaveUsefulAddressDBFunction · 0.85
GetIdMethod · 0.80
HasPermissionMethod · 0.80
IsDiscouragedMethod · 0.80
IsBannedMethod · 0.80
IsRoutableMethod · 0.80
IsAddrFetchConnMethod · 0.80
DisconnectMsgMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected