Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 332 Lines • ▼ Show 20 Lines | for (CNode *pnode : vNodes) { | ||||
} | } | ||||
} | } | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
bool CConnman::CheckIncomingNonce(uint64_t nonce) { | bool CConnman::CheckIncomingNonce(uint64_t nonce) { | ||||
LOCK(cs_vNodes); | LOCK(cs_vNodes); | ||||
for (const CNode *pnode : vNodes) { | for (const CNode *pnode : vNodes) { | ||||
if (!pnode->fSuccessfullyConnected && !pnode->fInbound && | if (!pnode->fSuccessfullyConnected && !pnode->IsInboundConn() && | ||||
pnode->GetLocalNonce() == nonce) { | pnode->GetLocalNonce() == nonce) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
/** Get the bind address for a socket as CAddress */ | /** Get the bind address for a socket as CAddress */ | ||||
▲ Show 20 Lines • Show All 196 Lines • ▼ Show 20 Lines | void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap) { | ||||
stats.nTimeConnected = nTimeConnected; | stats.nTimeConnected = nTimeConnected; | ||||
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 = IsInboundConn(); | ||||
stats.m_manual_connection = IsManualConn(); | 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; | ||||
} | } | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 372 Lines • ▼ Show 20 Lines | bool CConnman::AttemptToEvictConnection() { | ||||
std::vector<NodeEvictionCandidate> vEvictionCandidates; | std::vector<NodeEvictionCandidate> vEvictionCandidates; | ||||
{ | { | ||||
LOCK(cs_vNodes); | LOCK(cs_vNodes); | ||||
for (const CNode *node : vNodes) { | for (const CNode *node : vNodes) { | ||||
if (node->HasPermission(PF_NOBAN)) { | if (node->HasPermission(PF_NOBAN)) { | ||||
continue; | continue; | ||||
} | } | ||||
if (!node->fInbound) { | if (!node->IsInboundConn()) { | ||||
continue; | continue; | ||||
} | } | ||||
if (node->fDisconnect) { | if (node->fDisconnect) { | ||||
continue; | continue; | ||||
} | } | ||||
bool peer_relay_txes = false; | bool peer_relay_txes = false; | ||||
bool peer_filter_not_null = false; | bool peer_filter_not_null = false; | ||||
if (node->m_tx_relay != nullptr) { | if (node->m_tx_relay != nullptr) { | ||||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | if (NetPermissions::HasFlag(permissionFlags, | ||||
NetPermissions::AddFlag(permissionFlags, PF_MEMPOOL); | NetPermissions::AddFlag(permissionFlags, PF_MEMPOOL); | ||||
NetPermissions::AddFlag(permissionFlags, PF_NOBAN); | NetPermissions::AddFlag(permissionFlags, PF_NOBAN); | ||||
legacyWhitelisted = true; | legacyWhitelisted = true; | ||||
} | } | ||||
{ | { | ||||
LOCK(cs_vNodes); | LOCK(cs_vNodes); | ||||
for (const CNode *pnode : vNodes) { | for (const CNode *pnode : vNodes) { | ||||
if (pnode->fInbound) { | if (pnode->IsInboundConn()) { | ||||
nInbound++; | nInbound++; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (hSocket == INVALID_SOCKET) { | if (hSocket == INVALID_SOCKET) { | ||||
int nErr = WSAGetLastError(); | int nErr = WSAGetLastError(); | ||||
if (nErr != WSAEWOULDBLOCK) { | if (nErr != WSAEWOULDBLOCK) { | ||||
▲ Show 20 Lines • Show All 694 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 += pnode->fSuccessfullyConnected && | nRelevant += pnode->fSuccessfullyConnected && | ||||
!pnode->IsFeelerConn() && | !pnode->IsFeelerConn() && | ||||
!pnode->IsAddrFetchConn() && | !pnode->IsAddrFetchConn() && | ||||
!pnode->IsManualConn() && | !pnode->IsManualConn() && | ||||
!pnode->fInbound; | !pnode->IsInboundConn(); | ||||
} | } | ||||
} | } | ||||
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->IsManualConn() && | if (!pnode->IsInboundConn() && !pnode->IsManualConn() && | ||||
!pnode->IsFeelerConn() && !pnode->fDisconnect && | !pnode->IsFeelerConn() && !pnode->fDisconnect && | ||||
!pnode->IsAddrFetchConn() && pnode->fSuccessfullyConnected) { | !pnode->IsAddrFetchConn() && 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 63 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 && | if (!pnode->IsInboundConn() && | ||||
(pnode->m_conn_type != ConnectionType::MANUAL)) { | (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. | ||||
▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Lines | std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() { | ||||
// Build a map of all already connected addresses (by IP:port and by name) | // Build a map of all already connected addresses (by IP:port and by name) | ||||
// to inbound/outbound and resolved CService | // to inbound/outbound and resolved CService | ||||
std::map<CService, bool> mapConnected; | std::map<CService, bool> mapConnected; | ||||
std::map<std::string, std::pair<bool, CService>> mapConnectedByName; | std::map<std::string, std::pair<bool, CService>> mapConnectedByName; | ||||
{ | { | ||||
LOCK(cs_vNodes); | LOCK(cs_vNodes); | ||||
for (const CNode *pnode : vNodes) { | for (const CNode *pnode : vNodes) { | ||||
if (pnode->addr.IsValid()) { | if (pnode->addr.IsValid()) { | ||||
mapConnected[pnode->addr] = pnode->fInbound; | mapConnected[pnode->addr] = pnode->IsInboundConn(); | ||||
} | } | ||||
std::string addrName = pnode->GetAddrName(); | std::string addrName = pnode->GetAddrName(); | ||||
if (!addrName.empty()) { | if (!addrName.empty()) { | ||||
mapConnectedByName[std::move(addrName)] = | mapConnectedByName[std::move(addrName)] = | ||||
std::make_pair(pnode->fInbound, | std::make_pair(pnode->IsInboundConn(), | ||||
static_cast<const CService &>(pnode->addr)); | static_cast<const CService &>(pnode->addr)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
for (const std::string &strAddNode : lAddresses) { | for (const std::string &strAddNode : lAddresses) { | ||||
CService service(LookupNumeric(strAddNode, Params().GetDefaultPort())); | CService service(LookupNumeric(strAddNode, Params().GetDefaultPort())); | ||||
AddedNodeInfo addedNode{strAddNode, CService(), false, false}; | AddedNodeInfo addedNode{strAddNode, CService(), false, false}; | ||||
▲ Show 20 Lines • Show All 629 Lines • ▼ Show 20 Lines | size_t CConnman::GetNodeCount(NumConnections flags) { | ||||
LOCK(cs_vNodes); | LOCK(cs_vNodes); | ||||
// Shortcut if we want total | // Shortcut if we want total | ||||
if (flags == CConnman::CONNECTIONS_ALL) { | if (flags == CConnman::CONNECTIONS_ALL) { | ||||
return vNodes.size(); | return vNodes.size(); | ||||
} | } | ||||
int nNum = 0; | int nNum = 0; | ||||
for (const auto &pnode : vNodes) { | for (const auto &pnode : vNodes) { | ||||
if (flags & (pnode->fInbound ? CONNECTIONS_IN : CONNECTIONS_OUT)) { | if (flags & | ||||
(pnode->IsInboundConn() ? CONNECTIONS_IN : CONNECTIONS_OUT)) { | |||||
nNum++; | nNum++; | ||||
} | } | ||||
} | } | ||||
return nNum; | return nNum; | ||||
} | } | ||||
void CConnman::GetNodeStats(std::vector<CNodeStats> &vstats) { | void CConnman::GetNodeStats(std::vector<CNodeStats> &vstats) { | ||||
▲ Show 20 Lines • Show All 160 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), fInbound(conn_type_in == ConnectionType::INBOUND), | addrBind(addrBindIn), 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; | ||||
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn; | addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn; | ||||
hashContinue = BlockHash(); | hashContinue = BlockHash(); | ||||
▲ Show 20 Lines • Show All 158 Lines • Show Last 20 Lines |