MCPcopy Create free account
hub / github.com/ElementsProject/elements / PushMessage

Method PushMessage

src/net.cpp:3064–3103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3062}
3063
3064void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
3065{
3066 size_t nMessageSize = msg.data.size();
3067 LogPrint(BCLog::NET, "sending %s (%d bytes) peer=%d\n", msg.m_type, nMessageSize, pnode->GetId());
3068 if (gArgs.GetBoolArg("-capturemessages", false)) {
3069 CaptureMessage(pnode->addr, msg.m_type, msg.data, /*is_incoming=*/false);
3070 }
3071
3072 TRACE6(net, outbound_message,
3073 pnode->GetId(),
3074 pnode->m_addr_name.c_str(),
3075 pnode->ConnectionTypeAsString().c_str(),
3076 msg.m_type.c_str(),
3077 msg.data.size(),
3078 msg.data.data()
3079 );
3080
3081 // make sure we use the appropriate network transport format
3082 std::vector<unsigned char> serializedHeader;
3083 pnode->m_serializer->prepareForTransport(msg, serializedHeader);
3084 size_t nTotalSize = nMessageSize + serializedHeader.size();
3085
3086 size_t nBytesSent = 0;
3087 {
3088 LOCK(pnode->cs_vSend);
3089 bool optimisticSend(pnode->vSendMsg.empty());
3090
3091 //log total amount of bytes per message type
3092 pnode->mapSendBytesPerMsgCmd[msg.m_type] += nTotalSize;
3093 pnode->nSendSize += nTotalSize;
3094
3095 if (pnode->nSendSize > nSendBufferMaxSize) pnode->fPauseSend = true;
3096 pnode->vSendMsg.push_back(std::move(serializedHeader));
3097 if (nMessageSize) pnode->vSendMsg.push_back(std::move(msg.data));
3098
3099 // If write queue empty, attempt "optimistic write"
3100 if (optimisticSend) nBytesSent = SocketSendData(*pnode);
3101 }
3102 if (nBytesSent) RecordBytesSent(nBytesSent);
3103}
3104
3105bool CConnman::ForNode(NodeId id, std::function<bool(CNode* pnode)> func)
3106{

Callers 15

PushNodeVersionMethod · 0.80
FetchBlockMethod · 0.80
NewPoWValidBlockMethod · 0.80
ProcessGetBlockDataMethod · 0.80
ProcessGetDataMethod · 0.80
SendBlockTransactionsMethod · 0.80
ProcessHeadersMessageMethod · 0.80
ProcessGetCFiltersMethod · 0.80
ProcessGetCFHeadersMethod · 0.80
ProcessGetCFCheckPtMethod · 0.80
ProcessMessageMethod · 0.80

Calls 8

GetIdMethod · 0.80
GetBoolArgMethod · 0.80
prepareForTransportMethod · 0.80
sizeMethod · 0.45
dataMethod · 0.45
emptyMethod · 0.45
push_backMethod · 0.45

Tested by 1

FUZZ_TARGET_INITFunction · 0.64