Skip to content

Commit

Permalink
Merge #2586: [Cleanup] Remove fNetworkNode and pnodeLocalHost, and en…
Browse files Browse the repository at this point in the history
…capsulate CNode id.

37f2238 net: make CNode's id private (Cory Fields)
e83e5d6 scripted-diff: net: Use accessor rather than node's id directly (furszy)
8de5486 Remove pnodeLocalHost. (Gregory Maxwell)
8bd8694 Remove fNetworkNode. (furszy)

Pull request description:

  Coming straight from upstream:

  bitcoin#9226
  bitcoin#10189

  Initial steps towards the DMNs quorum connections work.

ACKs for top commit:
  random-zebra:
    ACK 37f2238

Tree-SHA512: aec92cf700b21a11721f907b6a055ded5f3fcb96e10f36fa78733f7ad6794ec89d66acb92f1d1779c51b5aef9440758400fa4edad028b315556cdf94cad5e53f
  • Loading branch information
furszy committed Nov 21, 2021
2 parents ce94ee6 + 37f2238 commit 6b4790d
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 62 deletions.
32 changes: 7 additions & 25 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ bool fListen = true;
RecursiveMutex cs_mapLocalHost;
std::map<CNetAddr, LocalServiceInfo> mapLocalHost;
static bool vfLimited[NET_MAX] = {};
static CNode* pnodeLocalHost = NULL;
std::string strSubVersion;

limitedmap<CInv, int64_t> mapAlreadyAskedFor(MAX_INV_SZ);
Expand Down Expand Up @@ -926,7 +925,7 @@ bool CConnman::AttemptToEvictConnection(bool fPreferNewConnection)
continue;
if (node->fDisconnect)
continue;
NodeEvictionCandidate candidate = {node->id, node->nTimeConnected, node->nMinPingUsecTime, node->addr, node->nKeyedNetGroup};
NodeEvictionCandidate candidate = {node->GetId(), node->nTimeConnected, node->nMinPingUsecTime, node->addr, node->nKeyedNetGroup};
vEvictionCandidates.push_back(candidate);
}
}
Expand Down Expand Up @@ -1085,8 +1084,7 @@ void CConnman::ThreadSocketHandler()
pnode->CloseSocketDisconnect();

