Line data Source code
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 : 10 0 : void ConnmanTestMsg::NodeReceiveMsgBytes(CNode& node, const char* pch, unsigned int nBytes, bool& complete) const 11 : { 12 0 : assert(node.ReceiveMsgBytes(pch, nBytes, complete)); 13 0 : if (complete) { 14 : size_t nSizeAdded = 0; 15 0 : auto it(node.vRecvMsg.begin()); 16 0 : for (; it != node.vRecvMsg.end(); ++it) { 17 : // vRecvMsg contains only completed CNetMessage 18 : // the single possible partially deserialized message are held by TransportDeserializer 19 0 : nSizeAdded += it->m_raw_message_size; 20 : } 21 : { 22 0 : LOCK(node.cs_vProcessMsg); 23 0 : node.vProcessMsg.splice(node.vProcessMsg.end(), node.vRecvMsg, node.vRecvMsg.begin(), it); 24 0 : node.nProcessQueueSize += nSizeAdded; 25 0 : node.fPauseRecv = node.nProcessQueueSize > nReceiveFloodSize; 26 0 : } 27 0 : } 28 0 : } 29 : 30 0 : bool ConnmanTestMsg::ReceiveMsgFrom(CNode& node, CSerializedNetMsg& ser_msg) const 31 : { 32 0 : std::vector<unsigned char> ser_msg_header; 33 0 : node.m_serializer->prepareForTransport(ser_msg, ser_msg_header); 34 : 35 0 : bool complete; 36 0 : NodeReceiveMsgBytes(node, (const char*)ser_msg_header.data(), ser_msg_header.size(), complete); 37 0 : NodeReceiveMsgBytes(node, (const char*)ser_msg.data.data(), ser_msg.data.size(), complete); 38 0 : return complete; 39 0 : }