Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 546 Lines • ▼ Show 20 Lines | void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap) { | ||||
stats.nTimeOffset = nTimeOffset; | stats.nTimeOffset = nTimeOffset; | ||||
stats.addrName = GetAddrName(); | stats.addrName = GetAddrName(); | ||||
stats.nVersion = nVersion; | stats.nVersion = nVersion; | ||||
{ | { | ||||
LOCK(cs_SubVer); | LOCK(cs_SubVer); | ||||
stats.cleanSubVer = cleanSubVer; | stats.cleanSubVer = cleanSubVer; | ||||
} | } | ||||
stats.fInbound = fInbound; | stats.fInbound = fInbound; | ||||
stats.m_manual_connection = m_manual_connection; | stats.m_manual_connection = IsManualConn(); | ||||
stats.nStartingHeight = nStartingHeight; | stats.nStartingHeight = nStartingHeight; | ||||
{ | { | ||||
LOCK(cs_vSend); | LOCK(cs_vSend); | ||||
stats.mapSendBytesPerMsgCmd = mapSendBytesPerMsgCmd; | stats.mapSendBytesPerMsgCmd = mapSendBytesPerMsgCmd; | ||||
stats.nSendBytes = nSendBytes; | stats.nSendBytes = nSendBytes; | ||||
} | } | ||||
{ | { | ||||
LOCK(cs_vRecv); | LOCK(cs_vRecv); | ||||
▲ Show 20 Lines • Show All 1,222 Lines • ▼ Show 20 Lines | for (const std::string &seed : seeds) { | ||||
int nRelevant = 0; | int nRelevant = 0; | ||||
{ | { | ||||
LOCK(cs_vNodes); | LOCK(cs_vNodes); | ||||
for (const CNode *pnode : vNodes) { | for (const CNode *pnode : vNodes) { | ||||
nRelevant += | nRelevant += | ||||
pnode->fSuccessfullyConnected && | pnode->fSuccessfullyConnected && | ||||
!pnode->fFeeler && !pnode->m_addr_fetch && | !pnode->fFeeler && !pnode->m_addr_fetch && | ||||
!pnode->m_manual_connection && !pnode->fInbound; | !pnode->IsManualConn() && !pnode->fInbound; | ||||
} | } | ||||
} | } | ||||
if (nRelevant >= 2) { | if (nRelevant >= 2) { | ||||
if (found > 0) { | if (found > 0) { | ||||
LogPrintf("%d addresses found from DNS seeds\n", | LogPrintf("%d addresses found from DNS seeds\n", | ||||
found); | found); | ||||
LogPrintf( | LogPrintf( | ||||
"P2P peers available. Finished DNS seeding.\n"); | "P2P peers available. Finished DNS seeding.\n"); | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | |||||
// Also exclude peers that haven't finished initial connection handshake yet (so | // Also exclude peers that haven't finished initial connection handshake yet (so | ||||
// that we don't decide we're over our desired connection limit, and then evict | // that we don't decide we're over our desired connection limit, and then evict | ||||
// some peer that has finished the handshake). | // some peer that has finished the handshake). | ||||
int CConnman::GetExtraOutboundCount() { | int CConnman::GetExtraOutboundCount() { | ||||
int nOutbound = 0; | int nOutbound = 0; | ||||
{ | { | ||||
LOCK(cs_vNodes); | LOCK(cs_vNodes); | ||||
for (const CNode *pnode : vNodes) { | for (const CNode *pnode : vNodes) { | ||||
if (!pnode->fInbound && !pnode->m_manual_connection && | if (!pnode->fInbound && !pnode->IsManualConn() && !pnode->fFeeler && | ||||
!pnode->fFeeler && !pnode->fDisconnect && | !pnode->fDisconnect && !pnode->m_addr_fetch && | ||||
!pnode->m_addr_fetch && pnode->fSuccessfullyConnected) { | pnode->fSuccessfullyConnected) { | ||||
++nOutbound; | ++nOutbound; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return std::max( | return std::max( | ||||
nOutbound - m_max_outbound_full_relay - m_max_outbound_block_relay, 0); | nOutbound - m_max_outbound_full_relay - m_max_outbound_block_relay, 0); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | while (!interruptNet) { | ||||
// Only connect out to one peer per network group (/16 for IPv4). | // Only connect out to one peer per network group (/16 for IPv4). | ||||
int nOutboundFullRelay = 0; | int nOutboundFullRelay = 0; | ||||
int nOutboundBlockRelay = 0; | int nOutboundBlockRelay = 0; | ||||
std::set<std::vector<uint8_t>> setConnected; | std::set<std::vector<uint8_t>> setConnected; | ||||
{ | { | ||||
LOCK(cs_vNodes); | LOCK(cs_vNodes); | ||||
for (const CNode *pnode : vNodes) { | for (const CNode *pnode : vNodes) { | ||||
if (!pnode->fInbound && !pnode->m_manual_connection) { | if (!pnode->fInbound && | ||||
(pnode->m_conn_type != ConnectionType::MANUAL)) { | |||||
// Netgroups for inbound and addnode peers are not excluded | // Netgroups for inbound and addnode peers are not excluded | ||||
// because our goal here is to not use multiple of our | // because our goal here is to not use multiple of our | ||||
// limited outbound slots on a single netgroup but inbound | // limited outbound slots on a single netgroup but inbound | ||||
// and addnode peers do not use our outbound slots. Inbound | // and addnode peers do not use our outbound slots. Inbound | ||||
// peers also have the added issue that they're attacker | // peers also have the added issue that they're attacker | ||||
// controlled and could be used to prevent us from | // controlled and could be used to prevent us from | ||||
// connecting to particular hosts if we used them here. | // connecting to particular hosts if we used them here. | ||||
setConnected.insert(pnode->addr.GetGroup(addrman.m_asmap)); | setConnected.insert(pnode->addr.GetGroup(addrman.m_asmap)); | ||||
▲ Show 20 Lines • Show All 977 Lines • ▼ Show 20 Lines | |||||
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, | const CAddress &addrBindIn, const std::string &addrNameIn, | ||||
ConnectionType conn_type_in) | ConnectionType conn_type_in) | ||||
: nTimeConnected(GetSystemTimeInSeconds()), addr(addrIn), | : nTimeConnected(GetSystemTimeInSeconds()), addr(addrIn), | ||||
addrBind(addrBindIn), fFeeler(conn_type_in == ConnectionType::FEELER), | addrBind(addrBindIn), fFeeler(conn_type_in == ConnectionType::FEELER), | ||||
m_addr_fetch(conn_type_in == ConnectionType::ADDR_FETCH), | m_addr_fetch(conn_type_in == ConnectionType::ADDR_FETCH), | ||||
m_manual_connection(conn_type_in == ConnectionType::MANUAL), | |||||
fInbound(conn_type_in == ConnectionType::INBOUND), | fInbound(conn_type_in == ConnectionType::INBOUND), | ||||
nKeyedNetGroup(nKeyedNetGroupIn), | 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), m_conn_type(conn_type_in), | ||||
nLocalServices(nLocalServicesIn), nMyStartingHeight(nMyStartingHeightIn) { | nLocalServices(nLocalServicesIn), nMyStartingHeight(nMyStartingHeightIn) { | ||||
hSocket = hSocketIn; | hSocket = hSocketIn; | ||||
▲ Show 20 Lines • Show All 160 Lines • Show Last 20 Lines |