MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / PushMessage

Method PushMessage

src/net.cpp:2819–2854  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2817}
2818
2819void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
2820{
2821 size_t nMessageSize = msg.data.size();
2822 size_t nTotalSize = nMessageSize + CMessageHeader::HEADER_SIZE;
2823 LogPrint(BCLog::NET, "sending %s (%d bytes) peer=%d\n", SanitizeString(msg.command.c_str()), nMessageSize, pnode->GetId());
2824
2825 std::vector<unsigned char> serializedHeader;
2826 serializedHeader.reserve(CMessageHeader::HEADER_SIZE);
2827 uint256 hash = Hash(msg.data.data(), msg.data.data() + nMessageSize);
2828 CMessageHeader hdr(Params().MessageStart(), msg.command.c_str(), nMessageSize);
2829 memcpy(hdr.pchChecksum, hash.begin(), CMessageHeader::CHECKSUM_SIZE);
2830
2831 CVectorWriter{SER_NETWORK, INIT_PROTO_VERSION, serializedHeader, 0, hdr};
2832
2833 size_t nBytesSent = 0;
2834 {
2835 LOCK(pnode->cs_vSend);
2836 bool optimisticSend(pnode->vSendMsg.empty());
2837
2838 //log total amount of bytes per command
2839 pnode->mapSendBytesPerMsgCmd[msg.command] += nTotalSize;
2840 pnode->nSendSize += nTotalSize;
2841
2842 if (pnode->nSendSize > nSendBufferMaxSize)
2843 pnode->fPauseSend = true;
2844 pnode->vSendMsg.push_back(std::move(serializedHeader));
2845 if (nMessageSize)
2846 pnode->vSendMsg.push_back(std::move(msg.data));
2847
2848 // If write queue empty, attempt "optimistic write"
2849 if (optimisticSend == true)
2850 nBytesSent = SocketSendData(pnode);
2851 }
2852 if (nBytesSent)
2853 RecordBytesSent(nBytesSent);
2854}
2855
2856bool CConnman::ForNode(NodeId id, std::function<bool(CNode* pnode)> func)
2857{

Callers 12

PushNodeVersionFunction · 0.80
NewPoWValidBlockMethod · 0.80
ProcessGetBlockDataFunction · 0.80
ProcessGetDataFunction · 0.80
SendBlockTransactionsFunction · 0.80
ProcessHeadersMessageFunction · 0.80
ProcessMessageFunction · 0.80
ProcessMessagesMethod · 0.80
ConsiderEvictionMethod · 0.80
SendMessagesMethod · 0.80

Calls 11

SanitizeStringFunction · 0.85
memcpyFunction · 0.85
GetIdMethod · 0.80
HashFunction · 0.70
ParamsClass · 0.70
sizeMethod · 0.45
reserveMethod · 0.45
dataMethod · 0.45
beginMethod · 0.45
emptyMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected