Skip to content

Commit 2e36866

Browse files
committed
Show nodeid instead of addresses (for anonymity) unless otherwise requested.
1 parent f04f123 commit 2e36866

File tree

6 files changed

+35
-25
lines changed

6 files changed

+35
-25
lines changed

src/init.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ std::string HelpMessage(HelpMessageMode mode)
288288
strUsage += " -gen " + _("Generate coins (default: 0)") + "\n";
289289
strUsage += " -genproclimit=<n> " + _("Set the processor limit for when generation is on (-1 = unlimited, default: -1)") + "\n";
290290
strUsage += " -help-debug " + _("Show all debugging options (usage: --help -help-debug)") + "\n";
291+
strUsage += " -logips " + _("Include IP addresses in debug output (default: 0)") + "\n";
291292
strUsage += " -logtimestamps " + _("Prepend debug output with timestamp (default: 1)") + "\n";
292293
if (GetBoolArg("-help-debug", false))
293294
{
@@ -585,6 +586,7 @@ bool AppInit2(boost::thread_group& threadGroup)
585586
fServer = GetBoolArg("-server", false);
586587
fPrintToConsole = GetBoolArg("-printtoconsole", false);
587588
fLogTimestamps = GetBoolArg("-logtimestamps", true);
589+
fLogIPs = GetBoolArg("-logips", false);
588590
setvbuf(stdout, NULL, _IOLBF, 0);
589591
#ifdef ENABLE_WALLET
590592
bool fDisableWallet = GetBoolArg("-disablewallet", false);

src/main.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3547,7 +3547,7 @@ void static ProcessGetData(CNode* pfrom)
35473547
bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
35483548
{
35493549
RandAddSeedPerfmon();
3550-
LogPrint("net", "received: %s (%u bytes)\n", strCommand, vRecv.size());
3550+
LogPrint("net", "received: %s (%u bytes) peer=%d\n", strCommand, vRecv.size(), pfrom->id);
35513551
if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
35523552
{
35533553
LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n");
@@ -3579,7 +3579,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
35793579
if (pfrom->nVersion < MIN_PEER_PROTO_VERSION)
35803580
{
35813581
// disconnect from peers older than this proto version
3582-
LogPrintf("partner %s using obsolete version %i; disconnecting\n", pfrom->addr.ToString(), pfrom->nVersion);
3582+
LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion);
35833583
pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE,
35843584
strprintf("Version must be %d or greater", MIN_PEER_PROTO_VERSION));
35853585
pfrom->fDisconnect = true;
@@ -3660,7 +3660,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
36603660

36613661
pfrom->fSuccessfullyConnected = true;
36623662

3663-
LogPrintf("receive version message: %s: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", pfrom->cleanSubVer, pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString(), addrFrom.ToString(), pfrom->addr.ToString());
3663+
LogPrintf("receive version message: %s: version %d, blocks=%d, us=%s, peer=%d\n", pfrom->cleanSubVer, pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString(), pfrom->id);
36643664

36653665
AddTimeData(pfrom->addr, nTime);
36663666
}
@@ -3767,7 +3767,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
37673767
pfrom->AddInventoryKnown(inv);
37683768

37693769
bool fAlreadyHave = AlreadyHave(inv);
3770-
LogPrint("net", " got inventory: %s %s\n", inv.ToString(), fAlreadyHave ? "have" : "new");
3770+
LogPrint("net", "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom->id);
37713771

37723772
if (!fAlreadyHave) {
37733773
if (!fImporting && !fReindex) {
@@ -3800,10 +3800,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
38003800
}
38013801

38023802
if (fDebug || (vInv.size() != 1))
3803-
LogPrint("net", "received getdata (%u invsz)\n", vInv.size());
3803+
LogPrint("net", "received getdata (%u invsz) peer=%d\n", vInv.size(), pfrom->id);
38043804

38053805
if ((fDebug && vInv.size() > 0) || (vInv.size() == 1))
3806-
LogPrint("net", "received getdata for: %s\n", vInv[0].ToString());
3806+
LogPrint("net", "received getdata for: %s peer=%d\n", vInv[0].ToString(), pfrom->id);
38073807

38083808
pfrom->vRecvGetData.insert(pfrom->vRecvGetData.end(), vInv.begin(), vInv.end());
38093809
ProcessGetData(pfrom);
@@ -3825,7 +3825,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
38253825
if (pindex)
38263826
pindex = chainActive.Next(pindex);
38273827
int nLimit = 500;
3828-
LogPrint("net", "getblocks %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop==uint256(0) ? "end" : hashStop.ToString(), nLimit);
3828+
LogPrint("net", "getblocks %d to %s limit %d from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop==uint256(0) ? "end" : hashStop.ToString(), nLimit, pfrom->id);
38293829
for (; pindex; pindex = chainActive.Next(pindex))
38303830
{
38313831
if (pindex->GetBlockHash() == hashStop)
@@ -3908,8 +3908,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
39083908
vEraseQueue.push_back(inv.hash);
39093909

39103910

3911-
LogPrint("mempool", "AcceptToMemoryPool: %s %s : accepted %s (poolsz %u)\n",
3912-
pfrom->addr.ToString(), pfrom->cleanSubVer,
3911+
LogPrint("mempool", "AcceptToMemoryPool: peer=%d %s : accepted %s (poolsz %u)\n",
3912+
pfrom->id, pfrom->cleanSubVer,
39133913
tx.GetHash().ToString(),
39143914
mempool.mapTx.size());
39153915

@@ -3962,8 +3962,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
39623962
int nDoS = 0;
39633963
if (state.IsInvalid(nDoS))
39643964
{
3965-
LogPrint("mempool", "%s from %s %s was not accepted into the memory pool: %s\n", tx.GetHash().ToString(),
3966-
pfrom->addr.ToString(), pfrom->cleanSubVer,
3965+
LogPrint("mempool", "%s from peer=%d %s was not accepted into the memory pool: %s\n", tx.GetHash().ToString(),
3966+
pfrom->id, pfrom->cleanSubVer,
39673967
state.GetRejectReason());
39683968
pfrom->PushMessage("reject", strCommand, state.GetRejectCode(),
39693969
state.GetRejectReason(), inv.hash);
@@ -3978,7 +3978,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
39783978
CBlock block;
39793979
vRecv >> block;
39803980

3981-
LogPrint("net", "received block %s\n", block.GetHash().ToString());
3981+
LogPrint("net", "received block %s peer=%d\n", block.GetHash().ToString(), pfrom->id);
39823982
// block.print();
39833983

39843984
CInv inv(MSG_BLOCK, block.GetHash());
@@ -4095,8 +4095,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
40954095
}
40964096

40974097
if (!(sProblem.empty())) {
4098-
LogPrint("net", "pong %s %s: %s, %x expected, %x received, %u bytes\n",
4099-
pfrom->addr.ToString(),
4098+
LogPrint("net", "pong peer=%d %s: %s, %x expected, %x received, %u bytes\n",
4099+
pfrom->id,
41004100
pfrom->cleanSubVer,
41014101
sProblem,
41024102
pfrom->nPingNonceSent,
@@ -4336,7 +4336,7 @@ bool ProcessMessages(CNode* pfrom)
43364336
}
43374337

43384338
if (!fRet)
4339-
LogPrintf("ProcessMessage(%s, %u bytes) FAILED\n", strCommand, nMessageSize);
4339+
LogPrintf("ProcessMessage(%s, %u bytes) FAILED peer=%d\n", strCommand, nMessageSize, pfrom->id);
43404340

43414341
break;
43424342
}
@@ -4540,7 +4540,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
45404540
uint256 hash = state.vBlocksToDownload.front();
45414541
vGetData.push_back(CInv(MSG_BLOCK, hash));
45424542
MarkBlockAsInFlight(pto->GetId(), hash);
4543-
LogPrint("net", "Requesting block %s from %s\n", hash.ToString(), state.name);
4543+
LogPrint("net", "Requesting block %s peer=%d\n", hash.ToString(), pto->id);
45444544
if (vGetData.size() >= 1000)
45454545
{
45464546
pto->PushMessage("getdata", vGetData);
@@ -4557,7 +4557,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
45574557
if (!AlreadyHave(inv))
45584558
{
45594559
if (fDebug)
4560-
LogPrint("net", "sending getdata: %s\n", inv.ToString());
4560+
LogPrint("net", "Requesting %s peer=%d\n", inv.ToString(), pto->id);
45614561
vGetData.push_back(inv);
45624562
if (vGetData.size() >= 1000)
45634563
{

src/net.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,6 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
491491
{
492492
addrman.Attempt(addrConnect);
493493

494-
LogPrint("net", "connected %s\n", pszDest ? pszDest : addrConnect.ToString());
495-
496494
// Set to non-blocking
497495
#ifdef WIN32
498496
u_long nOne = 1;
@@ -513,6 +511,7 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
513511
}
514512

515513
pnode->nTimeConnected = GetTime();
514+
516515
return pnode;
517516
}
518517

@@ -524,7 +523,7 @@ void CNode::CloseSocketDisconnect()
524523
fDisconnect = true;
525524
if (hSocket != INVALID_SOCKET)
526525
{
527-
LogPrint("net", "disconnecting node %s\n", addrName);
526+
LogPrint("net", "disconnecting peer=%d\n", id);
528527
closesocket(hSocket);
529528
hSocket = INVALID_SOCKET;
530529
}
@@ -548,7 +547,10 @@ void CNode::PushVersion()
548547
CAddress addrYou = (addr.IsRoutable() && !IsProxy(addr) ? addr : CAddress(CService("0.0.0.0",0)));
549548
CAddress addrMe = GetLocalAddress(&addr);
550549
RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce));
551-
LogPrint("net", "send version message: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), addrYou.ToString(), addr.ToString());
550+
if (fLogIPs)
551+
LogPrint("net", "send version message: version %d, blocks=%d, us=%s, them=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), addrYou.ToString(), id);
552+
else
553+
LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id);
552554
PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe,
553555
nLocalHostNonce, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<string>()), nBestHeight, true);
554556
}
@@ -950,7 +952,6 @@ void ThreadSocketHandler()
950952
}
951953
else
952954
{
953-
LogPrint("net", "accepted connection %s\n", addr.ToString());
954955
CNode* pnode = new CNode(hSocket, addr, "", true);
955956
pnode->AddRef();
956957

@@ -1040,7 +1041,7 @@ void ThreadSocketHandler()
10401041
{
10411042
if (pnode->nLastRecv == 0 || pnode->nLastSend == 0)
10421043
{
1043-
LogPrint("net", "socket no message in first 60 seconds, %d %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0);
1044+
LogPrint("net", "socket no message in first 60 seconds, %d %d from %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0, pnode->id);
10441045
pnode->fDisconnect = true;
10451046
}
10461047
else if (nTime - pnode->nLastSend > TIMEOUT_INTERVAL)

src/net.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ class CNode
330330
id = nLastNodeId++;
331331
}
332332

333+
if (fLogIPs)
334+
LogPrint("net", "Added connection to %s peer=%d\n", addrName, id);
335+
else
336+
LogPrint("net", "Added connection peer=%d\n", id);
337+
333338
// Be shy and don't send version until we hear
334339
if (hSocket != INVALID_SOCKET && !fInbound)
335340
PushVersion();
@@ -446,7 +451,7 @@ class CNode
446451
nRequestTime = it->second;
447452
else
448453
nRequestTime = 0;
449-
LogPrint("net", "askfor %s %d (%s)\n", inv.ToString(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str());
454+
LogPrint("net", "askfor %s %d (%s) peer=%d\n", inv.ToString(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str(), id);
450455

451456
// Make sure not to reuse time indexes to keep things in the same order
452457
int64_t nNow = GetTimeMicros() - 1000000;
@@ -514,7 +519,7 @@ class CNode
514519
assert(ssSend.size () >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum));
515520
memcpy((char*)&ssSend[CMessageHeader::CHECKSUM_OFFSET], &nChecksum, sizeof(nChecksum));
516521

517-
LogPrint("net", "(%d bytes)\n", nSize);
522+
LogPrint("net", "(%d bytes) peer=%d\n", nSize, id);
518523

519524
std::deque<CSerializeData>::iterator it = vSendMsg.insert(vSendMsg.end(), CSerializeData());
520525
ssSend.GetAndClear(*it);

src/util.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ bool fDaemon = false;
9595
bool fServer = false;
9696
string strMiscWarning;
9797
bool fLogTimestamps = false;
98+
bool fLogIPs = false;
9899
volatile bool fReopenDebugLog = false;
99100
CClientUIInterface uiInterface;
100101

src/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ extern bool fPrintToDebugLog;
100100
extern bool fServer;
101101
extern std::string strMiscWarning;
102102
extern bool fLogTimestamps;
103+
extern bool fLogIPs;
103104
extern volatile bool fReopenDebugLog;
104105

105106
void RandAddSeed();

0 commit comments

Comments
 (0)