Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | |||||
static const uint64_t SELECT_TIMEOUT_MILLISECONDS = 50; | static const uint64_t SELECT_TIMEOUT_MILLISECONDS = 50; | ||||
const std::string NET_MESSAGE_COMMAND_OTHER = "*other*"; | const std::string NET_MESSAGE_COMMAND_OTHER = "*other*"; | ||||
// SHA256("netgroup")[0:8] | // SHA256("netgroup")[0:8] | ||||
static const uint64_t RANDOMIZER_ID_NETGROUP = 0x6c0edd8036ef4036ULL; | static const uint64_t RANDOMIZER_ID_NETGROUP = 0x6c0edd8036ef4036ULL; | ||||
// SHA256("localhostnonce")[0:8] | // SHA256("localhostnonce")[0:8] | ||||
static const uint64_t RANDOMIZER_ID_LOCALHOSTNONCE = 0xd93e69e2bbfa5735ULL; | static const uint64_t RANDOMIZER_ID_LOCALHOSTNONCE = 0xd93e69e2bbfa5735ULL; | ||||
// SHA256("localhostnonce")[8:16] | |||||
static const uint64_t RANDOMIZER_ID_EXTRAENTROPY = 0x94b05d41679a4ff7ULL; | |||||
// | // | ||||
// Global state variables | // Global state variables | ||||
// | // | ||||
bool fDiscover = true; | bool fDiscover = true; | ||||
bool fListen = true; | bool fListen = true; | ||||
bool g_relay_txes = !DEFAULT_BLOCKSONLY; | bool g_relay_txes = !DEFAULT_BLOCKSONLY; | ||||
RecursiveMutex cs_mapLocalHost; | RecursiveMutex cs_mapLocalHost; | ||||
std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(cs_mapLocalHost); | std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(cs_mapLocalHost); | ||||
▲ Show 20 Lines • Show All 352 Lines • ▼ Show 20 Lines | if (!connected) { | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
// Add node | // Add node | ||||
NodeId id = GetNewNodeId(); | NodeId id = GetNewNodeId(); | ||||
uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE) | uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE) | ||||
.Write(id) | .Write(id) | ||||
.Finalize(); | .Finalize(); | ||||
uint64_t extra_entropy = | |||||
GetDeterministicRandomizer(RANDOMIZER_ID_EXTRAENTROPY) | |||||
.Write(id) | |||||
.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, extra_entropy, | ||||
pszDest ? pszDest : "", conn_type); | addr_bind, pszDest ? pszDest : "", conn_type); | ||||
pnode->AddRef(); | pnode->AddRef(); | ||||
// We're making a new connection, harvest entropy from the time (and our | // We're making a new connection, harvest entropy from the time (and our | ||||
// peer count) | // peer count) | ||||
RandAddEvent((uint32_t)id); | 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) { | ||||
▲ Show 20 Lines • Show All 656 Lines • ▼ Show 20 Lines | if (nInbound >= nMaxInbound) { | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
NodeId id = GetNewNodeId(); | NodeId id = GetNewNodeId(); | ||||
uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE) | uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE) | ||||
.Write(id) | .Write(id) | ||||
.Finalize(); | .Finalize(); | ||||
uint64_t extra_entropy = | |||||
GetDeterministicRandomizer(RANDOMIZER_ID_EXTRAENTROPY) | |||||
.Write(id) | |||||
.Finalize(); | |||||
CAddress addr_bind = GetBindAddress(hSocket); | CAddress addr_bind = GetBindAddress(hSocket); | ||||
ServiceFlags nodeServices = nLocalServices; | ServiceFlags nodeServices = nLocalServices; | ||||
if (NetPermissions::HasFlag(permissionFlags, PF_BLOOMFILTER)) { | if (NetPermissions::HasFlag(permissionFlags, PF_BLOOMFILTER)) { | ||||
nodeServices = static_cast<ServiceFlags>(nodeServices | NODE_BLOOM); | nodeServices = static_cast<ServiceFlags>(nodeServices | NODE_BLOOM); | ||||
} | } | ||||
CNode *pnode = new CNode(id, nodeServices, GetBestHeight(), hSocket, addr, | CNode *pnode = new CNode(id, nodeServices, GetBestHeight(), hSocket, addr, | ||||
CalculateKeyedNetGroup(addr), nonce, addr_bind, "", | CalculateKeyedNetGroup(addr), nonce, extra_entropy, | ||||
ConnectionType::INBOUND); | addr_bind, "", ConnectionType::INBOUND); | ||||
pnode->AddRef(); | pnode->AddRef(); | ||||
pnode->m_permissionFlags = permissionFlags; | pnode->m_permissionFlags = permissionFlags; | ||||
// If this flag is present, the user probably expect that RPC and QT report | // If this flag is present, the user probably expect that RPC and QT report | ||||
// it as whitelisted (backward compatibility) | // it as whitelisted (backward compatibility) | ||||
pnode->m_legacyWhitelisted = legacyWhitelisted; | pnode->m_legacyWhitelisted = legacyWhitelisted; | ||||
pnode->m_prefer_evict = discouraged; | pnode->m_prefer_evict = discouraged; | ||||
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 | // We received a new connection, harvest entropy from the time (and our peer | ||||
// count) | // count) | ||||
RandAddEvent((uint32_t)id); | 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,804 Lines • ▼ Show 20 Lines | |||||
unsigned int CConnman::GetReceiveFloodSize() const { | unsigned int CConnman::GetReceiveFloodSize() const { | ||||
return nReceiveFloodSize; | return nReceiveFloodSize; | ||||
} | } | ||||
CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, | CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, | ||||
int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, | int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, | ||||
uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, | uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, | ||||
const CAddress &addrBindIn, const std::string &addrNameIn, | uint64_t nLocalExtraEntropyIn, const CAddress &addrBindIn, | ||||
ConnectionType conn_type_in) | const std::string &addrNameIn, ConnectionType conn_type_in) | ||||
: nTimeConnected(GetSystemTimeInSeconds()), addr(addrIn), | : nTimeConnected(GetSystemTimeInSeconds()), addr(addrIn), | ||||
addrBind(addrBindIn), nKeyedNetGroup(nKeyedNetGroupIn), | addrBind(addrBindIn), nKeyedNetGroup(nKeyedNetGroupIn), | ||||
// Don't relay addr messages to peers that we connect to as | // Don't relay addr messages to peers that we connect to as | ||||
// block-relay-only peers (to prevent adversaries from inferring these | // block-relay-only peers (to prevent adversaries from inferring these | ||||
// links from addr traffic). | // links from addr traffic). | ||||
id(idIn), nLocalHostNonce(nLocalHostNonceIn), m_conn_type(conn_type_in), | id(idIn), nLocalHostNonce(nLocalHostNonceIn), | ||||
nLocalExtraEntropy(nLocalExtraEntropyIn), m_conn_type(conn_type_in), | |||||
nLocalServices(nLocalServicesIn), nMyStartingHeight(nMyStartingHeightIn) { | nLocalServices(nLocalServicesIn), nMyStartingHeight(nMyStartingHeightIn) { | ||||
hSocket = hSocketIn; | hSocket = hSocketIn; | ||||
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn; | addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn; | ||||
hashContinue = BlockHash(); | hashContinue = BlockHash(); | ||||
if (conn_type_in != ConnectionType::BLOCK_RELAY) { | if (conn_type_in != ConnectionType::BLOCK_RELAY) { | ||||
m_tx_relay = std::make_unique<TxRelay>(); | m_tx_relay = std::make_unique<TxRelay>(); | ||||
m_addr_known = std::make_unique<CRollingBloomFilter>(5000, 0.001); | m_addr_known = std::make_unique<CRollingBloomFilter>(5000, 0.001); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines |