| 3062 | } |
| 3063 | |
| 3064 | void 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 | |
| 3105 | bool CConnman::ForNode(NodeId id, std::function<bool(CNode* pnode)> func) |
| 3106 | { |