Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show All 9 Lines | |||||
#include <net.h> | #include <net.h> | ||||
#include <banman.h> | #include <banman.h> | ||||
#include <clientversion.h> | #include <clientversion.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <consensus/consensus.h> | #include <consensus/consensus.h> | ||||
#include <crypto/sha256.h> | #include <crypto/sha256.h> | ||||
#include <netbase.h> | #include <netbase.h> | ||||
#include <random.h> | |||||
#include <scheduler.h> | #include <scheduler.h> | ||||
#include <ui_interface.h> | #include <ui_interface.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/translation.h> | #include <util/translation.h> | ||||
#ifdef WIN32 | #ifdef WIN32 | ||||
#include <cstring> | #include <cstring> | ||||
#else | #else | ||||
▲ Show 20 Lines • Show All 426 Lines • ▼ Show 20 Lines | uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE) | ||||
.Finalize(); | .Finalize(); | ||||
CAddress addr_bind = GetBindAddress(hSocket); | CAddress addr_bind = GetBindAddress(hSocket); | ||||
CNode *pnode = | CNode *pnode = | ||||
new CNode(id, nLocalServices, GetBestHeight(), hSocket, addrConnect, | new CNode(id, nLocalServices, GetBestHeight(), hSocket, addrConnect, | ||||
CalculateKeyedNetGroup(addrConnect), nonce, addr_bind, | CalculateKeyedNetGroup(addrConnect), nonce, addr_bind, | ||||
pszDest ? pszDest : "", false, block_relay_only); | pszDest ? pszDest : "", false, block_relay_only); | ||||
pnode->AddRef(); | pnode->AddRef(); | ||||
// We're making a new connection, harvest entropy from the time (and our | |||||
// peer count) | |||||
RandAddEvent((uint32_t)id); | |||||
return pnode; | return pnode; | ||||
} | } | ||||
void CNode::CloseSocketDisconnect() { | void CNode::CloseSocketDisconnect() { | ||||
fDisconnect = true; | fDisconnect = true; | ||||
LOCK(cs_hSocket); | LOCK(cs_hSocket); | ||||
if (hSocket != INVALID_SOCKET) { | if (hSocket != INVALID_SOCKET) { | ||||
LogPrint(BCLog::NET, "disconnecting peer=%d\n", id); | LogPrint(BCLog::NET, "disconnecting peer=%d\n", id); | ||||
▲ Show 20 Lines • Show All 248 Lines • ▼ Show 20 Lines | msg.m_valid_netmagic = | ||||
CMessageHeader::MESSAGE_START_SIZE) == 0); | CMessageHeader::MESSAGE_START_SIZE) == 0); | ||||
uint256 hash = GetMessageHash(); | uint256 hash = GetMessageHash(); | ||||
// store command string, payload size | // store command string, payload size | ||||
msg.m_command = hdr.GetCommand(); | msg.m_command = hdr.GetCommand(); | ||||
msg.m_message_size = hdr.nMessageSize; | msg.m_message_size = hdr.nMessageSize; | ||||
msg.m_raw_message_size = hdr.nMessageSize + CMessageHeader::HEADER_SIZE; | msg.m_raw_message_size = hdr.nMessageSize + CMessageHeader::HEADER_SIZE; | ||||
// We just received a message off the wire, harvest entropy from the time | |||||
// (and the message checksum) | |||||
RandAddEvent(ReadLE32(hash.begin())); | |||||
msg.m_valid_checksum = (memcmp(hash.begin(), hdr.pchChecksum, | msg.m_valid_checksum = (memcmp(hash.begin(), hdr.pchChecksum, | ||||
CMessageHeader::CHECKSUM_SIZE) == 0); | CMessageHeader::CHECKSUM_SIZE) == 0); | ||||
if (!msg.m_valid_checksum) { | if (!msg.m_valid_checksum) { | ||||
LogPrint( | LogPrint( | ||||
BCLog::NET, "CHECKSUM ERROR (%s, %u bytes), expected %s was %s\n", | BCLog::NET, "CHECKSUM ERROR (%s, %u bytes), expected %s was %s\n", | ||||
SanitizeString(msg.m_command), msg.m_message_size, | SanitizeString(msg.m_command), msg.m_message_size, | ||||
HexStr(hash.begin(), hash.begin() + CMessageHeader::CHECKSUM_SIZE), | HexStr(hash.begin(), hash.begin() + CMessageHeader::CHECKSUM_SIZE), | ||||
HexStr(hdr.pchChecksum, | HexStr(hdr.pchChecksum, | ||||
hdr.pchChecksum + CMessageHeader::CHECKSUM_SIZE)); | hdr.pchChecksum + CMessageHeader::CHECKSUM_SIZE)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 391 Lines • ▼ Show 20 Lines | void CConnman::AcceptConnection(const ListenSocket &hListenSocket) { | ||||
m_msgproc->InitializeNode(*config, pnode); | m_msgproc->InitializeNode(*config, pnode); | ||||
LogPrint(BCLog::NET, "connection from %s accepted\n", addr.ToString()); | LogPrint(BCLog::NET, "connection from %s accepted\n", addr.ToString()); | ||||
{ | { | ||||
LOCK(cs_vNodes); | LOCK(cs_vNodes); | ||||
vNodes.push_back(pnode); | vNodes.push_back(pnode); | ||||
} | } | ||||
// We received a new connection, harvest entropy from the time (and our peer | |||||
// count) | |||||
RandAddEvent((uint32_t)id); | |||||
} | } | ||||
void CConnman::DisconnectNodes() { | void CConnman::DisconnectNodes() { | ||||
{ | { | ||||
LOCK(cs_vNodes); | LOCK(cs_vNodes); | ||||
if (!fNetworkActive) { | if (!fNetworkActive) { | ||||
// Disconnect any connected nodes | // Disconnect any connected nodes | ||||
▲ Show 20 Lines • Show All 1,922 Lines • Show Last 20 Lines |