2021-12-30 19:36:57 +02:00
|
|
|
// Copyright (c) 2020-2021 The Bitcoin Core developers
|
2020-04-04 07:30:51 +08:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <test/util/net.h>
|
|
|
|
|
|
|
|
#include <chainparams.h>
|
|
|
|
#include <net.h>
|
2021-07-01 12:48:51 +02:00
|
|
|
#include <span.h>
|
|
|
|
|
|
|
|
#include <vector>
|
2020-04-04 07:30:51 +08:00
|
|
|
|
2020-11-20 10:16:10 +01:00
|
|
|
void ConnmanTestMsg::NodeReceiveMsgBytes(CNode& node, Span<const uint8_t> msg_bytes, bool& complete) const
|
2020-04-04 07:30:51 +08:00
|
|
|
{
|
2020-09-30 17:08:26 +02:00
|
|
|
assert(node.ReceiveMsgBytes(msg_bytes, complete));
|
2020-04-04 07:30:51 +08:00
|
|
|
if (complete) {
|
|
|
|
size_t nSizeAdded = 0;
|
|
|
|
auto it(node.vRecvMsg.begin());
|
|
|
|
for (; it != node.vRecvMsg.end(); ++it) {
|
|
|
|
// vRecvMsg contains only completed CNetMessage
|
|
|
|
// the single possible partially deserialized message are held by TransportDeserializer
|
|
|
|
nSizeAdded += it->m_raw_message_size;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
LOCK(node.cs_vProcessMsg);
|
|
|
|
node.vProcessMsg.splice(node.vProcessMsg.end(), node.vRecvMsg, node.vRecvMsg.begin(), it);
|
|
|
|
node.nProcessQueueSize += nSizeAdded;
|
|
|
|
node.fPauseRecv = node.nProcessQueueSize > nReceiveFloodSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConnmanTestMsg::ReceiveMsgFrom(CNode& node, CSerializedNetMsg& ser_msg) const
|
|
|
|
{
|
2020-11-20 10:16:10 +01:00
|
|
|
std::vector<uint8_t> ser_msg_header;
|
2020-04-04 07:30:51 +08:00
|
|
|
node.m_serializer->prepareForTransport(ser_msg, ser_msg_header);
|
|
|
|
|
|
|
|
bool complete;
|
2020-11-20 10:16:10 +01:00
|
|
|
NodeReceiveMsgBytes(node, ser_msg_header, complete);
|
|
|
|
NodeReceiveMsgBytes(node, ser_msg.data, complete);
|
2020-04-04 07:30:51 +08:00
|
|
|
return complete;
|
|
|
|
}
|
2021-07-01 12:48:51 +02:00
|
|
|
|
|
|
|
std::vector<NodeEvictionCandidate> GetRandomNodeEvictionCandidates(int n_candidates, FastRandomContext& random_context)
|
|
|
|
{
|
|
|
|
std::vector<NodeEvictionCandidate> candidates;
|
|
|
|
for (int id = 0; id < n_candidates; ++id) {
|
|
|
|
candidates.push_back({
|
2021-09-14 16:56:34 +02:00
|
|
|
/*id=*/id,
|
2021-12-13 12:32:28 +01:00
|
|
|
/*m_connected=*/std::chrono::seconds{random_context.randrange(100)},
|
2021-09-14 16:56:34 +02:00
|
|
|
/*m_min_ping_time=*/std::chrono::microseconds{random_context.randrange(100)},
|
2021-12-13 12:32:28 +01:00
|
|
|
/*m_last_block_time=*/std::chrono::seconds{random_context.randrange(100)},
|
|
|
|
/*m_last_tx_time=*/std::chrono::seconds{random_context.randrange(100)},
|
2021-09-14 16:56:34 +02:00
|
|
|
/*fRelevantServices=*/random_context.randbool(),
|
2020-06-16 16:27:34 -04:00
|
|
|
/*m_relay_txs=*/random_context.randbool(),
|
2021-09-14 16:56:34 +02:00
|
|
|
/*fBloomFilter=*/random_context.randbool(),
|
|
|
|
/*nKeyedNetGroup=*/random_context.randrange(100),
|
|
|
|
/*prefer_evict=*/random_context.randbool(),
|
|
|
|
/*m_is_local=*/random_context.randbool(),
|
|
|
|
/*m_network=*/ALL_NETWORKS[random_context.randrange(ALL_NETWORKS.size())],
|
2022-05-26 15:40:21 +02:00
|
|
|
/*m_noban=*/false,
|
2022-05-26 15:49:10 +02:00
|
|
|
/*m_conn_type=*/ConnectionType::INBOUND,
|
2021-07-01 12:48:51 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return candidates;
|
|
|
|
}
|