aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorGleb <naumenko.gs@gmail.com>2018-05-21 12:02:40 -0700
committerUser <naumenko.gs@gmail.com>2018-07-13 23:14:35 -0700
commitd45b344ffd46b0226449cbd46cdaff9577402cf0 (patch)
tree0b23b028d113acce4c57faf3d8f931deba5436d9 /src/net.cpp
parent287e4edc2fd2514a0095273f01fe66b85ce10856 (diff)
downloadbitcoin-d45b344ffd46b0226449cbd46cdaff9577402cf0.tar.xz
Bucket for inbound when scheduling invs to hide tx time
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 55043ffe30..12bdcb465a 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -2864,8 +2864,20 @@ bool CConnman::ForNode(NodeId id, std::function<bool(CNode* pnode)> func)
return found != nullptr && NodeFullyConnected(found) && func(found);
}
-int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds) {
- return nNow + (int64_t)(log1p(GetRand(1ULL << 48) * -0.0000000000000035527136788 /* -1/2^48 */) * average_interval_seconds * -1000000.0 + 0.5);
+int64_t CConnman::PoissonNextSendInbound(int64_t now, int average_interval_seconds)
+{
+ if (m_next_send_inv_to_incoming < now) {
+ // If this function were called from multiple threads simultaneously
+ // it would possible that both update the next send variable, and return a different result to their caller.
+ // This is not possible in practice as only the net processing thread invokes this function.
+ m_next_send_inv_to_incoming = PoissonNextSend(now, average_interval_seconds);
+ }
+ return m_next_send_inv_to_incoming;
+}
+
+int64_t PoissonNextSend(int64_t now, int average_interval_seconds)
+{
+ return now + (int64_t)(log1p(GetRand(1ULL << 48) * -0.0000000000000035527136788 /* -1/2^48 */) * average_interval_seconds * -1000000.0 + 0.5);
}
CSipHasher CConnman::GetDeterministicRandomizer(uint64_t id) const