mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
net: Treat raw message bytes as uint8_t
This commit is contained in:
14
src/net.cpp
14
src/net.cpp
@@ -629,7 +629,7 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
|
||||
}
|
||||
#undef X
|
||||
|
||||
bool CNode::ReceiveMsgBytes(Span<const char> msg_bytes, bool& complete)
|
||||
bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
|
||||
{
|
||||
complete = false;
|
||||
const auto time = GetTime<std::chrono::microseconds>();
|
||||
@@ -673,7 +673,7 @@ bool CNode::ReceiveMsgBytes(Span<const char> msg_bytes, bool& complete)
|
||||
return true;
|
||||
}
|
||||
|
||||
int V1TransportDeserializer::readHeader(Span<const char> msg_bytes)
|
||||
int V1TransportDeserializer::readHeader(Span<const uint8_t> msg_bytes)
|
||||
{
|
||||
// copy data to temporary parsing buffer
|
||||
unsigned int nRemaining = CMessageHeader::HEADER_SIZE - nHdrPos;
|
||||
@@ -713,7 +713,7 @@ int V1TransportDeserializer::readHeader(Span<const char> msg_bytes)
|
||||
return nCopy;
|
||||
}
|
||||
|
||||
int V1TransportDeserializer::readData(Span<const char> msg_bytes)
|
||||
int V1TransportDeserializer::readData(Span<const uint8_t> msg_bytes)
|
||||
{
|
||||
unsigned int nRemaining = hdr.nMessageSize - nDataPos;
|
||||
unsigned int nCopy = std::min<unsigned int>(nRemaining, msg_bytes.size());
|
||||
@@ -723,7 +723,7 @@ int V1TransportDeserializer::readData(Span<const char> msg_bytes)
|
||||
vRecv.resize(std::min(hdr.nMessageSize, nDataPos + nCopy + 256 * 1024));
|
||||
}
|
||||
|
||||
hasher.Write(MakeUCharSpan(msg_bytes.first(nCopy)));
|
||||
hasher.Write(msg_bytes.first(nCopy));
|
||||
memcpy(&vRecv[nDataPos], msg_bytes.data(), nCopy);
|
||||
nDataPos += nCopy;
|
||||
|
||||
@@ -1463,18 +1463,18 @@ void CConnman::SocketHandler()
|
||||
if (recvSet || errorSet)
|
||||
{
|
||||
// typical socket buffer is 8K-64K
|
||||
char pchBuf[0x10000];
|
||||
uint8_t pchBuf[0x10000];
|
||||
int nBytes = 0;
|
||||
{
|
||||
LOCK(pnode->cs_hSocket);
|
||||
if (pnode->hSocket == INVALID_SOCKET)
|
||||
continue;
|
||||
nBytes = recv(pnode->hSocket, pchBuf, sizeof(pchBuf), MSG_DONTWAIT);
|
||||
nBytes = recv(pnode->hSocket, (char*)pchBuf, sizeof(pchBuf), MSG_DONTWAIT);
|
||||
}
|
||||
if (nBytes > 0)
|
||||
{
|
||||
bool notify = false;
|
||||
if (!pnode->ReceiveMsgBytes(Span<const char>(pchBuf, nBytes), notify))
|
||||
if (!pnode->ReceiveMsgBytes(Span<const uint8_t>(pchBuf, nBytes), notify))
|
||||
pnode->CloseSocketDisconnect();
|
||||
RecordBytesRecv(nBytes);
|
||||
if (notify) {
|
||||
|
||||
Reference in New Issue
Block a user