// hold in disconnected pool until all refs are released
if (pnode->fNetworkNode || pnode->fInbound)
pnode->Release();
pnode->Release();
vNodesDisconnected.push_back(pnode);
}
}
Expand Down Expand Up @@ -1308,7 +1306,7 @@ void CConnman::ThreadSocketHandler()
int64_t nTime = GetSystemTimeInSeconds();
if (nTime - pnode->nTimeConnected > 60) {
if (pnode->nLastRecv == 0 || pnode->nLastSend == 0) {
LogPrint(BCLog::NET, "socket no message in first 60 seconds, %d %d from %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0, pnode->id);
LogPrint(BCLog::NET, "socket no message in first 60 seconds, %d %d from %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0, pnode->GetId());
pnode->fDisconnect = true;
} else if (nTime - pnode->nLastSend > TIMEOUT_INTERVAL) {
LogPrintf("socket sending timeout: %is\n", nTime - pnode->nLastSend);
Expand Down Expand Up @@ -1701,7 +1699,6 @@ bool CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
return false;
if (grantOutbound)
grantOutbound->MoveTo(pnode->grantOutbound);
pnode->fNetworkNode = true;
if (fOneShot)
pnode->fOneShot = true;
if (fFeeler)
Expand Down Expand Up @@ -1973,17 +1970,6 @@ bool CConnman::Start(CScheduler& scheduler, std::string& strNodeError, Options c
semOutbound = std::make_unique<CSemaphore>(std::min((nMaxOutbound + nMaxFeeler), nMaxConnections));
}

if (pnodeLocalHost == nullptr) {
CNetAddr local;
LookupHost("127.0.0.1", local, false);

NodeId id = GetNewNodeId();
uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE).Write(id).Finalize();

pnodeLocalHost = new CNode(id, nLocalServices, GetBestHeight(), INVALID_SOCKET, CAddress(CService(local, 0), nLocalServices), 0, nonce);
m_msgproc->InitializeNode(pnodeLocalHost);
}

//
// Start threads
//
Expand Down Expand Up @@ -2098,9 +2084,6 @@ void CConnman::Stop()
vNodesDisconnected.clear();
vhListenSocket.clear();
semOutbound.reset();
if(pnodeLocalHost)
DeleteNode(pnodeLocalHost);
pnodeLocalHost = NULL;
}

void CConnman::DeleteNode(CNode* pnode)
Expand Down Expand Up @@ -2209,7 +2192,7 @@ bool CConnman::DisconnectNode(NodeId id)
{
LOCK(cs_vNodes);
for(CNode* pnode : vNodes) {
if (id == pnode->id) {
if (id == pnode->GetId()) {
pnode->fDisconnect = true;
return true;
}
Expand Down Expand Up @@ -2284,10 +2267,10 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
nTimeConnected(GetSystemTimeInSeconds()),
addr(addrIn),
fInbound(fInboundIn),
id(idIn),
nKeyedNetGroup(nKeyedNetGroupIn),
addrKnown(5000, 0.001),
filterInventoryKnown(50000, 0.000001),
id(idIn),
nLocalHostNonce(nLocalHostNonceIn),
nLocalServices(nLocalServicesIn),
nMyStartingHeight(nMyStartingHeightIn),
Expand All @@ -2309,7 +2292,6 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
fOneShot = false;
fClient = false; // set by version message
fFeeler = false;
fNetworkNode = false;
fSuccessfullyConnected = false;
fDisconnect = false;
nRefCount = 0;
Expand Down Expand Up @@ -2402,7 +2384,7 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
{
size_t nMessageSize = msg.data.size();
size_t nTotalSize = nMessageSize + CMessageHeader::HEADER_SIZE;
LogPrint(BCLog::NET, "sending %s (%d bytes) peer=%d\n", SanitizeString(msg.command.c_str()), nMessageSize, pnode->id);
LogPrint(BCLog::NET, "sending %s (%d bytes) peer=%d\n", SanitizeString(msg.command.c_str()), nMessageSize, pnode->GetId());

std::vector<unsigned char> serializedHeader;
serializedHeader.reserve(CMessageHeader::HEADER_SIZE);
Expand Down Expand Up @@ -2440,7 +2422,7 @@ bool CConnman::ForNode(NodeId id, std::function<bool(CNode* pnode)> func)
CNode* found = nullptr;
LOCK(cs_vNodes);
for (auto&& pnode : vNodes) {
if(pnode->id == id) {
if(pnode->GetId() == id) {
found = pnode;
break;
}
Expand Down
3 changes: 1 addition & 2 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,6 @@ class CNode
bool fOneShot;
bool fClient;
const bool fInbound;
bool fNetworkNode;
/**
* Whether the peer has signaled support for receiving ADDRv2 (BIP155)
* messages, implying a preference to receive ADDRv2 instead of ADDR ones.
Expand All @@ -612,7 +611,6 @@ class CNode
RecursiveMutex cs_filter;
std::unique_ptr<CBloomFilter> pfilter;
std::atomic<int> nRefCount;
const NodeId id;

const uint64_t nKeyedNetGroup;
std::atomic_bool fPauseRecv;
Expand Down Expand Up @@ -675,6 +673,7 @@ class CNode
CNode& operator=(const CNode&) = delete;

private:
const NodeId id;
const uint64_t nLocalHostNonce;
// Services offered to this peer
const ServiceFlags nLocalServices;
Expand Down
Loading

0 comments on commit 6b4790d

Please sign in to comment.