mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
[net/refactor] Remove fInbound flag from CNode
This commit is contained in:
parent
7b322df629
commit
60156f5fc4
21
src/net.cpp
21
src/net.cpp
@ -346,7 +346,7 @@ bool CConnman::CheckIncomingNonce(uint64_t nonce)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (const CNode* pnode : vNodes) {
|
||||
if (!pnode->fSuccessfullyConnected && !pnode->fInbound && pnode->GetLocalNonce() == nonce)
|
||||
if (!pnode->fSuccessfullyConnected && !pnode->IsInboundConn() && pnode->GetLocalNonce() == nonce)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -538,7 +538,7 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
|
||||
LOCK(cs_SubVer);
|
||||
X(cleanSubVer);
|
||||
}
|
||||
X(fInbound);
|
||||
stats.fInbound = IsInboundConn();
|
||||
stats.m_manual_connection = IsManualConn();
|
||||
X(nStartingHeight);
|
||||
{
|
||||
@ -874,7 +874,7 @@ bool CConnman::AttemptToEvictConnection()
|
||||
for (const CNode* node : vNodes) {
|
||||
if (node->HasPermission(PF_NOBAN))
|
||||
continue;
|
||||
if (!node->fInbound)
|
||||
if (!node->IsInboundConn())
|
||||
continue;
|
||||
if (node->fDisconnect)
|
||||
continue;
|
||||
@ -985,7 +985,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (const CNode* pnode : vNodes) {
|
||||
if (pnode->fInbound) nInbound++;
|
||||
if (pnode->IsInboundConn()) nInbound++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1648,7 +1648,7 @@ void CConnman::ThreadDNSAddressSeed()
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (const CNode* pnode : vNodes) {
|
||||
nRelevant += pnode->fSuccessfullyConnected && !pnode->IsFeelerConn() && !pnode->IsAddrFetchConn() && !pnode->IsManualConn() && !pnode->fInbound;
|
||||
nRelevant += pnode->fSuccessfullyConnected && !pnode->IsFeelerConn() && !pnode->IsAddrFetchConn() && !pnode->IsManualConn() && !pnode->IsInboundConn();
|
||||
}
|
||||
}
|
||||
if (nRelevant >= 2) {
|
||||
@ -1758,7 +1758,7 @@ int CConnman::GetExtraOutboundCount()
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (const CNode* pnode : vNodes) {
|
||||
if (!pnode->fInbound && !pnode->IsManualConn() && !pnode->IsFeelerConn() && !pnode->fDisconnect && !pnode->IsAddrFetchConn() && pnode->fSuccessfullyConnected) {
|
||||
if (!pnode->IsInboundConn() && !pnode->IsManualConn() && !pnode->IsFeelerConn() && !pnode->fDisconnect && !pnode->IsAddrFetchConn() && pnode->fSuccessfullyConnected) {
|
||||
++nOutbound;
|
||||
}
|
||||
}
|
||||
@ -1832,7 +1832,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (const CNode* pnode : vNodes) {
|
||||
if (!pnode->fInbound && (pnode->m_conn_type != ConnectionType::MANUAL)) {
|
||||
if (!pnode->IsInboundConn() && (pnode->m_conn_type != ConnectionType::MANUAL)) {
|
||||
// Netgroups for inbound and addnode peers are not excluded because our goal here
|
||||
// is to not use multiple of our limited outbound slots on a single netgroup
|
||||
// but inbound and addnode peers do not use our outbound slots. Inbound peers
|
||||
@ -1972,11 +1972,11 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo()
|
||||
LOCK(cs_vNodes);
|
||||
for (const CNode* pnode : vNodes) {
|
||||
if (pnode->addr.IsValid()) {
|
||||
mapConnected[pnode->addr] = pnode->fInbound;
|
||||
mapConnected[pnode->addr] = pnode->IsInboundConn();
|
||||
}
|
||||
std::string addrName = pnode->GetAddrName();
|
||||
if (!addrName.empty()) {
|
||||
mapConnectedByName[std::move(addrName)] = std::make_pair(pnode->fInbound, static_cast<const CService&>(pnode->addr));
|
||||
mapConnectedByName[std::move(addrName)] = std::make_pair(pnode->IsInboundConn(), static_cast<const CService&>(pnode->addr));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2551,7 +2551,7 @@ size_t CConnman::GetNodeCount(NumConnections flags)
|
||||
|
||||
int nNum = 0;
|
||||
for (const auto& pnode : vNodes) {
|
||||
if (flags & (pnode->fInbound ? CONNECTIONS_IN : CONNECTIONS_OUT)) {
|
||||
if (flags & (pnode->IsInboundConn() ? CONNECTIONS_IN : CONNECTIONS_OUT)) {
|
||||
nNum++;
|
||||
}
|
||||
}
|
||||
@ -2739,7 +2739,6 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
|
||||
: nTimeConnected(GetSystemTimeInSeconds()),
|
||||
addr(addrIn),
|
||||
addrBind(addrBindIn),
|
||||
fInbound(conn_type_in == ConnectionType::INBOUND),
|
||||
nKeyedNetGroup(nKeyedNetGroupIn),
|
||||
// Don't relay addr messages to peers that we connect to as block-relay-only
|
||||
// peers (to prevent adversaries from inferring these links from addr
|
||||
|
@ -777,7 +777,6 @@ public:
|
||||
bool m_legacyWhitelisted{false};
|
||||
bool fClient{false}; // set by version message
|
||||
bool m_limited_node{false}; //after BIP159, set by version message
|
||||
const bool fInbound;
|
||||
std::atomic_bool fSuccessfullyConnected{false};
|
||||
// Setting fDisconnect to true will cause the node to be disconnected the
|
||||
// next time DisconnectNodes() runs
|
||||
@ -802,6 +801,10 @@ public:
|
||||
return m_conn_type == ConnectionType::ADDR_FETCH;
|
||||
}
|
||||
|
||||
bool IsInboundConn() const {
|
||||
return m_conn_type == ConnectionType::INBOUND;
|
||||
}
|
||||
|
||||
protected:
|
||||
mapMsgCmdSize mapSendBytesPerMsgCmd;
|
||||
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
|
||||
|
@ -473,7 +473,7 @@ static void UpdatePreferredDownload(const CNode& node, CNodeState* state) EXCLUS
|
||||
nPreferredDownload -= state->fPreferredDownload;
|
||||
|
||||
// Whether this node should be marked as a preferred download node.
|
||||
state->fPreferredDownload = (!node.fInbound || node.HasPermission(PF_NOBAN)) && !node.IsAddrFetchConn() && !node.fClient;
|
||||
state->fPreferredDownload = (!node.IsInboundConn() || node.HasPermission(PF_NOBAN)) && !node.IsAddrFetchConn() && !node.fClient;
|
||||
|
||||
nPreferredDownload += state->fPreferredDownload;
|
||||
}
|
||||
@ -829,7 +829,7 @@ void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds)
|
||||
|
||||
static bool IsOutboundDisconnectionCandidate(const CNode& node)
|
||||
{
|
||||
return !(node.fInbound || node.IsManualConn() || node.IsFeelerConn() || node.IsAddrFetchConn());
|
||||
return !(node.IsInboundConn() || node.IsManualConn() || node.IsFeelerConn() || node.IsAddrFetchConn());
|
||||
}
|
||||
|
||||
void PeerLogicValidation::InitializeNode(CNode *pnode) {
|
||||
@ -838,9 +838,9 @@ void PeerLogicValidation::InitializeNode(CNode *pnode) {
|
||||
NodeId nodeid = pnode->GetId();
|
||||
{
|
||||
LOCK(cs_main);
|
||||
mapNodeState.emplace_hint(mapNodeState.end(), std::piecewise_construct, std::forward_as_tuple(nodeid), std::forward_as_tuple(addr, std::move(addrName), pnode->fInbound, pnode->IsManualConn()));
|
||||
mapNodeState.emplace_hint(mapNodeState.end(), std::piecewise_construct, std::forward_as_tuple(nodeid), std::forward_as_tuple(addr, std::move(addrName), pnode->IsInboundConn(), pnode->IsManualConn()));
|
||||
}
|
||||
if(!pnode->fInbound)
|
||||
if(!pnode->IsInboundConn())
|
||||
PushNodeVersion(*pnode, *connman, GetTime());
|
||||
}
|
||||
|
||||
@ -2320,11 +2320,11 @@ void ProcessMessage(
|
||||
vRecv >> nVersion >> nServiceInt >> nTime >> addrMe;
|
||||
nSendVersion = std::min(nVersion, PROTOCOL_VERSION);
|
||||
nServices = ServiceFlags(nServiceInt);
|
||||
if (!pfrom.fInbound)
|
||||
if (!pfrom.IsInboundConn())
|
||||
{
|
||||
connman.SetServices(pfrom.addr, nServices);
|
||||
}
|
||||
if (!pfrom.fInbound && !pfrom.IsFeelerConn() && !pfrom.IsManualConn() && !HasAllDesirableServiceFlags(nServices))
|
||||
if (!pfrom.IsInboundConn() && !pfrom.IsFeelerConn() && !pfrom.IsManualConn() && !HasAllDesirableServiceFlags(nServices))
|
||||
{
|
||||
LogPrint(BCLog::NET, "peer=%d does not offer the expected services (%08x offered, %08x expected); disconnecting\n", pfrom.GetId(), nServices, GetDesirableServiceFlags(nServices));
|
||||
pfrom.fDisconnect = true;
|
||||
@ -2351,20 +2351,20 @@ void ProcessMessage(
|
||||
if (!vRecv.empty())
|
||||
vRecv >> fRelay;
|
||||
// Disconnect if we connected to ourself
|
||||
if (pfrom.fInbound && !connman.CheckIncomingNonce(nNonce))
|
||||
if (pfrom.IsInboundConn() && !connman.CheckIncomingNonce(nNonce))
|
||||
{
|
||||
LogPrintf("connected to self at %s, disconnecting\n", pfrom.addr.ToString());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (pfrom.fInbound && addrMe.IsRoutable())
|
||||
if (pfrom.IsInboundConn() && addrMe.IsRoutable())
|
||||
{
|
||||
SeenLocal(addrMe);
|
||||
}
|
||||
|
||||
// Be shy and don't send version until we hear
|
||||
if (pfrom.fInbound)
|
||||
if (pfrom.IsInboundConn())
|
||||
PushNodeVersion(pfrom, connman, GetAdjustedTime());
|
||||
|
||||
if (nVersion >= WTXID_RELAY_VERSION) {
|
||||
@ -2408,7 +2408,7 @@ void ProcessMessage(
|
||||
UpdatePreferredDownload(pfrom, State(pfrom.GetId()));
|
||||
}
|
||||
|
||||
if (!pfrom.fInbound && pfrom.IsAddrRelayPeer())
|
||||
if (!pfrom.IsInboundConn() && pfrom.IsAddrRelayPeer())
|
||||
{
|
||||
// Advertise our address
|
||||
if (fListen && !::ChainstateActive().IsInitialBlockDownload())
|
||||
@ -2472,7 +2472,7 @@ void ProcessMessage(
|
||||
{
|
||||
pfrom.SetRecvVersion(std::min(pfrom.nVersion.load(), PROTOCOL_VERSION));
|
||||
|
||||
if (!pfrom.fInbound) {
|
||||
if (!pfrom.IsInboundConn()) {
|
||||
// Mark this node as currently connected, so we update its timestamp later.
|
||||
LOCK(cs_main);
|
||||
State(pfrom.GetId())->fCurrentlyConnected = true;
|
||||
@ -3452,7 +3452,7 @@ void ProcessMessage(
|
||||
// to users' AddrMan and later request them by sending getaddr messages.
|
||||
// Making nodes which are behind NAT and can only make outgoing connections ignore
|
||||
// the getaddr message mitigates the attack.
|
||||
if (!pfrom.fInbound) {
|
||||
if (!pfrom.IsInboundConn()) {
|
||||
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from outbound connection. peer=%d\n", pfrom.GetId());
|
||||
return;
|
||||
}
|
||||
@ -4279,7 +4279,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
|
||||
bool fSendTrickle = pto->HasPermission(PF_NOBAN);
|
||||
if (pto->m_tx_relay->nNextInvSend < current_time) {
|
||||
fSendTrickle = true;
|
||||
if (pto->fInbound) {
|
||||
if (pto->IsInboundConn()) {
|
||||
pto->m_tx_relay->nNextInvSend = std::chrono::microseconds{connman->PoissonNextSendInbound(nNow, INVENTORY_BROADCAST_INTERVAL)};
|
||||
} else {
|
||||
// Use half the delay for outbound peers, as there is less privacy concern for them.
|
||||
|
@ -182,10 +182,10 @@ BOOST_AUTO_TEST_CASE(cnode_simple_test)
|
||||
std::string pszDest;
|
||||
|
||||
std::unique_ptr<CNode> pnode1 = MakeUnique<CNode>(id++, NODE_NETWORK, height, hSocket, addr, 0, 0, CAddress(), pszDest, ConnectionType::OUTBOUND);
|
||||
BOOST_CHECK(pnode1->fInbound == false);
|
||||
BOOST_CHECK(pnode1->IsInboundConn() == false);
|
||||
|
||||
std::unique_ptr<CNode> pnode2 = MakeUnique<CNode>(id++, NODE_NETWORK, height, hSocket, addr, 1, 1, CAddress(), pszDest, ConnectionType::INBOUND);
|
||||
BOOST_CHECK(pnode2->fInbound == true);
|
||||
BOOST_CHECK(pnode2->IsInboundConn() == true);
|
||||
}
|
||||
|
||||
// prior to PR #14728, this test triggers an undefined behavior
|
||||
|
Loading…
Reference in New Issue
Block a user