mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 02:25:40 +01:00
[net] Construct addrman outside connman
node.context owns the CAddrMan. CConnman holds a reference to the CAddrMan.
This commit is contained in:
parent
3530d5d2d8
commit
1c25adf6d2
@ -228,6 +228,7 @@ void Shutdown(NodeContext& node)
|
||||
node.peerman.reset();
|
||||
node.connman.reset();
|
||||
node.banman.reset();
|
||||
node.addrman.reset();
|
||||
|
||||
if (node.mempool && node.mempool->IsLoaded() && node.args->GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
|
||||
DumpMempool(*node.mempool);
|
||||
@ -1402,10 +1403,12 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
|
||||
fDiscover = args.GetBoolArg("-discover", true);
|
||||
const bool ignores_incoming_txs{args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)};
|
||||
|
||||
assert(!node.addrman);
|
||||
node.addrman = std::make_unique<CAddrMan>();
|
||||
assert(!node.banman);
|
||||
node.banman = std::make_unique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface, args.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
|
||||
assert(!node.connman);
|
||||
node.connman = std::make_unique<CConnman>(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max()), args.GetBoolArg("-networkactive", true));
|
||||
node.connman = std::make_unique<CConnman>(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max()), *node.addrman, args.GetBoolArg("-networkactive", true));
|
||||
|
||||
assert(!node.fee_estimator);
|
||||
// Don't initialize fee estimation with old data if we don't relay transactions,
|
||||
|
@ -2351,8 +2351,8 @@ void CConnman::SetNetworkActive(bool active)
|
||||
uiInterface.NotifyNetworkActiveChanged(fNetworkActive);
|
||||
}
|
||||
|
||||
CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In, bool network_active)
|
||||
: nSeed0(nSeed0In), nSeed1(nSeed1In)
|
||||
CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In, CAddrMan& addrman_in, bool network_active)
|
||||
: addrman(addrman_in), nSeed0(nSeed0In), nSeed1(nSeed1In)
|
||||
{
|
||||
SetTryNewOutboundPeer(false);
|
||||
|
||||
|
@ -856,7 +856,7 @@ public:
|
||||
m_onion_binds = connOptions.onion_binds;
|
||||
}
|
||||
|
||||
CConnman(uint64_t seed0, uint64_t seed1, bool network_active = true);
|
||||
CConnman(uint64_t seed0, uint64_t seed1, CAddrMan& addrman, bool network_active = true);
|
||||
~CConnman();
|
||||
bool Start(CScheduler& scheduler, const Options& options);
|
||||
|
||||
@ -1130,7 +1130,7 @@ private:
|
||||
std::vector<ListenSocket> vhListenSocket;
|
||||
std::atomic<bool> fNetworkActive{true};
|
||||
bool fAddressesInitialized{false};
|
||||
CAddrMan addrman;
|
||||
CAddrMan& addrman;
|
||||
std::deque<std::string> m_addr_fetches GUARDED_BY(m_addr_fetches_mutex);
|
||||
RecursiveMutex m_addr_fetches_mutex;
|
||||
std::vector<std::string> vAddedNodes GUARDED_BY(cs_vAddedNodes);
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <node/context.h>
|
||||
|
||||
#include <addrman.h>
|
||||
#include <banman.h>
|
||||
#include <interfaces/chain.h>
|
||||
#include <net.h>
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
class ArgsManager;
|
||||
class BanMan;
|
||||
class CAddrMan;
|
||||
class CBlockPolicyEstimator;
|
||||
class CConnman;
|
||||
class CScheduler;
|
||||
@ -35,6 +36,7 @@ class WalletClient;
|
||||
//! any member functions. It should just be a collection of references that can
|
||||
//! be used without pulling in unwanted dependencies or functionality.
|
||||
struct NodeContext {
|
||||
std::unique_ptr<CAddrMan> addrman;
|
||||
std::unique_ptr<CConnman> connman;
|
||||
std::unique_ptr<CTxMemPool> mempool;
|
||||
std::unique_ptr<CBlockPolicyEstimator> fee_estimator;
|
||||
|
@ -67,7 +67,7 @@ BOOST_FIXTURE_TEST_SUITE(denialofservice_tests, TestingSetup)
|
||||
BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
|
||||
{
|
||||
const CChainParams& chainparams = Params();
|
||||
auto connman = std::make_unique<CConnman>(0x1337, 0x1337);
|
||||
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman);
|
||||
auto peerLogic = PeerManager::make(chainparams, *connman, nullptr, *m_node.scheduler,
|
||||
*m_node.chainman, *m_node.mempool, false);
|
||||
|
||||
@ -137,7 +137,7 @@ static void AddRandomOutboundPeer(std::vector<CNode *> &vNodes, PeerManager &pee
|
||||
BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
|
||||
{
|
||||
const CChainParams& chainparams = Params();
|
||||
auto connman = std::make_unique<CConnmanTest>(0x1337, 0x1337);
|
||||
auto connman = std::make_unique<CConnmanTest>(0x1337, 0x1337, *m_node.addrman);
|
||||
auto peerLogic = PeerManager::make(chainparams, *connman, nullptr, *m_node.scheduler,
|
||||
*m_node.chainman, *m_node.mempool, false);
|
||||
|
||||
@ -211,7 +211,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
|
||||
{
|
||||
const CChainParams& chainparams = Params();
|
||||
auto banman = std::make_unique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||
auto connman = std::make_unique<CConnman>(0x1337, 0x1337);
|
||||
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman);
|
||||
auto peerLogic = PeerManager::make(chainparams, *connman, banman.get(), *m_node.scheduler,
|
||||
*m_node.chainman, *m_node.mempool, false);
|
||||
|
||||
@ -258,7 +258,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
|
||||
{
|
||||
const CChainParams& chainparams = Params();
|
||||
auto banman = std::make_unique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||
auto connman = std::make_unique<CConnman>(0x1337, 0x1337);
|
||||
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman);
|
||||
auto peerLogic = PeerManager::make(chainparams, *connman, banman.get(), *m_node.scheduler,
|
||||
*m_node.chainman, *m_node.mempool, false);
|
||||
|
||||
|
@ -25,7 +25,8 @@ FUZZ_TARGET_INIT(connman, initialize_connman)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
||||
CConnman connman{fuzzed_data_provider.ConsumeIntegral<uint64_t>(), fuzzed_data_provider.ConsumeIntegral<uint64_t>(), fuzzed_data_provider.ConsumeBool()};
|
||||
CAddrMan addrman;
|
||||
CConnman connman{fuzzed_data_provider.ConsumeIntegral<uint64_t>(), fuzzed_data_provider.ConsumeIntegral<uint64_t>(), addrman, fuzzed_data_provider.ConsumeBool()};
|
||||
CAddress random_address;
|
||||
CNetAddr random_netaddr;
|
||||
CNode random_node = ConsumeNode(fuzzed_data_provider);
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
#include <addrman.h>
|
||||
#include <banman.h>
|
||||
#include <chainparams.h>
|
||||
#include <consensus/consensus.h>
|
||||
@ -155,6 +156,7 @@ ChainTestingSetup::~ChainTestingSetup()
|
||||
GetMainSignals().UnregisterBackgroundSignalScheduler();
|
||||
m_node.connman.reset();
|
||||
m_node.banman.reset();
|
||||
m_node.addrman.reset();
|
||||
m_node.args = nullptr;
|
||||
UnloadBlockIndex(m_node.mempool.get(), *m_node.chainman);
|
||||
m_node.mempool.reset();
|
||||
@ -187,8 +189,9 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
|
||||
throw std::runtime_error(strprintf("ActivateBestChain failed. (%s)", state.ToString()));
|
||||
}
|
||||
|
||||
m_node.addrman = std::make_unique<CAddrMan>();
|
||||
m_node.banman = std::make_unique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||
m_node.connman = std::make_unique<CConnman>(0x1337, 0x1337); // Deterministic randomness for tests.
|
||||
m_node.connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman); // Deterministic randomness for tests.
|
||||
m_node.peerman = PeerManager::make(chainparams, *m_node.connman, m_node.banman.get(),
|
||||
*m_node.scheduler, *m_node.chainman, *m_node.mempool,
|
||||
false);
|
||||
|
Loading…
Reference in New Issue
Block a user