| 739 | #undef X |
| 740 | |
| 741 | bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete) |
| 742 | { |
| 743 | complete = false; |
| 744 | int64_t nTimeMicros = GetTimeMicros(); |
| 745 | LOCK(cs_vRecv); |
| 746 | nLastRecv = nTimeMicros / 1000000; |
| 747 | nRecvBytes += nBytes; |
| 748 | while (nBytes > 0) { |
| 749 | |
| 750 | // get current incomplete message, or create a new one |
| 751 | if (vRecvMsg.empty() || |
| 752 | vRecvMsg.back().complete()) |
| 753 | vRecvMsg.push_back(CNetMessage(Params().MessageStart(), SER_NETWORK, INIT_PROTO_VERSION)); |
| 754 | |
| 755 | CNetMessage& msg = vRecvMsg.back(); |
| 756 | |
| 757 | // absorb network data |
| 758 | int handled; |
| 759 | if (!msg.in_data) |
| 760 | handled = msg.readHeader(pch, nBytes); |
| 761 | else |
| 762 | handled = msg.readData(pch, nBytes); |
| 763 | |
| 764 | if (handled < 0) |
| 765 | return false; |
| 766 | |
| 767 | if (msg.in_data && msg.hdr.nMessageSize > MAX_PROTOCOL_MESSAGE_LENGTH) { |
| 768 | LogPrint(BCLog::NET, "Oversized message from peer=%i, disconnecting\n", GetId()); |
| 769 | return false; |
| 770 | } |
| 771 | |
| 772 | pch += handled; |
| 773 | nBytes -= handled; |
| 774 | |
| 775 | if (msg.complete()) { |
| 776 | |
| 777 | //store received bytes per message command |
| 778 | //to prevent a memory DOS, only allow valid commands |
| 779 | mapMsgCmdSize::iterator i = mapRecvBytesPerMsgCmd.find(msg.hdr.pchCommand); |
| 780 | if (i == mapRecvBytesPerMsgCmd.end()) |
| 781 | i = mapRecvBytesPerMsgCmd.find(NET_MESSAGE_COMMAND_OTHER); |
| 782 | assert(i != mapRecvBytesPerMsgCmd.end()); |
| 783 | i->second += msg.hdr.nMessageSize + CMessageHeader::HEADER_SIZE; |
| 784 | |
| 785 | msg.nTime = nTimeMicros; |
| 786 | complete = true; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | return true; |
| 791 | } |
| 792 | |
| 793 | void CNode::SetSendVersion(int nVersionIn) |
| 794 | { |
no test coverage detected