From 4d1a582549bc982d55e24585b0ba06f92f21e9da Mon Sep 17 00:00:00 2001 From: Troy Giorshev Date: Mon, 13 Jul 2020 14:00:03 -0400 Subject: [PATCH] Call CaptureMessage at appropriate locations These calls are toggled by a debug-only "capturemessages" flag. Default disabled. --- src/init.cpp | 1 + src/net.cpp | 3 +++ src/net_processing.cpp | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index 3ab62638133..e16f0e8c831 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -521,6 +521,7 @@ void SetupServerArgs(NodeContext& node) argsman.AddArg("-limitdescendantcount=", strprintf("Do not accept transactions if any ancestor would have or more in-mempool descendants (default: %u)", DEFAULT_DESCENDANT_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-limitdescendantsize=", strprintf("Do not accept transactions if any ancestor would have more than kilobytes of in-mempool descendants (default: %u).", DEFAULT_DESCENDANT_SIZE_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-addrmantest", "Allows to test address relay on localhost", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); + argsman.AddArg("-capturemessages", "Capture all P2P messages to disk", ArgsManager::ALLOW_BOOL | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-debug=", "Output debugging information (default: -nodebug, supplying is optional). " "If is not supplied or if = 1, output all debugging information. can be: " + LogInstance().LogCategoriesString() + ".", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); diff --git a/src/net.cpp b/src/net.cpp index 29529d54caa..81f014d9325 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2864,6 +2864,9 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg) { size_t nMessageSize = msg.data.size(); LogPrint(BCLog::NET, "sending %s (%d bytes) peer=%d\n", SanitizeString(msg.m_type), nMessageSize, pnode->GetId()); + if (gArgs.GetBoolArg("-capturemessages", false)) { + CaptureMessage(pnode->addr, msg.m_type, msg.data, /* incoming */ false); + } // make sure we use the appropriate network transport format std::vector serializedHeader; diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 7d89d3ea6e9..d0a743e81c2 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -4042,6 +4042,10 @@ bool PeerManagerImpl::ProcessMessages(CNode* pfrom, std::atomic& interrupt } CNetMessage& msg(msgs.front()); + if (gArgs.GetBoolArg("-capturemessages", false)) { + CaptureMessage(pfrom->addr, msg.m_command, MakeUCharSpan(msg.m_recv), /* incoming */ true); + } + msg.SetVersion(pfrom->GetCommonVersion()); const std::string& msg_type = msg.m_command;