1 // Copyright (c) 2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <test/util/net.h>
6 
7 #include <chainparams.h>
8 #include <net.h>
9 
NodeReceiveMsgBytes(CNode & node,const char * pch,unsigned int nBytes,bool & complete) const10 void ConnmanTestMsg::NodeReceiveMsgBytes(CNode& node, const char* pch, unsigned int nBytes, bool& complete) const
11 {
12     assert(node.ReceiveMsgBytes(pch, nBytes, complete));
13     if (complete) {
14         size_t nSizeAdded = 0;
15         auto it(node.vRecvMsg.begin());
16         for (; it != node.vRecvMsg.end(); ++it) {
17             // vRecvMsg contains only completed CNetMessage
18             // the single possible partially deserialized message are held by TransportDeserializer
19             nSizeAdded += it->m_raw_message_size;
20         }
21         {
22             LOCK(node.cs_vProcessMsg);
23             node.vProcessMsg.splice(node.vProcessMsg.end(), node.vRecvMsg, node.vRecvMsg.begin(), it);
24             node.nProcessQueueSize += nSizeAdded;
25             node.fPauseRecv = node.nProcessQueueSize > nReceiveFloodSize;
26         }
27     }
28 }
29 
ReceiveMsgFrom(CNode & node,CSerializedNetMsg & ser_msg) const30 bool ConnmanTestMsg::ReceiveMsgFrom(CNode& node, CSerializedNetMsg& ser_msg) const
31 {
32     std::vector<unsigned char> ser_msg_header;
33     node.m_serializer->prepareForTransport(ser_msg, ser_msg_header);
34 
35     bool complete;
36     NodeReceiveMsgBytes(node, (const char*)ser_msg_header.data(), ser_msg_header.size(), complete);
37     NodeReceiveMsgBytes(node, (const char*)ser_msg.data.data(), ser_msg.data.size(), complete);
38     return complete;
39 }
40