Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 1,051 Lines • ▼ Show 20 Lines | if (!IsSelectableSocket(hSocket)) { | ||||
CloseSocket(hSocket); | CloseSocket(hSocket); | ||||
return; | return; | ||||
} | } | ||||
// According to the internet TCP_NODELAY is not carried into accepted | // According to the internet TCP_NODELAY is not carried into accepted | ||||
// sockets on all platforms. Set it again here just to be sure. | // sockets on all platforms. Set it again here just to be sure. | ||||
SetSocketNoDelay(hSocket); | SetSocketNoDelay(hSocket); | ||||
int bannedlevel = m_banman ? m_banman->IsBannedLevel(addr) : 0; | |||||
// Don't accept connections from banned peers. | // Don't accept connections from banned peers. | ||||
bool banned = m_banman->IsBanned(addr); | |||||
if (!NetPermissions::HasFlag(permissionFlags, | if (!NetPermissions::HasFlag(permissionFlags, | ||||
NetPermissionFlags::PF_NOBAN) && | NetPermissionFlags::PF_NOBAN) && | ||||
bannedlevel == 2) { | banned) { | ||||
LogPrint(BCLog::NET, "connection from %s dropped (banned)\n", | LogPrint(BCLog::NET, "connection from %s dropped (banned)\n", | ||||
addr.ToString()); | addr.ToString()); | ||||
CloseSocket(hSocket); | CloseSocket(hSocket); | ||||
return; | return; | ||||
} | } | ||||
// Only accept connections from discouraged peers if our inbound slots | // Only accept connections from discouraged peers if our inbound slots | ||||
// aren't (almost) full. | // aren't (almost) full. | ||||
bool discouraged = m_banman->IsDiscouraged(addr); | |||||
if (!NetPermissions::HasFlag(permissionFlags, | if (!NetPermissions::HasFlag(permissionFlags, | ||||
NetPermissionFlags::PF_NOBAN) && | NetPermissionFlags::PF_NOBAN) && | ||||
nInbound + 1 >= nMaxInbound && bannedlevel >= 1) { | nInbound + 1 >= nMaxInbound && discouraged) { | ||||
LogPrint(BCLog::NET, "connection from %s dropped (discouraged)\n", | LogPrint(BCLog::NET, "connection from %s dropped (discouraged)\n", | ||||
addr.ToString()); | addr.ToString()); | ||||
CloseSocket(hSocket); | CloseSocket(hSocket); | ||||
return; | return; | ||||
} | } | ||||
if (nInbound >= nMaxInbound) { | if (nInbound >= nMaxInbound) { | ||||
if (!AttemptToEvictConnection()) { | if (!AttemptToEvictConnection()) { | ||||
Show All 18 Lines | void CConnman::AcceptConnection(const ListenSocket &hListenSocket) { | ||||
CNode *pnode = | CNode *pnode = | ||||
new CNode(id, nodeServices, GetBestHeight(), hSocket, addr, | new CNode(id, nodeServices, GetBestHeight(), hSocket, addr, | ||||
CalculateKeyedNetGroup(addr), nonce, addr_bind, "", true); | CalculateKeyedNetGroup(addr), nonce, addr_bind, "", true); | ||||
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 = bannedlevel > 0; | 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); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 999 Lines • ▼ Show 20 Lines | void CConnman::OpenNetworkConnection(const CAddress &addrConnect, | ||||
// | // | ||||
if (interruptNet) { | if (interruptNet) { | ||||
return; | return; | ||||
} | } | ||||
if (!fNetworkActive) { | if (!fNetworkActive) { | ||||
return; | return; | ||||
} | } | ||||
if (!pszDest) { | if (!pszDest) { | ||||
bool banned_or_discouraged = | |||||
m_banman && (m_banman->IsDiscouraged(addrConnect) || | |||||
m_banman->IsBanned(addrConnect)); | |||||
if (IsLocal(addrConnect) || | if (IsLocal(addrConnect) || | ||||
FindNode(static_cast<CNetAddr>(addrConnect)) || | FindNode(static_cast<CNetAddr>(addrConnect)) || | ||||
(m_banman && m_banman->IsBanned(addrConnect)) || | banned_or_discouraged || FindNode(addrConnect.ToStringIPPort())) { | ||||
FindNode(addrConnect.ToStringIPPort())) { | |||||
return; | return; | ||||
} | } | ||||
} else if (FindNode(std::string(pszDest))) { | } else if (FindNode(std::string(pszDest))) { | ||||
return; | return; | ||||
} | } | ||||
CNode *pnode = ConnectNode(addrConnect, pszDest, fCountFailure, | CNode *pnode = ConnectNode(addrConnect, pszDest, fCountFailure, | ||||
manual_connection, block_relay_only); | manual_connection, block_relay_only); | ||||
▲ Show 20 Lines • Show All 909 Lines • Show Last 20 Lines |