aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2021-07-22 18:23:21 +0200
committerVasil Dimov <vd@FreeBSD.org>2022-03-02 15:40:36 +0100
commit3cb9d9c861710c0cff018bee90b1969193d3ed68 (patch)
treef0db6729c585e7d8e819762cf9437a678d78590e /src/net.cpp
parent43868ba416727effd515a471e2a337c3b8cacc37 (diff)
net: make CaptureMessage() mockable
Rename `CaptureMessage()` to `CaptureMessageToFile()` and introduce a `std::function` variable called `CaptureMessage` whose value can be changed by unit tests, should they need to inspect message contents.
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 9bb264a38a..b31b618eea 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -3085,7 +3085,10 @@ uint64_t CConnman::CalculateKeyedNetGroup(const CAddress& ad) const
return GetDeterministicRandomizer(RANDOMIZER_ID_NETGROUP).Write(vchNetGroup.data(), vchNetGroup.size()).Finalize();
}
-void CaptureMessage(const CAddress& addr, const std::string& msg_type, const Span<const unsigned char>& data, bool is_incoming)
+void CaptureMessageToFile(const CAddress& addr,
+ const std::string& msg_type,
+ const Span<const unsigned char>& data,
+ bool is_incoming)
{
// Note: This function captures the message at the time of processing,
// not at socket receive/send time.
@@ -3112,3 +3115,9 @@ void CaptureMessage(const CAddress& addr, const std::string& msg_type, const Spa
ser_writedata32(f, size);
f.write(AsBytes(data));
}
+
+std::function<void(const CAddress& addr,
+ const std::string& msg_type,
+ const Span<const unsigned char>& data,
+ bool is_incoming)>
+ CaptureMessage = CaptureMessageToFile;