MCPcopy Create free account
hub / github.com/Bitcoin-ABC/bitcoin-abc / MaybeSendAddr

Method MaybeSendAddr

src/net_processing.cpp:8394–8478  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8392}
8393
8394void PeerManagerImpl::MaybeSendAddr(CNode &node, Peer &peer,
8395 std::chrono::microseconds current_time) {
8396 // Nothing to do for non-address-relay peers
8397 if (!peer.m_addr_relay_enabled) {
8398 return;
8399 }
8400
8401 LOCK(peer.m_addr_send_times_mutex);
8402 if (fListen && !m_chainman.IsInitialBlockDownload() &&
8403 peer.m_next_local_addr_send < current_time) {
8404 // If we've sent before, clear the bloom filter for the peer, so
8405 // that our self-announcement will actually go out. This might
8406 // be unnecessary if the bloom filter has already rolled over
8407 // since our last self-announcement, but there is only a small
8408 // bandwidth cost that we can incur by doing this (which happens
8409 // once a day on average).
8410 if (peer.m_next_local_addr_send != 0us) {
8411 peer.m_addr_known->reset();
8412 }
8413 if (std::optional<CService> local_service = GetLocalAddrForPeer(node)) {
8414 CAddress local_addr{*local_service, peer.m_our_services,
8415 Now<NodeSeconds>()};
8416 PushAddress(peer, local_addr);
8417 }
8418 peer.m_next_local_addr_send =
8419 current_time +
8420 m_rng.rand_exp_duration(AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
8421 }
8422
8423 // We sent an `addr` message to this peer recently. Nothing more to do.
8424 if (current_time <= peer.m_next_addr_send) {
8425 return;
8426 }
8427
8428 peer.m_next_addr_send =
8429 current_time + m_rng.rand_exp_duration(AVG_ADDRESS_BROADCAST_INTERVAL);
8430
8431 const size_t max_addr_to_send = m_opts.max_addr_to_send;
8432 if (!Assume(peer.m_addrs_to_send.size() <= max_addr_to_send)) {
8433 // Should be impossible since we always check size before adding to
8434 // m_addrs_to_send. Recover by trimming the vector.
8435 peer.m_addrs_to_send.resize(max_addr_to_send);
8436 }
8437
8438 // Remove addr records that the peer already knows about, and add new
8439 // addrs to the m_addr_known filter on the same pass.
8440 auto addr_already_known =
8441 [&peer](const CAddress &addr)
8442 EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex) {
8443 bool ret = peer.m_addr_known->contains(addr.GetKey());
8444 if (!ret) {
8445 peer.m_addr_known->insert(addr.GetKey());
8446 }
8447 return ret;
8448 };
8449 peer.m_addrs_to_send.erase(std::remove_if(peer.m_addrs_to_send.begin(),
8450 peer.m_addrs_to_send.end(),
8451 addr_already_known),

Callers

nothing calls this directly

Calls 15

GetLocalAddrForPeerFunction · 0.85
WithParamsFunction · 0.85
rand_exp_durationMethod · 0.80
EXCLUSIVE_LOCKS_REQUIREDFunction · 0.70
clearMethod · 0.65
resetMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45
containsMethod · 0.45
GetKeyMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected