[net processing] Move PoissonNextSendInbound to PeerManager
This commit is contained in:
1 parent
bb060746df
commit
ea99f5d01e
4 files changed
+24
-26
No files matched your search
-11
@@ -3058,17 +3058,6 @@ bool CConnman::ForNode(NodeId id, std::function<bool(CNode* pnode)> func)
|
|||||||
return found != nullptr && NodeFullyConnected(found) && func(found);
|
return found != nullptr && NodeFullyConnected(found) && func(found);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::chrono::microseconds CConnman::PoissonNextSendInbound(std::chrono::microseconds now, std::chrono::seconds average_interval)
|
|
||||||
{
|
|
||||||
if (m_next_send_inv_to_incoming.load() < 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 = GetExponentialRand(now, average_interval);
|
|
||||||
}
|
|
||||||
return m_next_send_inv_to_incoming;
|
|
||||||
}
|
|
||||||
|
|
||||||
CSipHasher CConnman::GetDeterministicRandomizer(uint64_t id) const
|
CSipHasher CConnman::GetDeterministicRandomizer(uint64_t id) const
|
||||||
{
|
{
|
||||||
return CSipHasher(nSeed0, nSeed1).Write(id);
|
return CSipHasher(nSeed0, nSeed1).Write(id);
|
||||||
|
|||||||
@@ -936,12 +936,6 @@ public:
|
|||||||
|
|
||||||
void WakeMessageHandler();
|
void WakeMessageHandler();
|
||||||
|
|
||||||
/** Attempts to obfuscate tx time through exponentially distributed emitting.
|
|
||||||
Works assuming that a single interval is used.
|
|
||||||
Variable intervals will result in privacy decrease.
|
|
||||||
*/
|
|
||||||
std::chrono::microseconds PoissonNextSendInbound(std::chrono::microseconds now, std::chrono::seconds average_interval);
|
|
||||||
|
|
||||||
/** Return true if we should disconnect the peer for failing an inactivity check. */
|
/** Return true if we should disconnect the peer for failing an inactivity check. */
|
||||||
bool ShouldRunInactivityChecks(const CNode& node, std::chrono::seconds now) const;
|
bool ShouldRunInactivityChecks(const CNode& node, std::chrono::seconds now) const;
|
||||||
|
|
||||||
@@ -1221,8 +1215,6 @@ private:
|
|||||||
*/
|
*/
|
||||||
std::atomic_bool m_start_extra_block_relay_peers{false};
|
std::atomic_bool m_start_extra_block_relay_peers{false};
|
||||||
|
|
||||||
std::atomic<std::chrono::microseconds> m_next_send_inv_to_incoming{0us};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A vector of -bind=<address>:<port>=onion arguments each of which is
|
* A vector of -bind=<address>:<port>=onion arguments each of which is
|
||||||
* an address and port that are designated for incoming Tor connections.
|
* an address and port that are designated for incoming Tor connections.
|
||||||
|
|||||||
+24
-1
@@ -444,6 +444,8 @@ private:
|
|||||||
*/
|
*/
|
||||||
std::map<NodeId, PeerRef> m_peer_map GUARDED_BY(m_peer_mutex);
|
std::map<NodeId, PeerRef> m_peer_map GUARDED_BY(m_peer_mutex);
|
||||||
|
|
||||||
|
std::atomic<std::chrono::microseconds> m_next_send_inv_to_incoming{0us};
|
||||||
|
|
||||||
/** Number of nodes with fSyncStarted. */
|
/** Number of nodes with fSyncStarted. */
|
||||||
int nSyncStarted GUARDED_BY(cs_main) = 0;
|
int nSyncStarted GUARDED_BY(cs_main) = 0;
|
||||||
|
|
||||||
@@ -518,6 +520,15 @@ private:
|
|||||||
Mutex m_recent_confirmed_transactions_mutex;
|
Mutex m_recent_confirmed_transactions_mutex;
|
||||||
CRollingBloomFilter m_recent_confirmed_transactions GUARDED_BY(m_recent_confirmed_transactions_mutex){48'000, 0.000'001};
|
CRollingBloomFilter m_recent_confirmed_transactions GUARDED_BY(m_recent_confirmed_transactions_mutex){48'000, 0.000'001};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For sending `inv`s to inbound peers, we use a single (exponentially
|
||||||
|
* distributed) timer for all peers. If we used a separate timer for each
|
||||||
|
* peer, a spy node could make multiple inbound connections to us to
|
||||||
|
* accurately determine when we received the transaction (and potentially
|
||||||
|
* determine the transaction's origin). */
|
||||||
|
std::chrono::microseconds PoissonNextSendInbound(std::chrono::microseconds now,
|
||||||
|
std::chrono::seconds average_interval);
|
||||||
|
|
||||||
/** Have we requested this block from a peer */
|
/** Have we requested this block from a peer */
|
||||||
bool IsBlockRequested(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
bool IsBlockRequested(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
@@ -819,6 +830,18 @@ static void UpdatePreferredDownload(const CNode& node, CNodeState* state) EXCLUS
|
|||||||
nPreferredDownload += state->fPreferredDownload;
|
nPreferredDownload += state->fPreferredDownload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::chrono::microseconds PeerManagerImpl::PoissonNextSendInbound(std::chrono::microseconds now,
|
||||||
|
std::chrono::seconds average_interval)
|
||||||
|
{
|
||||||
|
if (m_next_send_inv_to_incoming.load() < 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 = GetExponentialRand(now, average_interval);
|
||||||
|
}
|
||||||
|
return m_next_send_inv_to_incoming;
|
||||||
|
}
|
||||||
|
|
||||||
bool PeerManagerImpl::IsBlockRequested(const uint256& hash)
|
bool PeerManagerImpl::IsBlockRequested(const uint256& hash)
|
||||||
{
|
{
|
||||||
return mapBlocksInFlight.find(hash) != mapBlocksInFlight.end();
|
return mapBlocksInFlight.find(hash) != mapBlocksInFlight.end();
|
||||||
@@ -4786,7 +4809,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
|
|||||||
if (pto->m_tx_relay->nNextInvSend < current_time) {
|
if (pto->m_tx_relay->nNextInvSend < current_time) {
|
||||||
fSendTrickle = true;
|
fSendTrickle = true;
|
||||||
if (pto->IsInboundConn()) {
|
if (pto->IsInboundConn()) {
|
||||||
pto->m_tx_relay->nNextInvSend = m_connman.PoissonNextSendInbound(current_time, INBOUND_INVENTORY_BROADCAST_INTERVAL);
|
pto->m_tx_relay->nNextInvSend = PoissonNextSendInbound(current_time, INBOUND_INVENTORY_BROADCAST_INTERVAL);
|
||||||
} else {
|
} else {
|
||||||
pto->m_tx_relay->nNextInvSend = GetExponentialRand(current_time, OUTBOUND_INVENTORY_BROADCAST_INTERVAL);
|
pto->m_tx_relay->nNextInvSend = GetExponentialRand(current_time, OUTBOUND_INVENTORY_BROADCAST_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,12 +89,6 @@ FUZZ_TARGET_INIT(connman, initialize_connman)
|
|||||||
[&] {
|
[&] {
|
||||||
(void)connman.OutboundTargetReached(fuzzed_data_provider.ConsumeBool());
|
(void)connman.OutboundTargetReached(fuzzed_data_provider.ConsumeBool());
|
||||||
},
|
},
|
||||||
[&] {
|
|
||||||
// Limit now to int32_t to avoid signed integer overflow
|
|
||||||
(void)connman.PoissonNextSendInbound(
|
|
||||||
std::chrono::microseconds{fuzzed_data_provider.ConsumeIntegral<int32_t>()},
|
|
||||||
std::chrono::seconds{fuzzed_data_provider.ConsumeIntegral<int>()});
|
|
||||||
},
|
|
||||||
[&] {
|
[&] {
|
||||||
CSerializedNetMsg serialized_net_msg;
|
CSerializedNetMsg serialized_net_msg;
|
||||||
serialized_net_msg.m_type = fuzzed_data_provider.ConsumeRandomLengthString(CMessageHeader::COMMAND_SIZE);
|
serialized_net_msg.m_type = fuzzed_data_provider.ConsumeRandomLengthString(CMessageHeader::COMMAND_SIZE);
|
||||||
|
|||||||
Reference in new issue
Block a user