mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-12 02:07:39 +01:00
9b8dcb25b5
[net processing] Rename PoissonNextSendInbound to NextInvToInbounds (John Newbery)ea99f5d01e
[net processing] Move PoissonNextSendInbound to PeerManager (John Newbery)bb060746df
scripted-diff: replace PoissonNextSend with GetExponentialRand (John Newbery)03cfa1b603
[refactor] Use uint64_t and std namespace in PoissonNextSend (John Newbery)9e64d69bf7
[move] Move PoissonNextSend to src/random and update comment (John Newbery) Pull request description: `PoissonNextSend` and `PoissonNextSendInbound` are used in the p2p code to obfuscate various regularly occurring processes, in order to make it harder for others to get timing-based information deterministically. The naming of these functions has been confusing to several people (including myself, see also #23347) because the resulting random timestamps don't follow a Poisson distribution but an exponential distribution (related to events in a Poisson process, hence the name). This PR - moves `PoissonNextSend()` out of `net` to `random` and renames it to `GetExponentialRand()` - moves `PoissonNextSendInbound()` out of `CConnman` to `PeerManager` and renames it to `NextInvToInbounds()` - adds documentation for these functions This is work by jnewbery - due to him being less active currently, I opened the PR and will address feedback. ACKs for top commit: jnewbery: ACK9b8dcb25b5
hebasto: ACK9b8dcb25b5
, I have reviewed the code and it looks OK, I agree it can be merged. theStack: ACK9b8dcb25b5
📊 Tree-SHA512: 85c366c994e7147f9981fe863fb9838502643fa61ffd32d55a43feef96a38b79a5daa2c4d38ce01074897cc95fa40c76779816edad53f5265b81b05c3a1f4f50
131 lines
5 KiB
C++
131 lines
5 KiB
C++
// Copyright (c) 2020-2021 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <addrman.h>
|
|
#include <chainparams.h>
|
|
#include <chainparamsbase.h>
|
|
#include <net.h>
|
|
#include <netaddress.h>
|
|
#include <protocol.h>
|
|
#include <test/fuzz/FuzzedDataProvider.h>
|
|
#include <test/fuzz/fuzz.h>
|
|
#include <test/fuzz/util.h>
|
|
#include <test/util/setup_common.h>
|
|
#include <util/system.h>
|
|
#include <util/translation.h>
|
|
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
namespace {
|
|
const BasicTestingSetup* g_setup;
|
|
} // namespace
|
|
|
|
void initialize_connman()
|
|
{
|
|
static const auto testing_setup = MakeNoLogFileContext<>();
|
|
g_setup = testing_setup.get();
|
|
}
|
|
|
|
FUZZ_TARGET_INIT(connman, initialize_connman)
|
|
{
|
|
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
|
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
|
AddrMan addrman(/*asmap=*/std::vector<bool>(),
|
|
/*deterministic=*/false,
|
|
g_setup->m_node.args->GetIntArg("-checkaddrman", 0));
|
|
CConnman connman{fuzzed_data_provider.ConsumeIntegral<uint64_t>(), fuzzed_data_provider.ConsumeIntegral<uint64_t>(), addrman, fuzzed_data_provider.ConsumeBool()};
|
|
CNetAddr random_netaddr;
|
|
CNode random_node = ConsumeNode(fuzzed_data_provider);
|
|
CSubNet random_subnet;
|
|
std::string random_string;
|
|
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
|
|
CallOneOf(
|
|
fuzzed_data_provider,
|
|
[&] {
|
|
random_netaddr = ConsumeNetAddr(fuzzed_data_provider);
|
|
},
|
|
[&] {
|
|
random_subnet = ConsumeSubNet(fuzzed_data_provider);
|
|
},
|
|
[&] {
|
|
random_string = fuzzed_data_provider.ConsumeRandomLengthString(64);
|
|
},
|
|
[&] {
|
|
connman.AddNode(random_string);
|
|
},
|
|
[&] {
|
|
connman.CheckIncomingNonce(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
|
|
},
|
|
[&] {
|
|
connman.DisconnectNode(fuzzed_data_provider.ConsumeIntegral<NodeId>());
|
|
},
|
|
[&] {
|
|
connman.DisconnectNode(random_netaddr);
|
|
},
|
|
[&] {
|
|
connman.DisconnectNode(random_string);
|
|
},
|
|
[&] {
|
|
connman.DisconnectNode(random_subnet);
|
|
},
|
|
[&] {
|
|
connman.ForEachNode([](auto) {});
|
|
},
|
|
[&] {
|
|
(void)connman.ForNode(fuzzed_data_provider.ConsumeIntegral<NodeId>(), [&](auto) { return fuzzed_data_provider.ConsumeBool(); });
|
|
},
|
|
[&] {
|
|
(void)connman.GetAddresses(
|
|
/*max_addresses=*/fuzzed_data_provider.ConsumeIntegral<size_t>(),
|
|
/*max_pct=*/fuzzed_data_provider.ConsumeIntegral<size_t>(),
|
|
/*network=*/std::nullopt);
|
|
},
|
|
[&] {
|
|
(void)connman.GetAddresses(
|
|
/*requestor=*/random_node,
|
|
/*max_addresses=*/fuzzed_data_provider.ConsumeIntegral<size_t>(),
|
|
/*max_pct=*/fuzzed_data_provider.ConsumeIntegral<size_t>());
|
|
},
|
|
[&] {
|
|
(void)connman.GetDeterministicRandomizer(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
|
|
},
|
|
[&] {
|
|
(void)connman.GetNodeCount(fuzzed_data_provider.PickValueInArray({ConnectionDirection::None, ConnectionDirection::In, ConnectionDirection::Out, ConnectionDirection::Both}));
|
|
},
|
|
[&] {
|
|
(void)connman.OutboundTargetReached(fuzzed_data_provider.ConsumeBool());
|
|
},
|
|
[&] {
|
|
CSerializedNetMsg serialized_net_msg;
|
|
serialized_net_msg.m_type = fuzzed_data_provider.ConsumeRandomLengthString(CMessageHeader::COMMAND_SIZE);
|
|
serialized_net_msg.data = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
|
connman.PushMessage(&random_node, std::move(serialized_net_msg));
|
|
},
|
|
[&] {
|
|
connman.RemoveAddedNode(random_string);
|
|
},
|
|
[&] {
|
|
connman.SetNetworkActive(fuzzed_data_provider.ConsumeBool());
|
|
},
|
|
[&] {
|
|
connman.SetTryNewOutboundPeer(fuzzed_data_provider.ConsumeBool());
|
|
});
|
|
}
|
|
(void)connman.GetAddedNodeInfo();
|
|
(void)connman.GetExtraFullOutboundCount();
|
|
(void)connman.GetLocalServices();
|
|
(void)connman.GetMaxOutboundTarget();
|
|
(void)connman.GetMaxOutboundTimeframe();
|
|
(void)connman.GetMaxOutboundTimeLeftInCycle();
|
|
(void)connman.GetNetworkActive();
|
|
std::vector<CNodeStats> stats;
|
|
connman.GetNodeStats(stats);
|
|
(void)connman.GetOutboundTargetBytesLeft();
|
|
(void)connman.GetReceiveFloodSize();
|
|
(void)connman.GetTotalBytesRecv();
|
|
(void)connman.GetTotalBytesSent();
|
|
(void)connman.GetTryNewOutboundPeer();
|
|
(void)connman.GetUseAddrmanOutgoing();
|
|
}
|