Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 641 Lines • ▼ Show 20 Lines | while (nBytes > 0) { | ||||
complete = true; | complete = true; | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
void CNode::SetSendVersion(int nVersionIn) { | |||||
// Send version may only be changed in the version message, and only one | |||||
// version message is allowed per session. We can therefore treat this value | |||||
// as const and even atomic as long as it's only used once a version message | |||||
// has been successfully processed. Any attempt to set this twice is an | |||||
// error. | |||||
if (nSendVersion != 0) { | |||||
error("Send version already set for node: %i. Refusing to change from " | |||||
"%i to %i", | |||||
id, nSendVersion, nVersionIn); | |||||
} else { | |||||
nSendVersion = nVersionIn; | |||||
} | |||||
} | |||||
int CNode::GetSendVersion() const { | |||||
// The send version should always be explicitly set to INIT_PROTO_VERSION | |||||
// rather than using this value until SetSendVersion has been called. | |||||
if (nSendVersion == 0) { | |||||
error("Requesting unset send version for node: %i. Using %i", id, | |||||
INIT_PROTO_VERSION); | |||||
return INIT_PROTO_VERSION; | |||||
} | |||||
return nSendVersion; | |||||
} | |||||
int V1TransportDeserializer::readHeader(const Config &config, const char *pch, | int V1TransportDeserializer::readHeader(const Config &config, const char *pch, | ||||
uint32_t nBytes) { | uint32_t nBytes) { | ||||
// copy data to temporary parsing buffer | // copy data to temporary parsing buffer | ||||
uint32_t nRemaining = CMessageHeader::HEADER_SIZE - nHdrPos; | uint32_t nRemaining = CMessageHeader::HEADER_SIZE - nHdrPos; | ||||
uint32_t 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; | ||||
▲ Show 20 Lines • Show All 591 Lines • ▼ Show 20 Lines | if (nTime - pnode->nTimeConnected > m_peer_connect_timeout) { | ||||
"socket no message in first %i seconds, %d %d from %d\n", | "socket no message in first %i seconds, %d %d from %d\n", | ||||
m_peer_connect_timeout, pnode->nLastRecv != 0, | m_peer_connect_timeout, pnode->nLastRecv != 0, | ||||
pnode->nLastSend != 0, pnode->GetId()); | pnode->nLastSend != 0, pnode->GetId()); | ||||
pnode->fDisconnect = true; | pnode->fDisconnect = true; | ||||
} else if (nTime - pnode->nLastSend > TIMEOUT_INTERVAL) { | } else if (nTime - pnode->nLastSend > TIMEOUT_INTERVAL) { | ||||
LogPrintf("socket sending timeout: %is\n", | LogPrintf("socket sending timeout: %is\n", | ||||
nTime - pnode->nLastSend); | nTime - pnode->nLastSend); | ||||
pnode->fDisconnect = true; | pnode->fDisconnect = true; | ||||
} else if (nTime - pnode->nLastRecv > (pnode->nVersion > BIP0031_VERSION | } else if (nTime - pnode->nLastRecv > | ||||
(pnode->GetCommonVersion() > BIP0031_VERSION | |||||
? TIMEOUT_INTERVAL | ? TIMEOUT_INTERVAL | ||||
: 90 * 60)) { | : 90 * 60)) { | ||||
LogPrintf("socket receive timeout: %is\n", | LogPrintf("socket receive timeout: %is\n", | ||||
nTime - pnode->nLastRecv); | nTime - pnode->nLastRecv); | ||||
pnode->fDisconnect = true; | pnode->fDisconnect = true; | ||||
} else if (pnode->nPingNonceSent && | } else if (pnode->nPingNonceSent && | ||||
pnode->m_ping_start.load() + | pnode->m_ping_start.load() + | ||||
std::chrono::seconds{TIMEOUT_INTERVAL} < | std::chrono::seconds{TIMEOUT_INTERVAL} < | ||||
GetTime<std::chrono::microseconds>()) { | GetTime<std::chrono::microseconds>()) { | ||||
LogPrintf("ping timeout: %fs\n", | LogPrintf("ping timeout: %fs\n", | ||||
▲ Show 20 Lines • Show All 1,893 Lines • Show Last 20 Lines |