timedata: make it possible to reset the state
Add a new function TestOnlyResetTimeData() which would reset the
internal state used by GetTimeOffset(), GetAdjustedTime() and
AddTimeData().This is needed so that unit tests that call AddTimeData() can restore
the state in order not to confuse other tests that rely on it.Currently timedata_tests/addtimedata is the only test that modifies
the state (via AddTimeData()) and also the only test that relies on
that state.
timedata: rename variables to match the coding style
Rename the local variables in src/timedata.cpp:
setKnown -> g_sources
vTimeOffsets -> g_time_offsets
fDone -> g_warning_emitted
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.
net: pass Span by value to CaptureMessage()
Span is lightweight and need not be passed by const reference.
net: fix GetListenPort() to derive the proper port
GetListenPort() uses a simple logic: "if -port=P is given, then we
must be listening on P, otherwise we must be listening on 8333".
This is however not true if -bind= has been provided with :port part
or if -whitebind= has been provided. Thus, extend GetListenPort() to
return the port from -bind= or -whitebind=, if any.Fixes https://github.com/bitcoin/bitcoin/issues/20184 (cases 1. 2. 3. 5.)
TestChainState is from core#20332
net: only assume all local addresses if listening on any
If -bind= is provided then we would bind only to a particular address
and should not add all the other addresses of the machine to the list of
local addresses.Fixes https://github.com/bitcoin/bitcoin/issues/20184 (case 4.)
This is a backport of core#20196
Depends on D14689