net: merge V2Transport constructors, move key gen

This removes the ability for BIP324Cipher to generate its own key, moving that
responsibility to the caller (mostly, V2Transport). This allows us to write
the random-key V2Transport constructor by delegating to the explicit-key one.
This commit is contained in:
Pieter Wuille
2023-09-08 11:48:09 -04:00
parent c5a63ea56f
commit b6934fd03f
4 changed files with 30 additions and 23 deletions

View File

@@ -1008,6 +1008,14 @@ BOOST_AUTO_TEST_CASE(advertise_local_address)
namespace {
CKey GenerateRandomTestKey() noexcept
{
CKey key;
uint256 key_data = InsecureRand256();
key.Set(key_data.begin(), key_data.end(), true);
return key;
}
/** A class for scenario-based tests of V2Transport
*
* Each V2TransportTester encapsulates a V2Transport (the one being tested), and can be told to
@@ -1031,6 +1039,7 @@ public:
/** Construct a tester object. test_initiator: whether the tested transport is initiator. */
V2TransportTester(bool test_initiator) :
m_transport(0, test_initiator, SER_NETWORK, INIT_PROTO_VERSION),
m_cipher{GenerateRandomTestKey(), MakeByteSpan(InsecureRand256())},
m_test_initiator(test_initiator) {}
/** Data type returned by Interact: