From ac0270871cdf04ad0cd25fd190281d3f23e3363a Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 22 Sep 2019 23:48:15 +0300 Subject: [PATCH] Respect `logips` config option in few more log outputs (#3078) * Introduce CNode::GetLogString() and use it where appropriate * All other cases * fix typo * drop useless argument --- src/addrman.cpp | 4 ++- src/governance/governance.cpp | 4 +-- src/masternode/masternode-utils.cpp | 6 +++- src/net.cpp | 48 +++++++++++++++++++++----- src/net.h | 2 ++ src/net_processing.cpp | 6 ++-- src/privatesend/privatesend-server.cpp | 6 +++- 7 files changed, 59 insertions(+), 17 deletions(-) diff --git a/src/addrman.cpp b/src/addrman.cpp index 2bbf11385b..b4d4526f77 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -248,7 +248,9 @@ void CAddrMan::Good_(const CService& addr, int64_t nTime) if (nUBucket == -1) return; - LogPrint(BCLog::ADDRMAN, "Moving %s to tried\n", addr.ToString()); + if (fLogIPs) { + LogPrint(BCLog::ADDRMAN, "Moving %s to tried\n", addr.ToString()); + } // move nId to the tried tables MakeTried(info, nId); diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index 1f23ecd920..15ade9c286 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -121,7 +121,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& strComm } else { SyncSingleObjVotes(pfrom, nProp, filter, connman); } - LogPrint(BCLog::GOBJECT, "MNGOVERNANCESYNC -- syncing governance objects to our peer at %s\n", pfrom->addr.ToString()); + LogPrint(BCLog::GOBJECT, "MNGOVERNANCESYNC -- syncing governance objects to our peer %s\n", pfrom->GetLogString()); } // A NEW GOVERNANCE OBJECT HAS ARRIVED @@ -320,7 +320,7 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CConnman } } - LogPrintf("CGovernanceManager::AddGovernanceObject -- %s new, received from %s\n", strHash, pfrom ? pfrom->GetAddrName() : "nullptr"); + LogPrintf("CGovernanceManager::AddGovernanceObject -- %s new, received from peer %s\n", strHash, pfrom ? pfrom->GetLogString() : "nullptr"); govobj.Relay(connman); // Update the rate buffer diff --git a/src/masternode/masternode-utils.cpp b/src/masternode/masternode-utils.cpp index d4abbe81af..e72d730b40 100644 --- a/src/masternode/masternode-utils.cpp +++ b/src/masternode/masternode-utils.cpp @@ -39,7 +39,11 @@ void CMasternodeUtils::ProcessMasternodeConnections(CConnman& connman) } if (fFound) return; // do NOT disconnect mixing masternodes #endif // ENABLE_WALLET - LogPrintf("Closing Masternode connection: peer=%d, addr=%s\n", pnode->GetId(), pnode->addr.ToString()); + if (fLogIPs) { + LogPrintf("Closing Masternode connection: peer=%d, addr=%s\n", pnode->GetId(), pnode->addr.ToString()); + } else { + LogPrintf("Closing Masternode connection: peer=%d\n", pnode->GetId()); + } pnode->fDisconnect = true; } }); diff --git a/src/net.cpp b/src/net.cpp index d122c09e85..1160f278d7 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -392,9 +392,14 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo } /// debug print - LogPrint(BCLog::NET, "trying connection %s lastseen=%.1fhrs\n", - pszDest ? pszDest : addrConnect.ToString(), - pszDest ? 0.0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0); + if (fLogIPs) { + LogPrint(BCLog::NET, "trying connection %s lastseen=%.1fhrs\n", + pszDest ? pszDest : addrConnect.ToString(), + pszDest ? 0.0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0); + } else { + LogPrint(BCLog::NET, "trying connection lastseen=%.1fhrs\n", + pszDest ? 0.0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0); + } // Connect SOCKET hSocket; @@ -655,6 +660,11 @@ void CNode::SetAddrLocal(const CService& addrLocalIn) { } } +std::string CNode::GetLogString() const +{ + return fLogIPs ? addr.ToString() : strprintf("%d", id); +} + #undef X #define X(name) stats.name = name void CNode::copyStats(CNodeStats &stats) @@ -1131,15 +1141,22 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) { return; } + std::string strDropped; + if (fLogIPs) { + strDropped = strprintf("connection from %s dropped", addr.ToString()); + } else { + strDropped = "connection dropped"; + } + if (!fNetworkActive) { - LogPrintf("connection from %s dropped: not accepting new connections\n", addr.ToString()); + LogPrintf("%s: not accepting new connections\n", strDropped); CloseSocket(hSocket); return; } if (!IsSelectableSocket(hSocket)) { - LogPrintf("connection from %s dropped: non-selectable socket\n", addr.ToString()); + LogPrintf("%s: non-selectable socket\n", strDropped); CloseSocket(hSocket); return; } @@ -1150,7 +1167,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) { if (IsBanned(addr) && !whitelisted) { - LogPrintf("connection from %s dropped (banned)\n", addr.ToString()); + LogPrintf("%s (banned)\n", strDropped); CloseSocket(hSocket); return; } @@ -1187,7 +1204,11 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) { pnode->fWhitelisted = whitelisted; GetNodeSignals().InitializeNode(pnode, *this); - LogPrint(BCLog::NET, "connection from %s accepted\n", addr.ToString()); + if (fLogIPs) { + LogPrint(BCLog::NET, "connection from %s accepted\n", addr.ToString()); + } else { + LogPrint(BCLog::NET, "connection accepted\n"); + } { LOCK(cs_vNodes); @@ -1211,8 +1232,13 @@ void CConnman::ThreadSocketHandler() { if (pnode->fDisconnect) { - LogPrintf("ThreadSocketHandler -- removing node: peer=%d addr=%s nRefCount=%d fInbound=%d fMasternode=%d\n", + if (fLogIPs) { + LogPrintf("ThreadSocketHandler -- removing node: peer=%d addr=%s nRefCount=%d fInbound=%d fMasternode=%d\n", pnode->GetId(), pnode->addr.ToString(), pnode->GetRefCount(), pnode->fInbound, pnode->fMasternode); + } else { + LogPrintf("ThreadSocketHandler -- removing node: peer=%d nRefCount=%d fInbound=%d fMasternode=%d\n", + pnode->GetId(), pnode->GetRefCount(), pnode->fInbound, pnode->fMasternode); + } // remove from vNodes vNodes.erase(remove(vNodes.begin(), vNodes.end(), pnode), vNodes.end()); @@ -1957,7 +1983,11 @@ void CConnman::ThreadOpenConnections() int randsleep = GetRandInt(FEELER_SLEEP_WINDOW * 1000); if (!interruptNet.sleep_for(std::chrono::milliseconds(randsleep))) return; - LogPrint(BCLog::NET, "Making feeler connection to %s\n", addrConnect.ToString()); + if (fLogIPs) { + LogPrint(BCLog::NET, "Making feeler connection to %s\n", addrConnect.ToString()); + } else { + LogPrint(BCLog::NET, "Making feeler connection\n"); + } } OpenNetworkConnection(addrConnect, (int)setConnected.size() >= std::min(nMaxConnections - 1, 2), &grant, nullptr, false, fFeeler); diff --git a/src/net.h b/src/net.h index bfe9b32e4f..b3fd255a7e 100644 --- a/src/net.h +++ b/src/net.h @@ -1020,6 +1020,8 @@ public: std::string GetAddrName() const; //! Sets the addrName only if it was not previously set void MaybeSetAddrName(const std::string& addrNameIn); + + std::string GetLogString() const; }; class CExplicitNetCleanup diff --git a/src/net_processing.cpp b/src/net_processing.cpp index ffe5e7e480..2d3dc4e8d0 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2987,13 +2987,13 @@ static bool SendRejectsAndCheckIfBanned(CNode* pnode, CConnman& connman) if (state.fShouldBan) { state.fShouldBan = false; if (pnode->fWhitelisted) - LogPrintf("Warning: not punishing whitelisted peer %s!\n", pnode->addr.ToString()); + LogPrintf("Warning: not punishing whitelisted peer %s!\n", pnode->GetLogString()); else if (pnode->fAddnode) - LogPrintf("Warning: not punishing addnoded peer %s!\n", pnode->addr.ToString()); + LogPrintf("Warning: not punishing addnoded peer %s!\n", pnode->GetLogString()); else { pnode->fDisconnect = true; if (pnode->addr.IsLocal()) - LogPrintf("Warning: not banning local peer %s!\n", pnode->addr.ToString()); + LogPrintf("Warning: not banning local peer %s!\n", pnode->GetLogString()); else { connman.Ban(pnode->addr, BanReasonNodeMisbehaving); diff --git a/src/privatesend/privatesend-server.cpp b/src/privatesend/privatesend-server.cpp index 061c6e12db..eee8456018 100644 --- a/src/privatesend/privatesend-server.cpp +++ b/src/privatesend/privatesend-server.cpp @@ -72,7 +72,11 @@ void CPrivateSendServer::ProcessMessage(CNode* pfrom, const std::string& strComm int64_t nLastDsq = mmetaman.GetMetaInfo(dmn->proTxHash)->GetLastDsq(); if (nLastDsq != 0 && nLastDsq + mnList.GetValidMNsCount() / 5 > mmetaman.GetDsqCount()) { - LogPrint(BCLog::PRIVATESEND, "DSACCEPT -- last dsq too recent, must wait: addr=%s\n", pfrom->addr.ToString()); + if (fLogIPs) { + LogPrint(BCLog::PRIVATESEND, "DSACCEPT -- last dsq too recent, must wait: peer=%d, addr=%s\n", pfrom->GetId(), pfrom->addr.ToString()); + } else { + LogPrint(BCLog::PRIVATESEND, "DSACCEPT -- last dsq too recent, must wait: peer=%d\n", pfrom->GetId()); + } PushStatus(pfrom, STATUS_REJECTED, ERR_RECENT, connman); return; }