From 8bd8694819469f49f47446c7c4558508c4502608 Mon Sep 17 00:00:00 2001 From: furszy Date: Wed, 6 Oct 2021 17:27:30 -0300 Subject: [PATCH 1/4] Remove fNetworkNode. Coming from btc@083f20369878196785151e038e5f5126fed74021 --- src/net.cpp | 5 +---- src/net.h | 1 - src/net_processing.cpp | 4 ++-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index b0211ff6d0630..915a1a3cc24c9 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1085,8 +1085,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); } } @@ -1701,7 +1700,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) @@ -2298,7 +2296,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; diff --git a/src/net.h b/src/net.h index b9b1648742f5c..740cef41bbade 100644 --- a/src/net.h +++ b/src/net.h @@ -577,7 +577,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. diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 2f0f384e55ab3..6fab51a9b82d2 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1278,8 +1278,8 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR if (strCommand == NetMsgType::VERACK) { pfrom->SetRecvVersion(std::min(pfrom->nVersion.load(), PROTOCOL_VERSION)); - // Mark this node as currently connected, so we update its timestamp later. - if (pfrom->fNetworkNode) { + if (!pfrom->fInbound) { + // Mark this node as currently connected, so we update its timestamp later. LOCK(cs_main); State(pfrom->GetId())->fCurrentlyConnected = true; } From 8de548694a06e99d8a0d870c07f23e92e24ea39a Mon Sep 17 00:00:00 2001 From: Gregory Maxwell Date: Wed, 6 Oct 2021 17:29:46 -0300 Subject: [PATCH 2/4] Remove pnodeLocalHost. Mostly a legacy of the long removed pub/sub system --- src/net.cpp | 15 --------------- test/functional/p2p_addr_relay.py | 4 ++-- test/functional/p2p_addrv2_relay.py | 4 ++-- test/functional/p2p_invalid_messages.py | 4 ++-- 4 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 915a1a3cc24c9..67b5b7972c8de 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -71,7 +71,6 @@ bool fListen = true; RecursiveMutex cs_mapLocalHost; std::map mapLocalHost; static bool vfLimited[NET_MAX] = {}; -static CNode* pnodeLocalHost = NULL; std::string strSubVersion; limitedmap mapAlreadyAskedFor(MAX_INV_SZ); @@ -1971,17 +1970,6 @@ bool CConnman::Start(CScheduler& scheduler, std::string& strNodeError, Options c semOutbound = std::make_unique(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 // @@ -2096,9 +2084,6 @@ void CConnman::Stop() vNodesDisconnected.clear(); vhListenSocket.clear(); semOutbound.reset(); - if(pnodeLocalHost) - DeleteNode(pnodeLocalHost); - pnodeLocalHost = NULL; } void CConnman::DeleteNode(CNode* pnode) diff --git a/test/functional/p2p_addr_relay.py b/test/functional/p2p_addr_relay.py index 66bb463f2374a..1c92df28c00f4 100755 --- a/test/functional/p2p_addr_relay.py +++ b/test/functional/p2p_addr_relay.py @@ -59,8 +59,8 @@ def run_test(self): msg.addrs = ADDRS with self.nodes[0].assert_debug_log([ 'Added 10 addresses from 127.0.0.1: 0 tried', - 'received: addr (301 bytes) peer=1', - 'sending addr (301 bytes) peer=2', + 'received: addr (301 bytes) peer=0', + 'sending addr (301 bytes) peer=1', ]): addr_source.send_and_ping(msg) self.nodes[0].setmocktime(int(time.time()) + 30 * 60) diff --git a/test/functional/p2p_addrv2_relay.py b/test/functional/p2p_addrv2_relay.py index b6cb9b19f0030..3f6b681f232ec 100755 --- a/test/functional/p2p_addrv2_relay.py +++ b/test/functional/p2p_addrv2_relay.py @@ -64,8 +64,8 @@ def run_test(self): msg.addrs = ADDRS with self.nodes[0].assert_debug_log([ 'Added 10 addresses from 127.0.0.1: 0 tried', - 'received: addrv2 (131 bytes) peer=1', - 'sending addrv2 (131 bytes) peer=2', + 'received: addrv2 (131 bytes) peer=0', + 'sending addrv2 (131 bytes) peer=1', ]): addr_source.send_and_ping(msg) self.nodes[0].setmocktime(int(time.time()) + 30 * 60) diff --git a/test/functional/p2p_invalid_messages.py b/test/functional/p2p_invalid_messages.py index a5a29ba9e4b40..2e088f9e3381a 100755 --- a/test/functional/p2p_invalid_messages.py +++ b/test/functional/p2p_invalid_messages.py @@ -179,10 +179,10 @@ def test_addrv2_unrecognized_network(self): def test_large_inv(self): conn = self.nodes[0].add_p2p_connection(P2PInterface()) - with self.nodes[0].assert_debug_log(['Misbehaving', 'peer=9 (0 -> 20): message inv size() = 50001']): + with self.nodes[0].assert_debug_log(['Misbehaving', 'peer=8 (0 -> 20): message inv size() = 50001']): msg = messages.msg_inv([messages.CInv(1, 1)] * 50001) conn.send_and_ping(msg) - with self.nodes[0].assert_debug_log(['Misbehaving', 'peer=9 (20 -> 40): message getdata size() = 50001']): + with self.nodes[0].assert_debug_log(['Misbehaving', 'peer=8 (20 -> 40): message getdata size() = 50001']): msg = messages.msg_getdata([messages.CInv(1, 1)] * 50001) conn.send_and_ping(msg) self.nodes[0].disconnect_p2ps() From e83e5d60ef809908e81168abf95b9123d4fc4bfa Mon Sep 17 00:00:00 2001 From: furszy Date: Wed, 6 Oct 2021 18:17:57 -0300 Subject: [PATCH 3/4] scripted-diff: net: Use accessor rather than node's id directly -BEGIN VERIFY SCRIPT- sed -i "s/\(node\|to\|from\)->id/\1->GetId()/" src/net.cpp src/net_processing.cpp src/tiertwo_networksync.cpp -END VERIFY SCRIPT- --- src/net.cpp | 10 ++++---- src/net_processing.cpp | 48 ++++++++++++++++++------------------- src/tiertwo_networksync.cpp | 6 ++--- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 67b5b7972c8de..cfc878f0916fa 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -925,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); } } @@ -1306,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); @@ -2192,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; } @@ -2361,7 +2361,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 serializedHeader; serializedHeader.reserve(CMessageHeader::HEADER_SIZE); @@ -2399,7 +2399,7 @@ bool CConnman::ForNode(NodeId id, std::function func) CNode* found = nullptr; LOCK(cs_vNodes); for (auto&& pnode : vNodes) { - if(pnode->id == id) { + if(pnode->GetId() == id) { found = pnode; break; } diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 6fab51a9b82d2..8a0398550ed6f 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -837,7 +837,7 @@ static void RelayAddress(const CAddress& addr, bool fReachable, CConnman* connma const CSipHasher hasher = connman->GetDeterministicRandomizer(RANDOMIZER_ID_ADDRESS_RELAY).Write(hashAddr << 32).Write((GetTime() + hashAddr) / (24*60*60)); auto sortfunc = [&mapMix, &hasher](CNode* pnode) { - uint64_t hashKey = CSipHasher(hasher).Write(pnode->id).Finalize(); + uint64_t hashKey = CSipHasher(hasher).Write(pnode->GetId()).Finalize(); mapMix.emplace(hashKey, pnode); }; @@ -1089,7 +1089,7 @@ void static ProcessGetData(CNode* pfrom, CConnman* connman, const std::atomic& interruptMsgProc) { - LogPrint(BCLog::NET, "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id); + LogPrint(BCLog::NET, "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->GetId()); if (gArgs.IsArgSet("-dropmessagestest") && GetRand(gArgs.GetArg("-dropmessagestest", 0)) == 0) { LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n"); return true; @@ -1121,7 +1121,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR connman->SetServices(pfrom->addr, nServices); } if (pfrom->nServicesExpected & ~nServices) { - LogPrint(BCLog::NET, "peer=%d does not offer the expected services (%08x offered, %08x expected); disconnecting\n", pfrom->id, nServices, pfrom->nServicesExpected); + LogPrint(BCLog::NET, "peer=%d does not offer the expected services (%08x offered, %08x expected); disconnecting\n", pfrom->GetId(), nServices, pfrom->nServicesExpected); pfrom->fDisconnect = true; return false; } @@ -1226,7 +1226,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR LogPrint(BCLog::NET, "receive version message: %s: version %d, blocks=%d, us=%s, peer=%d%s\n", cleanSubVer, pfrom->nVersion, - pfrom->nStartingHeight, addrMe.ToString(), pfrom->id, + pfrom->nStartingHeight, addrMe.ToString(), pfrom->GetId(), remoteAddr); int64_t nTimeOffset = nTime - GetTime(); @@ -1371,7 +1371,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR pfrom->AddInventoryKnown(inv); bool fAlreadyHave = AlreadyHave(inv); - LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom->id); + LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom->GetId()); if (!fAlreadyHave && !fImporting && !fReindex && inv.type != MSG_BLOCK) pfrom->AskFor(inv); @@ -1382,7 +1382,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) { // Add this to the list of blocks to request vToFetch.push_back(inv); - LogPrint(BCLog::NET, "getblocks (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->id); + LogPrint(BCLog::NET, "getblocks (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->GetId()); } } @@ -1403,10 +1403,10 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR } if (vInv.size() != 1) - LogPrint(BCLog::NET, "received getdata (%u invsz) peer=%d\n", vInv.size(), pfrom->id); + LogPrint(BCLog::NET, "received getdata (%u invsz) peer=%d\n", vInv.size(), pfrom->GetId()); if (vInv.size() > 0) - LogPrint(BCLog::NET, "received getdata for: %s peer=%d\n", vInv[0].ToString(), pfrom->id); + LogPrint(BCLog::NET, "received getdata for: %s peer=%d\n", vInv[0].ToString(), pfrom->GetId()); pfrom->vRecvGetData.insert(pfrom->vRecvGetData.end(), vInv.begin(), vInv.end()); ProcessGetData(pfrom, connman, interruptMsgProc); @@ -1433,7 +1433,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR if (pindex) pindex = chainActive.Next(pindex); int nLimit = 500; - LogPrint(BCLog::NET, "getblocks %d to %s limit %d from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.IsNull() ? "end" : hashStop.ToString(), nLimit, pfrom->id); + LogPrint(BCLog::NET, "getblocks %d to %s limit %d from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.IsNull() ? "end" : hashStop.ToString(), nLimit, pfrom->GetId()); for (; pindex; pindex = chainActive.Next(pindex)) { if (pindex->GetBlockHash() == hashStop) { LogPrint(BCLog::NET, " getblocks stopping at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString()); @@ -1484,7 +1484,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR // we must use CBlocks, as CBlockHeaders won't include the 0x00 nTx count at the end std::vector vHeaders; int nLimit = MAX_HEADERS_RESULTS; - LogPrintf("getheaders %d to %s from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString(), pfrom->id); + LogPrintf("getheaders %d to %s from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString(), pfrom->GetId()); for (; pindex; pindex = chainActive.Next(pindex)) { vHeaders.push_back(pindex->GetBlockHeader()); if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop) @@ -1526,7 +1526,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR } LogPrint(BCLog::MEMPOOL, "%s : peer=%d %s : accepted %s (poolsz %u txn, %u kB)\n", - __func__, pfrom->id, pfrom->cleanSubVer, tx.GetHash().ToString(), + __func__, pfrom->GetId(), pfrom->cleanSubVer, tx.GetHash().ToString(), mempool.size(), mempool.DynamicMemoryUsage() / 1000); // Recursively process any orphan transactions that depended on this one @@ -1637,7 +1637,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR int nDoS = 0; if (state.IsInvalid(nDoS)) { LogPrint(BCLog::MEMPOOLREJ, "%s from peer=%d %s was not accepted into the memory pool: %s\n", tx.GetHash().ToString(), - pfrom->id, pfrom->cleanSubVer, + pfrom->GetId(), pfrom->cleanSubVer, FormatStateMessage(state)); if (nDoS > 0) { Misbehaving(pfrom->GetId(), nDoS); @@ -1699,7 +1699,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR // Headers message had its maximum size; the peer may have more headers. // TODO: optimize: if pindexLast is an ancestor of chainActive.Tip or pindexBestHeader, continue // from there instead. - LogPrintf("more getheaders (%d) to end to peer=%d (startheight:%d)\n", pindexLast->nHeight, pfrom->id, pfrom->nStartingHeight); + LogPrintf("more getheaders (%d) to end to peer=%d (startheight:%d)\n", pindexLast->nHeight, pfrom->GetId(), pfrom->nStartingHeight); connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::GETHEADERS, chainActive.GetLocator(pindexLast), UINT256_ZERO)); } } @@ -1710,7 +1710,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR vRecv >> *pblock; const uint256& hashBlock = pblock->GetHash(); CInv inv(MSG_BLOCK, hashBlock); - LogPrint(BCLog::NET, "received block %s peer=%d\n", inv.hash.ToString(), pfrom->id); + LogPrint(BCLog::NET, "received block %s peer=%d\n", inv.hash.ToString(), pfrom->GetId()); // sometimes we will be sent their most recent block and its not the one we want, in that case tell where we are if (!mapBlockIndex.count(pblock->hashPrevBlock)) { @@ -1833,7 +1833,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR if (!(sProblem.empty())) { LogPrint(BCLog::NET, "pong peer=%d %s: %s, %x expected, %x received, %u bytes\n", - pfrom->id, + pfrom->GetId(), pfrom->cleanSubVer, sProblem, pfrom->nPingNonceSent, @@ -1917,7 +1917,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR } } else { // Ignore unknown commands for extensibility - LogPrint(BCLog::NET, "Unknown command \"%s\" from peer=%d\n", SanitizeString(strCommand), pfrom->id); + LogPrint(BCLog::NET, "Unknown command \"%s\" from peer=%d\n", SanitizeString(strCommand), pfrom->GetId()); } } @@ -1965,7 +1965,7 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic& inter msg.SetVersion(pfrom->GetRecvVersion()); // Scan for message start if (memcmp(msg.hdr.pchMessageStart, Params().MessageStart(), MESSAGE_START_SIZE) != 0) { - LogPrint(BCLog::NET, "PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n", SanitizeString(msg.hdr.GetCommand()), pfrom->id); + LogPrint(BCLog::NET, "PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n", SanitizeString(msg.hdr.GetCommand()), pfrom->GetId()); pfrom->fDisconnect = true; return false; } @@ -1973,7 +1973,7 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic& inter // Read header CMessageHeader& hdr = msg.hdr; if (!hdr.IsValid(Params().MessageStart())) { - LogPrint(BCLog::NET, "PROCESSMESSAGE: ERRORS IN HEADER '%s' peer=%d\n", SanitizeString(hdr.GetCommand()), pfrom->id); + LogPrint(BCLog::NET, "PROCESSMESSAGE: ERRORS IN HEADER '%s' peer=%d\n", SanitizeString(hdr.GetCommand()), pfrom->GetId()); return fMoreWork; } std::string strCommand = hdr.GetCommand(); @@ -2018,7 +2018,7 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic& inter } if (!fRet) - LogPrint(BCLog::NET, "ProcessMessage(%s, %u bytes) FAILED peer=%d\n", SanitizeString(strCommand), nMessageSize, pfrom->id); + LogPrint(BCLog::NET, "ProcessMessage(%s, %u bytes) FAILED peer=%d\n", SanitizeString(strCommand), nMessageSize, pfrom->GetId()); return fMoreWork; } @@ -2147,7 +2147,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic& interruptM state.fSyncStarted = true; nSyncStarted++; //CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; - //LogPrint(BCLog::NET, "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->id, pto->nStartingHeight); + //LogPrint(BCLog::NET, "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->GetId(), pto->nStartingHeight); //pto->PushMessage(NetMsgType::GETHEADERS, chainActive.GetLocator(pindexStart), UINT256_ZERO); connman->PushMessage(pto, msgMaker.Make(NetMsgType::GETBLOCKS, chainActive.GetLocator(chainActive.Tip()), UINT256_ZERO)); } @@ -2284,7 +2284,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic& interruptM // Stalling only triggers when the block download window cannot move. During normal steady state, // the download window should be much larger than the to-be-downloaded set of blocks, so disconnection // should only happen during initial block download. - LogPrintf("Peer=%d is stalling block download, disconnecting\n", pto->id); + LogPrintf("Peer=%d is stalling block download, disconnecting\n", pto->GetId()); pto->fDisconnect = true; return true; } @@ -2294,7 +2294,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic& interruptM // being saturated. We only count validated in-flight blocks so peers can't advertise nonexisting block hashes // to unreasonably increase our timeout. if (state.vBlocksInFlight.size() > 0 && state.vBlocksInFlight.front().nTime < nNow - 500000 * Params().GetConsensus().nTargetSpacing * (4 + state.vBlocksInFlight.front().nValidatedQueuedBefore)) { - LogPrintf("Timeout downloading block %s from peer=%d, disconnecting\n", state.vBlocksInFlight.front().hash.ToString(), pto->id); + LogPrintf("Timeout downloading block %s from peer=%d, disconnecting\n", state.vBlocksInFlight.front().hash.ToString(), pto->GetId()); pto->fDisconnect = true; return true; } @@ -2311,7 +2311,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic& interruptM vGetData.emplace_back(MSG_BLOCK, pindex->GetBlockHash()); MarkBlockAsInFlight(pto->GetId(), pindex->GetBlockHash(), pindex); LogPrintf("Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(), - pindex->nHeight, pto->id); + pindex->nHeight, pto->GetId()); } if (state.nBlocksInFlight == 0 && staller != -1) { if (State(staller)->nStallingSince == 0) { @@ -2327,7 +2327,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic& interruptM while (!pto->mapAskFor.empty() && (*pto->mapAskFor.begin()).first <= nNow) { const CInv& inv = (*pto->mapAskFor.begin()).second; if (!AlreadyHave(inv)) { - LogPrint(BCLog::NET, "Requesting %s peer=%d\n", inv.ToString(), pto->id); + LogPrint(BCLog::NET, "Requesting %s peer=%d\n", inv.ToString(), pto->GetId()); vGetData.push_back(inv); if (vGetData.size() >= 1000) { connman->PushMessage(pto, msgMaker.Make(NetMsgType::GETDATA, vGetData)); diff --git a/src/tiertwo_networksync.cpp b/src/tiertwo_networksync.cpp index 8f89402de7390..a2dd7f6ef11e2 100644 --- a/src/tiertwo_networksync.cpp +++ b/src/tiertwo_networksync.cpp @@ -128,12 +128,12 @@ void CMasternodeSync::PushMessage(CNode* pnode, const char* msg, Args&&... args) template void CMasternodeSync::RequestDataTo(CNode* pnode, const char* msg, bool forceRequest, Args&&... args) { - const auto& it = peersSyncState.find(pnode->id); + const auto& it = peersSyncState.find(pnode->GetId()); bool exist = it != peersSyncState.end(); if (!exist || forceRequest) { // Erase it if this is a forced request if (exist) { - peersSyncState.at(pnode->id).mapMsgData.erase(msg); + peersSyncState.at(pnode->GetId()).mapMsgData.erase(msg); } // send the message PushMessage(pnode, msg, std::forward(args)...); @@ -141,7 +141,7 @@ void CMasternodeSync::RequestDataTo(CNode* pnode, const char* msg, bool forceReq // Add data to the tier two peers sync state TierTwoPeerData peerData; peerData.mapMsgData.emplace(msg, std::make_pair(GetTime(), false)); - peersSyncState.emplace(pnode->id, peerData); + peersSyncState.emplace(pnode->GetId(), peerData); } else { // Check if we have sent the message or not TierTwoPeerData& peerData = it->second; From 37f2238c013b2fef9ab6db3218cf6d4893157159 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Tue, 11 Apr 2017 12:11:27 -0400 Subject: [PATCH 4/4] net: make CNode's id private --- src/net.cpp | 2 +- src/net.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index cfc878f0916fa..f6a857921dde7 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2256,10 +2256,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), diff --git a/src/net.h b/src/net.h index 740cef41bbade..af8d515a9b8aa 100644 --- a/src/net.h +++ b/src/net.h @@ -593,7 +593,6 @@ class CNode RecursiveMutex cs_filter; std::unique_ptr pfilter; std::atomic nRefCount; - const NodeId id; const uint64_t nKeyedNetGroup; std::atomic_bool fPauseRecv; @@ -656,6 +655,7 @@ class CNode CNode& operator=(const CNode&) = delete; private: + const NodeId id; const uint64_t nLocalHostNonce; // Services offered to this peer const ServiceFlags nLocalServices;