[net_processing] Introduce SetupAddressRelay

Idempotent function that initializes m_addr_known for connections that support
address relay (anything other than block-relay-only). Unused until the next
commit.
pull/21528/head
Amiti Uttarwar 4 years ago
parent 7925f3aba8
commit 2fcaec7bbb

@ -226,7 +226,7 @@ struct Peer {
std::vector<CAddress> m_addrs_to_send;
/** Probabilistic filter of addresses that this peer already knows.
* Used to avoid relaying addresses to this peer more than once. */
const std::unique_ptr<CRollingBloomFilter> m_addr_known;
std::unique_ptr<CRollingBloomFilter> m_addr_known;
/** Whether a getaddr request to this peer is outstanding. */
bool m_getaddr_sent{false};
/** Guards address sending timers. */
@ -612,6 +612,14 @@ private:
* @param[in] vRecv The raw message received
*/
void ProcessGetCFCheckPt(CNode& peer, CDataStream& vRecv);
/** Checks if address relay is permitted with peer. Initializes
* `m_addr_known` bloom filter if needed.
*
* @return True if address relay is enabled with peer
* False if address relay is disallowed
*/
bool SetupAddressRelay(CNode& node, Peer& peer);
};
} // namespace
@ -4423,6 +4431,22 @@ public:
};
}
bool PeerManagerImpl::SetupAddressRelay(CNode& node, Peer& peer)
{
// We don't participate in addr relay with outbound block-relay-only
// connections to prevent providing adversaries with the additional
// information of addr traffic to infer the link.
if (node.IsBlockOnlyConn()) return false;
if (!RelayAddrsWithPeer(peer)) {
// First addr message we have received from the peer, initialize
// m_addr_known
peer.m_addr_known = std::make_unique<CRollingBloomFilter>(5000, 0.001);
}
return true;
}
bool PeerManagerImpl::SendMessages(CNode* pto)
{
PeerRef peer = GetPeerRef(pto->GetId());

Loading…
Cancel
Save