Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 536 Lines • ▼ Show 20 Lines | uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE) | ||||
.Finalize(); | .Finalize(); | ||||
uint64_t extra_entropy = | uint64_t extra_entropy = | ||||
GetDeterministicRandomizer(RANDOMIZER_ID_EXTRAENTROPY) | GetDeterministicRandomizer(RANDOMIZER_ID_EXTRAENTROPY) | ||||
.Write(id) | .Write(id) | ||||
.Finalize(); | .Finalize(); | ||||
if (!addr_bind.IsValid()) { | if (!addr_bind.IsValid()) { | ||||
addr_bind = GetBindAddress(sock->Get()); | addr_bind = GetBindAddress(sock->Get()); | ||||
} | } | ||||
CNode *pnode = | CNode *pnode = new CNode( | ||||
new CNode(id, nLocalServices, sock->Release(), addrConnect, | id, sock->Release(), addrConnect, CalculateKeyedNetGroup(addrConnect), | ||||
CalculateKeyedNetGroup(addrConnect), nonce, extra_entropy, | nonce, extra_entropy, addr_bind, pszDest ? pszDest : "", conn_type, | ||||
addr_bind, pszDest ? pszDest : "", conn_type, | |||||
/* inbound_onion */ false); | /* inbound_onion */ false); | ||||
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; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 830 Lines • ▼ Show 20 Lines | void CConnman::CreateNodeFromAcceptedSocket(SOCKET hSocket, | ||||
if (NetPermissions::HasFlag(permissionFlags, | if (NetPermissions::HasFlag(permissionFlags, | ||||
NetPermissionFlags::BloomFilter)) { | NetPermissionFlags::BloomFilter)) { | ||||
nodeServices = static_cast<ServiceFlags>(nodeServices | NODE_BLOOM); | nodeServices = static_cast<ServiceFlags>(nodeServices | NODE_BLOOM); | ||||
} | } | ||||
const bool inbound_onion = | const bool inbound_onion = | ||||
std::find(m_onion_binds.begin(), m_onion_binds.end(), addr_bind) != | std::find(m_onion_binds.begin(), m_onion_binds.end(), addr_bind) != | ||||
m_onion_binds.end(); | m_onion_binds.end(); | ||||
CNode *pnode = new CNode( | CNode *pnode = new CNode(id, hSocket, addr, CalculateKeyedNetGroup(addr), | ||||
id, nodeServices, hSocket, addr, CalculateKeyedNetGroup(addr), nonce, | nonce, extra_entropy, addr_bind, "", | ||||
extra_entropy, addr_bind, "", ConnectionType::INBOUND, inbound_onion); | ConnectionType::INBOUND, inbound_onion); | ||||
pnode->AddRef(); | pnode->AddRef(); | ||||
pnode->m_permissionFlags = permissionFlags; | pnode->m_permissionFlags = permissionFlags; | ||||
pnode->m_prefer_evict = discouraged; | pnode->m_prefer_evict = discouraged; | ||||
for (auto interface : m_msgproc) { | for (auto interface : m_msgproc) { | ||||
interface->InitializeNode(*config, *pnode, nodeServices); | interface->InitializeNode(*config, *pnode, nodeServices); | ||||
} | } | ||||
LogPrint(BCLog::NET, "connection from %s accepted\n", addr.ToString()); | LogPrint(BCLog::NET, "connection from %s accepted\n", addr.ToString()); | ||||
▲ Show 20 Lines • Show All 2,036 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
double CNode::getAvailabilityScore() const { | double CNode::getAvailabilityScore() const { | ||||
// The score is set atomically so there is no need to lock the statistics | // The score is set atomically so there is no need to lock the statistics | ||||
// when reading. | // when reading. | ||||
return availabilityScore; | return availabilityScore; | ||||
} | } | ||||
CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, | CNode::CNode(NodeId idIn, SOCKET hSocketIn, const CAddress &addrIn, | ||||
const CAddress &addrIn, uint64_t nKeyedNetGroupIn, | uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, | ||||
uint64_t nLocalHostNonceIn, uint64_t nLocalExtraEntropyIn, | uint64_t nLocalExtraEntropyIn, const CAddress &addrBindIn, | ||||
const CAddress &addrBindIn, const std::string &addrNameIn, | const std::string &addrNameIn, ConnectionType conn_type_in, | ||||
ConnectionType conn_type_in, bool inbound_onion) | bool inbound_onion) | ||||
: m_connected(GetTime<std::chrono::seconds>()), addr(addrIn), | : m_connected(GetTime<std::chrono::seconds>()), addr(addrIn), | ||||
addrBind(addrBindIn), m_addr_name{addrNameIn.empty() | addrBind(addrBindIn), m_addr_name{addrNameIn.empty() | ||||
? addr.ToStringIPPort() | ? addr.ToStringIPPort() | ||||
: addrNameIn}, | : addrNameIn}, | ||||
m_inbound_onion(inbound_onion), nKeyedNetGroup(nKeyedNetGroupIn), | m_inbound_onion(inbound_onion), 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), | id(idIn), nLocalHostNonce(nLocalHostNonceIn), | ||||
nLocalExtraEntropy(nLocalExtraEntropyIn), m_conn_type(conn_type_in), | nLocalExtraEntropy(nLocalExtraEntropyIn), m_conn_type(conn_type_in) { | ||||
nLocalServices(nLocalServicesIn) { | |||||
if (inbound_onion) { | if (inbound_onion) { | ||||
assert(conn_type_in == ConnectionType::INBOUND); | assert(conn_type_in == ConnectionType::INBOUND); | ||||
} | } | ||||
hSocket = hSocketIn; | hSocket = hSocketIn; | ||||
for (const std::string &msg : getAllNetMessageTypes()) { | for (const std::string &msg : getAllNetMessageTypes()) { | ||||
mapRecvBytesPerMsgCmd[msg] = 0; | mapRecvBytesPerMsgCmd[msg] = 0; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 195 Lines • Show Last 20 Lines |