Skip to content

Commit fa47a0b

Browse files
author
MarcoFalke
committed
net: Make addr relay mockable
1 parent 210b533 commit fa47a0b

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/net.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,8 @@ class CNode
797797
std::vector<CAddress> vAddrToSend;
798798
const std::unique_ptr<CRollingBloomFilter> m_addr_known;
799799
bool fGetAddr{false};
800-
int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing){0};
801-
int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing){0};
800+
std::chrono::microseconds m_next_addr_send GUARDED_BY(cs_sendProcessing){0};
801+
std::chrono::microseconds m_next_local_addr_send GUARDED_BY(cs_sendProcessing){0};
802802

803803
bool IsAddrRelayPeer() const { return m_addr_known != nullptr; }
804804

src/net_processing.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ void EraseOrphansFor(NodeId peer);
9797
/** Increase a node's misbehavior score. */
9898
void Misbehaving(NodeId nodeid, int howmuch, const std::string& message="") EXCLUSIVE_LOCKS_REQUIRED(cs_main);
9999

100-
/** Average delay between local address broadcasts in seconds. */
101-
static constexpr unsigned int AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL = 24 * 60 * 60;
102-
/** Average delay between peer address broadcasts in seconds. */
103-
static const unsigned int AVG_ADDRESS_BROADCAST_INTERVAL = 30;
100+
/** Average delay between local address broadcasts */
101+
static constexpr std::chrono::hours AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL{24};
102+
/** Average delay between peer address broadcasts */
103+
static constexpr std::chrono::seconds AVG_ADDRESS_BROADCAST_INTERVAL{30};
104104
/** Average delay between trickled inventory transmissions in seconds.
105105
* Blocks and whitelisted receivers bypass this, outbound peers get half this delay. */
106106
static const unsigned int INVENTORY_BROADCAST_INTERVAL = 5;
@@ -3583,16 +3583,16 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
35833583
int64_t nNow = GetTimeMicros();
35843584
auto current_time = GetTime<std::chrono::microseconds>();
35853585

3586-
if (pto->IsAddrRelayPeer() && !::ChainstateActive().IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) {
3586+
if (pto->IsAddrRelayPeer() && !::ChainstateActive().IsInitialBlockDownload() && pto->m_next_local_addr_send < current_time) {
35873587
AdvertiseLocal(pto);
3588-
pto->nNextLocalAddrSend = PoissonNextSend(nNow, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
3588+
pto->m_next_local_addr_send = PoissonNextSend(current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
35893589
}
35903590

35913591
//
35923592
// Message: addr
35933593
//
3594-
if (pto->IsAddrRelayPeer() && pto->nNextAddrSend < nNow) {
3595-
pto->nNextAddrSend = PoissonNextSend(nNow, AVG_ADDRESS_BROADCAST_INTERVAL);
3594+
if (pto->IsAddrRelayPeer() && pto->m_next_addr_send < current_time) {
3595+
pto->m_next_addr_send = PoissonNextSend(current_time, AVG_ADDRESS_BROADCAST_INTERVAL);
35963596
std::vector<CAddress> vAddr;
35973597
vAddr.reserve(pto->vAddrToSend.size());
35983598
assert(pto->m_addr_known);

0 commit comments

Comments
 (0)