Skip to content

Commit 430f489

Browse files
committed
Don't relay addr messages to block-relay-only peers
We don't want relay of addr messages to leak information about these network links.
1 parent 3a5e885 commit 430f489

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/net.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,6 +2647,10 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
26472647
fInbound(fInboundIn),
26482648
nKeyedNetGroup(nKeyedNetGroupIn),
26492649
addrKnown(5000, 0.001),
2650+
// Don't relay addr messages to peers that we connect to as block-relay-only
2651+
// peers (to prevent adversaries from inferring these links from addr
2652+
// traffic).
2653+
m_addr_relay_peer(!block_relay_only),
26502654
id(idIn),
26512655
nLocalHostNonce(nLocalHostNonceIn),
26522656
nLocalServices(nLocalServicesIn),

src/net.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,9 @@ class CNode
712712
int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing){0};
713713
int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing){0};
714714

715+
const bool m_addr_relay_peer;
716+
bool IsAddrRelayPeer() const { return m_addr_relay_peer; }
717+
715718
// List of block ids we still have announce.
716719
// There is no final sorting before sending, as they are always sent immediately
717720
// and in the order requested.
@@ -748,6 +751,7 @@ class CNode
748751

749752
// m_tx_relay == nullptr if we're not relaying transactions with this peer
750753
std::unique_ptr<TxRelay> m_tx_relay;
754+
751755
// Used for headers announcements - unfiltered blocks to relay
752756
std::vector<uint256> vBlockHashesToAnnounce GUARDED_BY(cs_inventory);
753757

src/net_processing.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ static void RelayAddress(const CAddress& addr, bool fReachable, CConnman* connma
13291329
assert(nRelayNodes <= best.size());
13301330

13311331
auto sortfunc = [&best, &hasher, nRelayNodes](CNode* pnode) {
1332-
if (pnode->nVersion >= CADDR_TIME_VERSION) {
1332+
if (pnode->nVersion >= CADDR_TIME_VERSION && pnode->IsAddrRelayPeer()) {
13331333
uint64_t hashKey = CSipHasher(hasher).Write(pnode->GetId()).Finalize();
13341334
for (unsigned int i = 0; i < nRelayNodes; i++) {
13351335
if (hashKey > best[i].first) {
@@ -2018,7 +2018,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
20182018
UpdatePreferredDownload(pfrom, State(pfrom->GetId()));
20192019
}
20202020

2021-
if (!pfrom->fInbound)
2021+
if (!pfrom->fInbound && pfrom->IsAddrRelayPeer())
20222022
{
20232023
// Advertise our address
20242024
if (fListen && !::ChainstateActive().IsInitialBlockDownload())
@@ -2134,6 +2134,9 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
21342134
// Don't want addr from older versions unless seeding
21352135
if (pfrom->nVersion < CADDR_TIME_VERSION && connman->GetAddressCount() > 1000)
21362136
return true;
2137+
if (!pfrom->IsAddrRelayPeer()) {
2138+
return true;
2139+
}
21372140
if (vAddr.size() > 1000)
21382141
{
21392142
LOCK(cs_main);
@@ -2994,6 +2997,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
29942997
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from outbound connection. peer=%d\n", pfrom->GetId());
29952998
return true;
29962999
}
3000+
if (!pfrom->IsAddrRelayPeer()) {
3001+
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from block-relay-only connection. peer=%d\n", pfrom->GetId());
3002+
return true;
3003+
}
29973004

29983005
// Only send one GetAddr response per connection to reduce resource waste
29993006
// and discourage addr stamping of INV announcements.
@@ -3587,15 +3594,15 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
35873594

35883595
// Address refresh broadcast
35893596
int64_t nNow = GetTimeMicros();
3590-
if (!::ChainstateActive().IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) {
3597+
if (pto->IsAddrRelayPeer() && !::ChainstateActive().IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) {
35913598
AdvertiseLocal(pto);
35923599
pto->nNextLocalAddrSend = PoissonNextSend(nNow, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
35933600
}
35943601

35953602
//
35963603
// Message: addr
35973604
//
3598-
if (pto->nNextAddrSend < nNow) {
3605+
if (pto->IsAddrRelayPeer() && pto->nNextAddrSend < nNow) {
35993606
pto->nNextAddrSend = PoissonNextSend(nNow, AVG_ADDRESS_BROADCAST_INTERVAL);
36003607
std::vector<CAddress> vAddr;
36013608
vAddr.reserve(pto->vAddrToSend.size());

0 commit comments

Comments
 (0)