mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-04 13:55:23 -05:00
[refactor] Add CChainParams member to CConnman
This is done in preparation to the next commit, but has the nice effect of removing one further data structure relying on the global `Params()`.
This commit is contained in:
parent
f0d1d8b35c
commit
2b08c55f01
6 changed files with 19 additions and 14 deletions
|
@ -1223,7 +1223,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
assert(!node.connman);
|
assert(!node.connman);
|
||||||
node.connman = std::make_unique<CConnman>(GetRand<uint64_t>(),
|
node.connman = std::make_unique<CConnman>(GetRand<uint64_t>(),
|
||||||
GetRand<uint64_t>(),
|
GetRand<uint64_t>(),
|
||||||
*node.addrman, *node.netgroupman, args.GetBoolArg("-networkactive", true));
|
*node.addrman, *node.netgroupman, chainparams, args.GetBoolArg("-networkactive", true));
|
||||||
|
|
||||||
assert(!node.fee_estimator);
|
assert(!node.fee_estimator);
|
||||||
// Don't initialize fee estimation with old data if we don't relay transactions,
|
// Don't initialize fee estimation with old data if we don't relay transactions,
|
||||||
|
|
15
src/net.cpp
15
src/net.cpp
|
@ -470,8 +470,8 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
||||||
Ticks<HoursDouble>(pszDest ? 0h : Now<NodeSeconds>() - addrConnect.nTime));
|
Ticks<HoursDouble>(pszDest ? 0h : Now<NodeSeconds>() - addrConnect.nTime));
|
||||||
|
|
||||||
// Resolve
|
// Resolve
|
||||||
const uint16_t default_port{pszDest != nullptr ? Params().GetDefaultPort(pszDest) :
|
const uint16_t default_port{pszDest != nullptr ? m_params.GetDefaultPort(pszDest) :
|
||||||
Params().GetDefaultPort()};
|
m_params.GetDefaultPort()};
|
||||||
if (pszDest) {
|
if (pszDest) {
|
||||||
const std::vector<CService> resolved{Lookup(pszDest, default_port, fNameLookup && !HaveNameProxy(), 256)};
|
const std::vector<CService> resolved{Lookup(pszDest, default_port, fNameLookup && !HaveNameProxy(), 256)};
|
||||||
if (!resolved.empty()) {
|
if (!resolved.empty()) {
|
||||||
|
@ -2184,7 +2184,7 @@ void CConnman::WakeMessageHandler()
|
||||||
void CConnman::ThreadDNSAddressSeed()
|
void CConnman::ThreadDNSAddressSeed()
|
||||||
{
|
{
|
||||||
FastRandomContext rng;
|
FastRandomContext rng;
|
||||||
std::vector<std::string> seeds = Params().DNSSeeds();
|
std::vector<std::string> seeds = m_params.DNSSeeds();
|
||||||
Shuffle(seeds.begin(), seeds.end(), rng);
|
Shuffle(seeds.begin(), seeds.end(), rng);
|
||||||
int seeds_right_now = 0; // Number of seeds left before testing if we have enough connections
|
int seeds_right_now = 0; // Number of seeds left before testing if we have enough connections
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
@ -2275,7 +2275,7 @@ void CConnman::ThreadDNSAddressSeed()
|
||||||
const auto addresses{LookupHost(host, nMaxIPs, true)};
|
const auto addresses{LookupHost(host, nMaxIPs, true)};
|
||||||
if (!addresses.empty()) {
|
if (!addresses.empty()) {
|
||||||
for (const CNetAddr& ip : addresses) {
|
for (const CNetAddr& ip : addresses) {
|
||||||
CAddress addr = CAddress(CService(ip, Params().GetDefaultPort()), requiredServiceBits);
|
CAddress addr = CAddress(CService(ip, m_params.GetDefaultPort()), requiredServiceBits);
|
||||||
addr.nTime = rng.rand_uniform_delay(Now<NodeSeconds>() - 3 * 24h, -4 * 24h); // use a random age between 3 and 7 days old
|
addr.nTime = rng.rand_uniform_delay(Now<NodeSeconds>() - 3 * 24h, -4 * 24h); // use a random age between 3 and 7 days old
|
||||||
vAdd.push_back(addr);
|
vAdd.push_back(addr);
|
||||||
found++;
|
found++;
|
||||||
|
@ -2480,7 +2480,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (add_fixed_seeds_now) {
|
if (add_fixed_seeds_now) {
|
||||||
std::vector<CAddress> seed_addrs{ConvertSeeds(Params().FixedSeeds())};
|
std::vector<CAddress> seed_addrs{ConvertSeeds(m_params.FixedSeeds())};
|
||||||
// We will not make outgoing connections to peers that are unreachable
|
// We will not make outgoing connections to peers that are unreachable
|
||||||
// (e.g. because of -onlynet configuration).
|
// (e.g. because of -onlynet configuration).
|
||||||
// Therefore, we do not add them to addrman in the first place.
|
// Therefore, we do not add them to addrman in the first place.
|
||||||
|
@ -2769,7 +2769,7 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const std::string& strAddNode : lAddresses) {
|
for (const std::string& strAddNode : lAddresses) {
|
||||||
CService service(LookupNumeric(strAddNode, Params().GetDefaultPort(strAddNode)));
|
CService service(LookupNumeric(strAddNode, m_params.GetDefaultPort(strAddNode)));
|
||||||
AddedNodeInfo addedNode{strAddNode, CService(), false, false};
|
AddedNodeInfo addedNode{strAddNode, CService(), false, false};
|
||||||
if (service.IsValid()) {
|
if (service.IsValid()) {
|
||||||
// strAddNode is an IP:port
|
// strAddNode is an IP:port
|
||||||
|
@ -3075,11 +3075,12 @@ void CConnman::SetNetworkActive(bool active)
|
||||||
}
|
}
|
||||||
|
|
||||||
CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In, AddrMan& addrman_in,
|
CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In, AddrMan& addrman_in,
|
||||||
const NetGroupManager& netgroupman, bool network_active)
|
const NetGroupManager& netgroupman, const CChainParams& params, bool network_active)
|
||||||
: addrman(addrman_in)
|
: addrman(addrman_in)
|
||||||
, m_netgroupman{netgroupman}
|
, m_netgroupman{netgroupman}
|
||||||
, nSeed0(nSeed0In)
|
, nSeed0(nSeed0In)
|
||||||
, nSeed1(nSeed1In)
|
, nSeed1(nSeed1In)
|
||||||
|
, m_params(params)
|
||||||
{
|
{
|
||||||
SetTryNewOutboundPeer(false);
|
SetTryNewOutboundPeer(false);
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
|
|
||||||
class AddrMan;
|
class AddrMan;
|
||||||
class BanMan;
|
class BanMan;
|
||||||
|
class CChainParams;
|
||||||
class CNode;
|
class CNode;
|
||||||
class CScheduler;
|
class CScheduler;
|
||||||
struct bilingual_str;
|
struct bilingual_str;
|
||||||
|
@ -1081,7 +1082,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
CConnman(uint64_t seed0, uint64_t seed1, AddrMan& addrman, const NetGroupManager& netgroupman,
|
CConnman(uint64_t seed0, uint64_t seed1, AddrMan& addrman, const NetGroupManager& netgroupman,
|
||||||
bool network_active = true);
|
const CChainParams& params, bool network_active = true);
|
||||||
|
|
||||||
~CConnman();
|
~CConnman();
|
||||||
|
|
||||||
|
@ -1566,6 +1567,8 @@ private:
|
||||||
std::vector<CNode*> m_nodes_copy;
|
std::vector<CNode*> m_nodes_copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const CChainParams& m_params;
|
||||||
|
|
||||||
friend struct ConnmanTestMsg;
|
friend struct ConnmanTestMsg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ static void AddRandomOutboundPeer(NodeId& id, std::vector<CNode*>& vNodes, PeerM
|
||||||
BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
|
BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
|
||||||
{
|
{
|
||||||
NodeId id{0};
|
NodeId id{0};
|
||||||
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
|
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
||||||
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {});
|
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {});
|
||||||
|
|
||||||
constexpr int max_outbound_full_relay = MAX_OUTBOUND_FULL_RELAY_CONNECTIONS;
|
constexpr int max_outbound_full_relay = MAX_OUTBOUND_FULL_RELAY_CONNECTIONS;
|
||||||
|
@ -242,7 +242,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
|
||||||
BOOST_AUTO_TEST_CASE(block_relay_only_eviction)
|
BOOST_AUTO_TEST_CASE(block_relay_only_eviction)
|
||||||
{
|
{
|
||||||
NodeId id{0};
|
NodeId id{0};
|
||||||
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
|
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
||||||
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {});
|
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {});
|
||||||
|
|
||||||
constexpr int max_outbound_block_relay{MAX_BLOCK_RELAY_ONLY_CONNECTIONS};
|
constexpr int max_outbound_block_relay{MAX_BLOCK_RELAY_ONLY_CONNECTIONS};
|
||||||
|
@ -305,7 +305,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
|
||||||
LOCK(NetEventsInterface::g_msgproc_mutex);
|
LOCK(NetEventsInterface::g_msgproc_mutex);
|
||||||
|
|
||||||
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||||
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
|
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
||||||
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, {});
|
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, {});
|
||||||
|
|
||||||
CNetAddr tor_netaddr;
|
CNetAddr tor_netaddr;
|
||||||
|
@ -407,7 +407,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
|
||||||
LOCK(NetEventsInterface::g_msgproc_mutex);
|
LOCK(NetEventsInterface::g_msgproc_mutex);
|
||||||
|
|
||||||
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||||
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
|
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
||||||
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, {});
|
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, {});
|
||||||
|
|
||||||
banman->ClearBanned();
|
banman->ClearBanned();
|
||||||
|
|
|
@ -36,6 +36,7 @@ FUZZ_TARGET(connman, .init = initialize_connman)
|
||||||
fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
||||||
*g_setup->m_node.addrman,
|
*g_setup->m_node.addrman,
|
||||||
*g_setup->m_node.netgroupman,
|
*g_setup->m_node.netgroupman,
|
||||||
|
Params(),
|
||||||
fuzzed_data_provider.ConsumeBool()};
|
fuzzed_data_provider.ConsumeBool()};
|
||||||
CNetAddr random_netaddr;
|
CNetAddr random_netaddr;
|
||||||
CNode random_node = ConsumeNode(fuzzed_data_provider);
|
CNode random_node = ConsumeNode(fuzzed_data_provider);
|
||||||
|
|
|
@ -253,7 +253,7 @@ TestingSetup::TestingSetup(
|
||||||
/*deterministic=*/false,
|
/*deterministic=*/false,
|
||||||
m_node.args->GetIntArg("-checkaddrman", 0));
|
m_node.args->GetIntArg("-checkaddrman", 0));
|
||||||
m_node.banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
m_node.banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||||
m_node.connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman); // Deterministic randomness for tests.
|
m_node.connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params()); // Deterministic randomness for tests.
|
||||||
PeerManager::Options peerman_opts;
|
PeerManager::Options peerman_opts;
|
||||||
ApplyArgsManOptions(*m_node.args, peerman_opts);
|
ApplyArgsManOptions(*m_node.args, peerman_opts);
|
||||||
m_node.peerman = PeerManager::make(*m_node.connman, *m_node.addrman,
|
m_node.peerman = PeerManager::make(*m_node.connman, *m_node.addrman,
|
||||||
|
|
Loading…
Add table
Reference in a new issue