Skip to content

Commit 00fa78c

Browse files
committed
Merge pull request #3764
2e36866 Show nodeid instead of addresses (for anonymity) unless otherwise requested. (R E Broadley)
2 parents e61c6d6 + 2e36866 commit 00fa78c

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
@@ -290,6 +290,7 @@ std::string HelpMessage(HelpMessageMode mode)
290290
strUsage += " -gen " + _("Generate coins (default: 0)") + "\n";
291291
strUsage += " -genproclimit=<n> " + _("Set the processor limit for when generation is on (-1 = unlimited, default: -1)") + "\n";
292292
strUsage += " -help-debug " + _("Show all debugging options (usage: --help -help-debug)") + "\n";
293+
strUsage += " -logips " + _("Include IP addresses in debug output (default: 0)") + "\n";
293294
strUsage += " -logtimestamps " + _("Prepend debug output with timestamp (default: 1)") + "\n";
294295
if (GetBoolArg("-help-debug", false))
295296
{
@@ -586,6 +587,7 @@ bool AppInit2(boost::thread_group& threadGroup)
586587
fServer = GetBoolArg("-server", false);
587588
fPrintToConsole = GetBoolArg("-printtoconsole", false);
588589
fLogTimestamps = GetBoolArg("-logtimestamps", true);
590+
fLogIPs = GetBoolArg("-logips", false);
589591
setvbuf(stdout, NULL, _IOLBF, 0);
590592
#ifdef ENABLE_WALLET
591593
bool fDisableWallet = GetBoolArg("-disablewallet", false);

src/main.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3538,7 +3538,7 @@ void static ProcessGetData(CNode* pfrom)
35383538
bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
35393539
{
35403540
RandAddSeedPerfmon();
3541-
LogPrint("net", "received: %s (%u bytes)\n", strCommand, vRecv.size());
3541+
LogPrint("net", "received: %s (%u bytes) peer=%d\n", strCommand, vRecv.size(), pfrom->id);
35423542
if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
35433543
{
35443544
LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n");
@@ -3570,7 +3570,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
35703570
if (pfrom->nVersion < MIN_PEER_PROTO_VERSION)
35713571
{
35723572
// disconnect from peers older than this proto version
3573-
LogPrintf("partner %s using obsolete version %i; disconnecting\n", pfrom->addr.ToString(), pfrom->nVersion);
3573+
LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion);
35743574
pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE,
35753575
strprintf("Version must be %d or greater", MIN_PEER_PROTO_VERSION));
35763576
pfrom->fDisconnect = true;
@@ -3651,7 +3651,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
36513651

36523652
pfrom->fSuccessfullyConnected = true;
36533653

3654-
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());
3654+
LogPrintf("receive version message: %s: version %d, blocks=%d, us=%s, peer=%d\n", pfrom->cleanSubVer, pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString(), pfrom->id);
36553655

36563656
AddTimeData(pfrom->addr, nTime);
36573657
}
@@ -3758,7 +3758,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
37583758
pfrom->AddInventoryKnown(inv);
37593759

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

37633763
if (!fAlreadyHave) {
37643764
if (!fImporting && !fReindex) {
@@ -3791,10 +3791,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
37913791
}
37923792

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

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

37993799
pfrom->vRecvGetData.insert(pfrom->vRecvGetData.end(), vInv.begin(), vInv.end());
38003800
ProcessGetData(pfrom);
@@ -3816,7 +3816,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
38163816
if (pindex)
38173817
pindex = chainActive.Next(pindex);
38183818
int nLimit = 500;
3819-
LogPrint("net", "getblocks %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop==uint256(0) ? "end" : hashStop.ToString(), nLimit);
3819+
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);
38203820
for (; pindex; pindex = chainActive.Next(pindex))
38213821
{
38223822
if (pindex->GetBlockHash() == hashStop)
@@ -3899,8 +3899,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
38993899
vEraseQueue.push_back(inv.hash);
39003900

39013901

3902-
LogPrint("mempool", "AcceptToMemoryPool: %s %s : accepted %s (poolsz %u)\n",
3903-
pfrom->addr.ToString(), pfrom->cleanSubVer,
3902+
LogPrint("mempool", "AcceptToMemoryPool: peer=%d %s : accepted %s (poolsz %u)\n",
3903+
pfrom->id, pfrom->cleanSubVer,
39043904
tx.GetHash().ToString(),
39053905
mempool.mapTx.size());
39063906

@@ -3953,8 +3953,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
39533953
int nDoS = 0;
39543954
if (state.IsInvalid(nDoS))
39553955
{
3956-
LogPrint("mempool", "%s from %s %s was not accepted into the memory pool: %s\n", tx.GetHash().ToString(),
3957-
pfrom->addr.ToString(), pfrom->cleanSubVer,
3956+
LogPrint("mempool", "%s from peer=%d %s was not accepted into the memory pool: %s\n", tx.GetHash().ToString(),
3957+
pfrom->id, pfrom->cleanSubVer,
39583958
state.GetRejectReason());
39593959
pfrom->PushMessage("reject", strCommand, state.GetRejectCode(),
39603960
state.GetRejectReason(), inv.hash);
@@ -3969,7 +3969,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
39693969
CBlock block;
39703970
vRecv >> block;
39713971

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

39753975
CInv inv(MSG_BLOCK, block.GetHash());
@@ -4086,8 +4086,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
40864086
}
40874087

40884088
if (!(sProblem.empty())) {
4089-
LogPrint("net", "pong %s %s: %s, %x expected, %x received, %u bytes\n",
4090-
pfrom->addr.ToString(),
4089+
LogPrint("net", "pong peer=%d %s: %s, %x expected, %x received, %u bytes\n",
4090+
pfrom->id,
40914091
pfrom->cleanSubVer,
40924092
sProblem,
40934093
pfrom->nPingNonceSent,
@@ -4327,7 +4327,7 @@ bool ProcessMessages(CNode* pfrom)
43274327
}
43284328

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

43324332
break;
43334333
}
@@ -4531,7 +4531,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
45314531
uint256 hash = state.vBlocksToDownload.front();
45324532
vGetData.push_back(CInv(MSG_BLOCK, hash));
45334533
MarkBlockAsInFlight(pto->GetId(), hash);
4534-
LogPrint("net", "Requesting block %s from %s\n", hash.ToString(), state.name);
4534+
LogPrint("net", "Requesting block %s peer=%d\n", hash.ToString(), pto->id);
45354535
if (vGetData.size() >= 1000)
45364536
{
45374537
pto->PushMessage("getdata", vGetData);
@@ -4548,7 +4548,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
45484548
if (!AlreadyHave(inv))
45494549
{
45504550
if (fDebug)
4551-
LogPrint("net", "sending getdata: %s\n", inv.ToString());
4551+
LogPrint("net", "Requesting %s peer=%d\n", inv.ToString(), pto->id);
45524552
vGetData.push_back(inv);
45534553
if (vGetData.size() >= 1000)
45544554
{

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)