mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 23:07:59 +01:00
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.
This commit is contained in:
parent
3a5e885306
commit
430f489027
3 changed files with 19 additions and 4 deletions
|
@ -2647,6 +2647,10 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
|
||||||
fInbound(fInboundIn),
|
fInbound(fInboundIn),
|
||||||
nKeyedNetGroup(nKeyedNetGroupIn),
|
nKeyedNetGroup(nKeyedNetGroupIn),
|
||||||
addrKnown(5000, 0.001),
|
addrKnown(5000, 0.001),
|
||||||
|
// Don't relay addr messages to peers that we connect to as block-relay-only
|
||||||
|
// peers (to prevent adversaries from inferring these links from addr
|
||||||
|
// traffic).
|
||||||
|
m_addr_relay_peer(!block_relay_only),
|
||||||
id(idIn),
|
id(idIn),
|
||||||
nLocalHostNonce(nLocalHostNonceIn),
|
nLocalHostNonce(nLocalHostNonceIn),
|
||||||
nLocalServices(nLocalServicesIn),
|
nLocalServices(nLocalServicesIn),
|
||||||
|
|
|
@ -712,6 +712,9 @@ public:
|
||||||
int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing){0};
|
int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing){0};
|
||||||
int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing){0};
|
int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing){0};
|
||||||
|
|
||||||
|
const bool m_addr_relay_peer;
|
||||||
|
bool IsAddrRelayPeer() const { return m_addr_relay_peer; }
|
||||||
|
|
||||||
// List of block ids we still have announce.
|
// List of block ids we still have announce.
|
||||||
// There is no final sorting before sending, as they are always sent immediately
|
// There is no final sorting before sending, as they are always sent immediately
|
||||||
// and in the order requested.
|
// and in the order requested.
|
||||||
|
@ -748,6 +751,7 @@ public:
|
||||||
|
|
||||||
// m_tx_relay == nullptr if we're not relaying transactions with this peer
|
// m_tx_relay == nullptr if we're not relaying transactions with this peer
|
||||||
std::unique_ptr<TxRelay> m_tx_relay;
|
std::unique_ptr<TxRelay> m_tx_relay;
|
||||||
|
|
||||||
// Used for headers announcements - unfiltered blocks to relay
|
// Used for headers announcements - unfiltered blocks to relay
|
||||||
std::vector<uint256> vBlockHashesToAnnounce GUARDED_BY(cs_inventory);
|
std::vector<uint256> vBlockHashesToAnnounce GUARDED_BY(cs_inventory);
|
||||||
|
|
||||||
|
|
|
@ -1329,7 +1329,7 @@ static void RelayAddress(const CAddress& addr, bool fReachable, CConnman* connma
|
||||||
assert(nRelayNodes <= best.size());
|
assert(nRelayNodes <= best.size());
|
||||||
|
|
||||||
auto sortfunc = [&best, &hasher, nRelayNodes](CNode* pnode) {
|
auto sortfunc = [&best, &hasher, nRelayNodes](CNode* pnode) {
|
||||||
if (pnode->nVersion >= CADDR_TIME_VERSION) {
|
if (pnode->nVersion >= CADDR_TIME_VERSION && pnode->IsAddrRelayPeer()) {
|
||||||
uint64_t hashKey = CSipHasher(hasher).Write(pnode->GetId()).Finalize();
|
uint64_t hashKey = CSipHasher(hasher).Write(pnode->GetId()).Finalize();
|
||||||
for (unsigned int i = 0; i < nRelayNodes; i++) {
|
for (unsigned int i = 0; i < nRelayNodes; i++) {
|
||||||
if (hashKey > best[i].first) {
|
if (hashKey > best[i].first) {
|
||||||
|
@ -2018,7 +2018,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||||
UpdatePreferredDownload(pfrom, State(pfrom->GetId()));
|
UpdatePreferredDownload(pfrom, State(pfrom->GetId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pfrom->fInbound)
|
if (!pfrom->fInbound && pfrom->IsAddrRelayPeer())
|
||||||
{
|
{
|
||||||
// Advertise our address
|
// Advertise our address
|
||||||
if (fListen && !::ChainstateActive().IsInitialBlockDownload())
|
if (fListen && !::ChainstateActive().IsInitialBlockDownload())
|
||||||
|
@ -2134,6 +2134,9 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||||
// Don't want addr from older versions unless seeding
|
// Don't want addr from older versions unless seeding
|
||||||
if (pfrom->nVersion < CADDR_TIME_VERSION && connman->GetAddressCount() > 1000)
|
if (pfrom->nVersion < CADDR_TIME_VERSION && connman->GetAddressCount() > 1000)
|
||||||
return true;
|
return true;
|
||||||
|
if (!pfrom->IsAddrRelayPeer()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (vAddr.size() > 1000)
|
if (vAddr.size() > 1000)
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
@ -2994,6 +2997,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||||
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from outbound connection. peer=%d\n", pfrom->GetId());
|
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from outbound connection. peer=%d\n", pfrom->GetId());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (!pfrom->IsAddrRelayPeer()) {
|
||||||
|
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from block-relay-only connection. peer=%d\n", pfrom->GetId());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Only send one GetAddr response per connection to reduce resource waste
|
// Only send one GetAddr response per connection to reduce resource waste
|
||||||
// and discourage addr stamping of INV announcements.
|
// and discourage addr stamping of INV announcements.
|
||||||
|
@ -3587,7 +3594,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
|
||||||
|
|
||||||
// Address refresh broadcast
|
// Address refresh broadcast
|
||||||
int64_t nNow = GetTimeMicros();
|
int64_t nNow = GetTimeMicros();
|
||||||
if (!::ChainstateActive().IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) {
|
if (pto->IsAddrRelayPeer() && !::ChainstateActive().IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) {
|
||||||
AdvertiseLocal(pto);
|
AdvertiseLocal(pto);
|
||||||
pto->nNextLocalAddrSend = PoissonNextSend(nNow, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
|
pto->nNextLocalAddrSend = PoissonNextSend(nNow, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
|
||||||
}
|
}
|
||||||
|
@ -3595,7 +3602,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
|
||||||
//
|
//
|
||||||
// Message: addr
|
// Message: addr
|
||||||
//
|
//
|
||||||
if (pto->nNextAddrSend < nNow) {
|
if (pto->IsAddrRelayPeer() && pto->nNextAddrSend < nNow) {
|
||||||
pto->nNextAddrSend = PoissonNextSend(nNow, AVG_ADDRESS_BROADCAST_INTERVAL);
|
pto->nNextAddrSend = PoissonNextSend(nNow, AVG_ADDRESS_BROADCAST_INTERVAL);
|
||||||
std::vector<CAddress> vAddr;
|
std::vector<CAddress> vAddr;
|
||||||
vAddr.reserve(pto->vAddrToSend.size());
|
vAddr.reserve(pto->vAddrToSend.size());
|
||||||
|
|
Loading…
Add table
Reference in a new issue