aboutsummaryrefslogtreecommitdiff
path: root/src/net.h
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2019-11-05 12:38:17 -0500
committerMarcoFalke <falke.marco@gmail.com>2019-11-05 12:38:28 -0500
commitc7e6b3b343e836ff41e9a8872187e0b24f13064d (patch)
tree3297e5346ff7da74fa9a69df54b8f01f51bd65d4 /src/net.h
parent54a337478dfbfede7c8335f6c7ab134817b73dcd (diff)
parent1a8f0d5a74d5cc0000456932babf35301f5c1686 (diff)
downloadbitcoin-c7e6b3b343e836ff41e9a8872187e0b24f13064d.tar.xz
Merge #17243: p2p: add PoissonNextSend method that returns mockable time
1a8f0d5a74d5cc0000456932babf35301f5c1686 [tools] update nNextInvSend to use mockable time (Amiti Uttarwar) 4de630354fc6808b9b13b9e82da1a82f2f50f26a [tools] add PoissonNextSend method that returns mockable time (Amiti Uttarwar) Pull request description: Introduce a Poisson helper method that wraps the existing method to return `std::chrono::duration` type, which is mockable. Needed for https://github.com/bitcoin/bitcoin/pull/16698. ACKs for top commit: ajtowns: ACK 1a8f0d5a74d5cc0000456932babf35301f5c1686 MarcoFalke: re-ACK 1a8f0d5a74d5cc0000456932babf35301f5c1686 naumenkogs: ACK 1a8f0d5, and let's merge it and come back to it later. Tree-SHA512: 7e2325d7c55fc0b4357cb86b83e0c218ba269f678c1786342d8bc380bfd9696373bc24ff124b9ff17a6e761c62b2b44ff5247c3911e2afdc7cc5c20417e8290b
Diffstat (limited to 'src/net.h')
-rw-r--r--src/net.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/net.h b/src/net.h
index 1e5f1c3f09..9cd3b769ec 100644
--- a/src/net.h
+++ b/src/net.h
@@ -808,7 +808,7 @@ public:
bool fSendMempool GUARDED_BY(cs_tx_inventory){false};
// Last time a "MEMPOOL" request was serviced.
std::atomic<std::chrono::seconds> m_last_mempool_req{std::chrono::seconds{0}};
- int64_t nNextInvSend{0};
+ std::chrono::microseconds nNextInvSend{0};
CCriticalSection cs_feeFilter;
// Minimum fee rate with which to filter inv's to this node
@@ -991,11 +991,13 @@ public:
void MaybeSetAddrName(const std::string& addrNameIn);
};
-
-
-
-
/** Return a timestamp in the future (in microseconds) for exponentially distributed events. */
int64_t PoissonNextSend(int64_t now, int average_interval_seconds);
+/** Wrapper to return mockable type */
+inline std::chrono::microseconds PoissonNextSend(std::chrono::microseconds now, std::chrono::seconds average_interval)
+{
+ return std::chrono::microseconds{PoissonNextSend(now.count(), average_interval.count())};
+}
+
#endif // BITCOIN_NET_H