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
This commit is contained in:
UdjinM6 2019-09-22 23:48:15 +03:00 committed by GitHub
parent d26b6a84cc
commit ac0270871c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 59 additions and 17 deletions

View File

@ -248,7 +248,9 @@ void CAddrMan::Good_(const CService& addr, int64_t nTime)
if (nUBucket == -1) if (nUBucket == -1)
return; 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 // move nId to the tried tables
MakeTried(info, nId); MakeTried(info, nId);

View File

@ -121,7 +121,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& strComm
} else { } else {
SyncSingleObjVotes(pfrom, nProp, filter, connman); 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 // 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); govobj.Relay(connman);
// Update the rate buffer // Update the rate buffer

View File

@ -39,7 +39,11 @@ void CMasternodeUtils::ProcessMasternodeConnections(CConnman& connman)
} }
if (fFound) return; // do NOT disconnect mixing masternodes if (fFound) return; // do NOT disconnect mixing masternodes
#endif // ENABLE_WALLET #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; pnode->fDisconnect = true;
} }
}); });

View File

@ -392,9 +392,14 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
} }
/// debug print /// debug print
LogPrint(BCLog::NET, "trying connection %s lastseen=%.1fhrs\n", if (fLogIPs) {
pszDest ? pszDest : addrConnect.ToString(), LogPrint(BCLog::NET, "trying connection %s lastseen=%.1fhrs\n",
pszDest ? 0.0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0); 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 // Connect
SOCKET hSocket; 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 #undef X
#define X(name) stats.name = name #define X(name) stats.name = name
void CNode::copyStats(CNodeStats &stats) void CNode::copyStats(CNodeStats &stats)
@ -1131,15 +1141,22 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
return; return;
} }
std::string strDropped;
if (fLogIPs) {
strDropped = strprintf("connection from %s dropped", addr.ToString());
} else {
strDropped = "connection dropped";
}
if (!fNetworkActive) { if (!fNetworkActive) {
LogPrintf("connection from %s dropped: not accepting new connections\n", addr.ToString()); LogPrintf("%s: not accepting new connections\n", strDropped);
CloseSocket(hSocket); CloseSocket(hSocket);
return; return;
} }
if (!IsSelectableSocket(hSocket)) if (!IsSelectableSocket(hSocket))
{ {
LogPrintf("connection from %s dropped: non-selectable socket\n", addr.ToString()); LogPrintf("%s: non-selectable socket\n", strDropped);
CloseSocket(hSocket); CloseSocket(hSocket);
return; return;
} }
@ -1150,7 +1167,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
if (IsBanned(addr) && !whitelisted) if (IsBanned(addr) && !whitelisted)
{ {
LogPrintf("connection from %s dropped (banned)\n", addr.ToString()); LogPrintf("%s (banned)\n", strDropped);
CloseSocket(hSocket); CloseSocket(hSocket);
return; return;
} }
@ -1187,7 +1204,11 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
pnode->fWhitelisted = whitelisted; pnode->fWhitelisted = whitelisted;
GetNodeSignals().InitializeNode(pnode, *this); 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); LOCK(cs_vNodes);
@ -1211,8 +1232,13 @@ void CConnman::ThreadSocketHandler()
{ {
if (pnode->fDisconnect) 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); 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 // remove from vNodes
vNodes.erase(remove(vNodes.begin(), vNodes.end(), pnode), vNodes.end()); vNodes.erase(remove(vNodes.begin(), vNodes.end(), pnode), vNodes.end());
@ -1957,7 +1983,11 @@ void CConnman::ThreadOpenConnections()
int randsleep = GetRandInt(FEELER_SLEEP_WINDOW * 1000); int randsleep = GetRandInt(FEELER_SLEEP_WINDOW * 1000);
if (!interruptNet.sleep_for(std::chrono::milliseconds(randsleep))) if (!interruptNet.sleep_for(std::chrono::milliseconds(randsleep)))
return; 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); OpenNetworkConnection(addrConnect, (int)setConnected.size() >= std::min(nMaxConnections - 1, 2), &grant, nullptr, false, fFeeler);

View File

@ -1020,6 +1020,8 @@ public:
std::string GetAddrName() const; std::string GetAddrName() const;
//! Sets the addrName only if it was not previously set //! Sets the addrName only if it was not previously set
void MaybeSetAddrName(const std::string& addrNameIn); void MaybeSetAddrName(const std::string& addrNameIn);
std::string GetLogString() const;
}; };
class CExplicitNetCleanup class CExplicitNetCleanup

View File

@ -2987,13 +2987,13 @@ static bool SendRejectsAndCheckIfBanned(CNode* pnode, CConnman& connman)
if (state.fShouldBan) { if (state.fShouldBan) {
state.fShouldBan = false; state.fShouldBan = false;
if (pnode->fWhitelisted) 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) 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 { else {
pnode->fDisconnect = true; pnode->fDisconnect = true;
if (pnode->addr.IsLocal()) 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 else
{ {
connman.Ban(pnode->addr, BanReasonNodeMisbehaving); connman.Ban(pnode->addr, BanReasonNodeMisbehaving);

View File

@ -72,7 +72,11 @@ void CPrivateSendServer::ProcessMessage(CNode* pfrom, const std::string& strComm
int64_t nLastDsq = mmetaman.GetMetaInfo(dmn->proTxHash)->GetLastDsq(); int64_t nLastDsq = mmetaman.GetMetaInfo(dmn->proTxHash)->GetLastDsq();
if (nLastDsq != 0 && nLastDsq + mnList.GetValidMNsCount() / 5 > mmetaman.GetDsqCount()) { 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); PushStatus(pfrom, STATUS_REJECTED, ERR_RECENT, connman);
return; return;
} }