Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 702 Lines • ▼ Show 20 Lines | if (!msg.in_data) { | ||||
// Header only, cannot be oversized. | // Header only, cannot be oversized. | ||||
return false; | return false; | ||||
} | } | ||||
return msg.hdr.IsOversized(config); | return msg.hdr.IsOversized(config); | ||||
} | } | ||||
bool CNode::ReceiveMsgBytes(const Config &config, const char *pch, | bool CNode::ReceiveMsgBytes(const Config &config, const char *pch, | ||||
unsigned int nBytes, bool &complete) { | uint32_t nBytes, bool &complete) { | ||||
complete = false; | complete = false; | ||||
int64_t nTimeMicros = GetTimeMicros(); | int64_t nTimeMicros = GetTimeMicros(); | ||||
LOCK(cs_vRecv); | LOCK(cs_vRecv); | ||||
nLastRecv = nTimeMicros / 1000000; | nLastRecv = nTimeMicros / 1000000; | ||||
nRecvBytes += nBytes; | nRecvBytes += nBytes; | ||||
while (nBytes > 0) { | while (nBytes > 0) { | ||||
// Get current incomplete message, or create a new one. | // Get current incomplete message, or create a new one. | ||||
if (vRecvMsg.empty() || vRecvMsg.back().complete()) { | if (vRecvMsg.empty() || vRecvMsg.back().complete()) { | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | if (nSendVersion == 0) { | ||||
error("Requesting unset send version for node: %i. Using %i", id, | error("Requesting unset send version for node: %i. Using %i", id, | ||||
INIT_PROTO_VERSION); | INIT_PROTO_VERSION); | ||||
return INIT_PROTO_VERSION; | return INIT_PROTO_VERSION; | ||||
} | } | ||||
return nSendVersion; | return nSendVersion; | ||||
} | } | ||||
int CNetMessage::readHeader(const Config &config, const char *pch, | int CNetMessage::readHeader(const Config &config, const char *pch, | ||||
unsigned int nBytes) { | uint32_t nBytes) { | ||||
// copy data to temporary parsing buffer | // copy data to temporary parsing buffer | ||||
unsigned int nRemaining = 24 - nHdrPos; | uint32_t nRemaining = 24 - nHdrPos; | ||||
unsigned int nCopy = std::min(nRemaining, nBytes); | uint32_t nCopy = std::min(nRemaining, nBytes); | ||||
memcpy(&hdrbuf[nHdrPos], pch, nCopy); | memcpy(&hdrbuf[nHdrPos], pch, nCopy); | ||||
nHdrPos += nCopy; | nHdrPos += nCopy; | ||||
// if header incomplete, exit | // if header incomplete, exit | ||||
if (nHdrPos < 24) { | if (nHdrPos < 24) { | ||||
return nCopy; | return nCopy; | ||||
} | } | ||||
Show All 12 Lines | int CNetMessage::readHeader(const Config &config, const char *pch, | ||||
} | } | ||||
// switch state to reading message data | // switch state to reading message data | ||||
in_data = true; | in_data = true; | ||||
return nCopy; | return nCopy; | ||||
} | } | ||||
int CNetMessage::readData(const char *pch, unsigned int nBytes) { | int CNetMessage::readData(const char *pch, uint32_t nBytes) { | ||||
unsigned int nRemaining = hdr.nMessageSize - nDataPos; | unsigned int nRemaining = hdr.nMessageSize - nDataPos; | ||||
unsigned int nCopy = std::min(nRemaining, nBytes); | unsigned int nCopy = std::min(nRemaining, nBytes); | ||||
if (vRecv.size() < nDataPos + nCopy) { | if (vRecv.size() < nDataPos + nCopy) { | ||||
// Allocate up to 256 KiB ahead, but never more than the total message | // Allocate up to 256 KiB ahead, but never more than the total message | ||||
// size. | // size. | ||||
vRecv.resize(std::min(hdr.nMessageSize, nDataPos + nCopy + 256 * 1024)); | vRecv.resize(std::min(hdr.nMessageSize, nDataPos + nCopy + 256 * 1024)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 566 Lines • ▼ Show 20 Lines | while (!interruptNet) { | ||||
} | } | ||||
recvSet = FD_ISSET(pnode->hSocket, &fdsetRecv); | recvSet = FD_ISSET(pnode->hSocket, &fdsetRecv); | ||||
sendSet = FD_ISSET(pnode->hSocket, &fdsetSend); | sendSet = FD_ISSET(pnode->hSocket, &fdsetSend); | ||||
errorSet = FD_ISSET(pnode->hSocket, &fdsetError); | errorSet = FD_ISSET(pnode->hSocket, &fdsetError); | ||||
} | } | ||||
if (recvSet || errorSet) { | if (recvSet || errorSet) { | ||||
// typical socket buffer is 8K-64K | // typical socket buffer is 8K-64K | ||||
char pchBuf[0x10000]; | char pchBuf[0x10000]; | ||||
int nBytes = 0; | int32_t nBytes = 0; | ||||
{ | { | ||||
LOCK(pnode->cs_hSocket); | LOCK(pnode->cs_hSocket); | ||||
if (pnode->hSocket == INVALID_SOCKET) { | if (pnode->hSocket == INVALID_SOCKET) { | ||||
continue; | continue; | ||||
} | } | ||||
nBytes = recv(pnode->hSocket, pchBuf, sizeof(pchBuf), | nBytes = recv(pnode->hSocket, pchBuf, sizeof(pchBuf), | ||||
MSG_DONTWAIT); | MSG_DONTWAIT); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,652 Lines • Show Last 20 Lines |