mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
Merge bitcoin/bitcoin#24078: net, refactor: Rename CNetMessage::m_command with CNetMessage::m_type
224d87855e
net, refactor: Drop tautological local variables (Hennadii Stepanov)3073a9917b
scripted-diff: Rename CNetMessage::m_command with CNetMessage::m_type (Hennadii Stepanov) Pull request description: https://github.com/bitcoin/bitcoin/pull/18533#issue-594592488: > a message is not a command, but simply a message of some type Continuation of bitcoin/bitcoin#18533 and bitcoin/bitcoin#18937. ACKs for top commit: theStack: Concept and code-review ACK224d87855e
shaavan: Code Review ACK224d87855e
w0xlt: crACK224d878
Tree-SHA512: 898cafb44708dae1413fcc1533d809d75878891354f1b5edaaec1287f4921c31adc9330f4d42d82544a39689886bc17fee71ea587f9199fd5cc849d376f82176
This commit is contained in:
commit
973c390298
4 changed files with 12 additions and 16 deletions
|
@ -657,7 +657,7 @@ bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
|
|||
|
||||
// Store received bytes per message command
|
||||
// to prevent a memory DOS, only allow valid commands
|
||||
auto i = mapRecvBytesPerMsgCmd.find(msg.m_command);
|
||||
auto i = mapRecvBytesPerMsgCmd.find(msg.m_type);
|
||||
if (i == mapRecvBytesPerMsgCmd.end()) {
|
||||
i = mapRecvBytesPerMsgCmd.find(NET_MESSAGE_COMMAND_OTHER);
|
||||
}
|
||||
|
@ -747,7 +747,7 @@ CNetMessage V1TransportDeserializer::GetMessage(const std::chrono::microseconds
|
|||
CNetMessage msg(std::move(vRecv));
|
||||
|
||||
// store command string, time, and sizes
|
||||
msg.m_command = hdr.GetCommand();
|
||||
msg.m_type = hdr.GetCommand();
|
||||
msg.m_time = time;
|
||||
msg.m_message_size = hdr.nMessageSize;
|
||||
msg.m_raw_message_size = hdr.nMessageSize + CMessageHeader::HEADER_SIZE;
|
||||
|
@ -760,7 +760,7 @@ CNetMessage V1TransportDeserializer::GetMessage(const std::chrono::microseconds
|
|||
// Check checksum and header command string
|
||||
if (memcmp(hash.begin(), hdr.pchChecksum, CMessageHeader::CHECKSUM_SIZE) != 0) {
|
||||
LogPrint(BCLog::NET, "Header error: Wrong checksum (%s, %u bytes), expected %s was %s, peer=%d\n",
|
||||
SanitizeString(msg.m_command), msg.m_message_size,
|
||||
SanitizeString(msg.m_type), msg.m_message_size,
|
||||
HexStr(Span{hash}.first(CMessageHeader::CHECKSUM_SIZE)),
|
||||
HexStr(hdr.pchChecksum),
|
||||
m_node_id);
|
||||
|
|
|
@ -278,7 +278,7 @@ public:
|
|||
|
||||
/** Transport protocol agnostic message container.
|
||||
* Ideally it should only contain receive time, payload,
|
||||
* command and size.
|
||||
* type and size.
|
||||
*/
|
||||
class CNetMessage {
|
||||
public:
|
||||
|
@ -286,7 +286,7 @@ public:
|
|||
std::chrono::microseconds m_time{0}; //!< time of message receipt
|
||||
uint32_t m_message_size{0}; //!< size of the payload
|
||||
uint32_t m_raw_message_size{0}; //!< used wire size of the message (including header/checksum)
|
||||
std::string m_command;
|
||||
std::string m_type;
|
||||
|
||||
CNetMessage(CDataStream&& recv_in) : m_recv(std::move(recv_in)) {}
|
||||
|
||||
|
|
|
@ -4177,32 +4177,28 @@ bool PeerManagerImpl::ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt
|
|||
pfrom->GetId(),
|
||||
pfrom->m_addr_name.c_str(),
|
||||
pfrom->ConnectionTypeAsString().c_str(),
|
||||
msg.m_command.c_str(),
|
||||
msg.m_type.c_str(),
|
||||
msg.m_recv.size(),
|
||||
msg.m_recv.data()
|
||||
);
|
||||
|
||||
if (gArgs.GetBoolArg("-capturemessages", false)) {
|
||||
CaptureMessage(pfrom->addr, msg.m_command, MakeUCharSpan(msg.m_recv), /*is_incoming=*/true);
|
||||
CaptureMessage(pfrom->addr, msg.m_type, MakeUCharSpan(msg.m_recv), /*is_incoming=*/true);
|
||||
}
|
||||
|
||||
msg.SetVersion(pfrom->GetCommonVersion());
|
||||
const std::string& msg_type = msg.m_command;
|
||||
|
||||
// Message size
|
||||
unsigned int nMessageSize = msg.m_message_size;
|
||||
|
||||
try {
|
||||
ProcessMessage(*pfrom, msg_type, msg.m_recv, msg.m_time, interruptMsgProc);
|
||||
ProcessMessage(*pfrom, msg.m_type, msg.m_recv, msg.m_time, interruptMsgProc);
|
||||
if (interruptMsgProc) return false;
|
||||
{
|
||||
LOCK(peer->m_getdata_requests_mutex);
|
||||
if (!peer->m_getdata_requests.empty()) fMoreWork = true;
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' (%s) caught\n", __func__, SanitizeString(msg_type), nMessageSize, e.what(), typeid(e).name());
|
||||
LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' (%s) caught\n", __func__, SanitizeString(msg.m_type), msg.m_message_size, e.what(), typeid(e).name());
|
||||
} catch (...) {
|
||||
LogPrint(BCLog::NET, "%s(%s, %u bytes): Unknown exception caught\n", __func__, SanitizeString(msg_type), nMessageSize);
|
||||
LogPrint(BCLog::NET, "%s(%s, %u bytes): Unknown exception caught\n", __func__, SanitizeString(msg.m_type), msg.m_message_size);
|
||||
}
|
||||
|
||||
return fMoreWork;
|
||||
|
|
|
@ -70,13 +70,13 @@ FUZZ_TARGET_INIT(p2p_transport_serialization, initialize_p2p_transport_serializa
|
|||
const std::chrono::microseconds m_time{std::numeric_limits<int64_t>::max()};
|
||||
bool reject_message{false};
|
||||
CNetMessage msg = deserializer.GetMessage(m_time, reject_message);
|
||||
assert(msg.m_command.size() <= CMessageHeader::COMMAND_SIZE);
|
||||
assert(msg.m_type.size() <= CMessageHeader::COMMAND_SIZE);
|
||||
assert(msg.m_raw_message_size <= mutable_msg_bytes.size());
|
||||
assert(msg.m_raw_message_size == CMessageHeader::HEADER_SIZE + msg.m_message_size);
|
||||
assert(msg.m_time == m_time);
|
||||
|
||||
std::vector<unsigned char> header;
|
||||
auto msg2 = CNetMsgMaker{msg.m_recv.GetVersion()}.Make(msg.m_command, MakeUCharSpan(msg.m_recv));
|
||||
auto msg2 = CNetMsgMaker{msg.m_recv.GetVersion()}.Make(msg.m_type, MakeUCharSpan(msg.m_recv));
|
||||
serializer.prepareForTransport(msg2, header);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue