mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 10:37:37 -07:00
Merge pull request #6443
145be6d
p2p: startup speedup, init seed nodes on first 'connect_to_seed()' (xiphon)
This commit is contained in:
commit
6e7b883212
@ -384,6 +384,7 @@ namespace nodetool
|
||||
bool is_addr_recently_failed(const epee::net_utils::network_address& addr);
|
||||
bool is_priority_node(const epee::net_utils::network_address& na);
|
||||
std::set<std::string> get_seed_nodes(cryptonote::network_type nettype) const;
|
||||
std::set<std::string> get_seed_nodes();
|
||||
bool connect_to_seed();
|
||||
|
||||
template <class Container>
|
||||
@ -467,7 +468,9 @@ namespace nodetool
|
||||
std::list<epee::net_utils::network_address> m_priority_peers;
|
||||
std::vector<epee::net_utils::network_address> m_exclusive_peers;
|
||||
std::vector<epee::net_utils::network_address> m_seed_nodes;
|
||||
bool m_fallback_seed_nodes_added;
|
||||
bool m_seed_nodes_initialized = false;
|
||||
boost::shared_mutex m_seed_nodes_lock;
|
||||
std::atomic_flag m_fallback_seed_nodes_added;
|
||||
std::vector<nodetool::peerlist_entry> m_command_line_peers;
|
||||
uint64_t m_peer_livetime;
|
||||
//keep connections to initiate some interactions
|
||||
|
@ -435,6 +435,8 @@ namespace nodetool
|
||||
|
||||
if (command_line::has_arg(vm, arg_p2p_seed_node))
|
||||
{
|
||||
boost::unique_lock<boost::shared_mutex> lock(m_seed_nodes_lock);
|
||||
|
||||
if (!parse_peers_and_add_to_container(vm, arg_p2p_seed_node, m_seed_nodes))
|
||||
return false;
|
||||
}
|
||||
@ -635,40 +637,23 @@ namespace nodetool
|
||||
}
|
||||
//-----------------------------------------------------------------------------------
|
||||
template<class t_payload_net_handler>
|
||||
typename node_server<t_payload_net_handler>::network_zone& node_server<t_payload_net_handler>::add_zone(const epee::net_utils::zone zone)
|
||||
std::set<std::string> node_server<t_payload_net_handler>::get_seed_nodes()
|
||||
{
|
||||
const auto zone_ = m_network_zones.lower_bound(zone);
|
||||
if (zone_ != m_network_zones.end() && zone_->first == zone)
|
||||
return zone_->second;
|
||||
|
||||
network_zone& public_zone = m_network_zones[epee::net_utils::zone::public_];
|
||||
return m_network_zones.emplace_hint(zone_, std::piecewise_construct, std::make_tuple(zone), std::tie(public_zone.m_net_server.get_io_service()))->second;
|
||||
if (!m_exclusive_peers.empty() || m_offline)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
//-----------------------------------------------------------------------------------
|
||||
template<class t_payload_net_handler>
|
||||
bool node_server<t_payload_net_handler>::init(const boost::program_options::variables_map& vm)
|
||||
{
|
||||
std::set<std::string> full_addrs;
|
||||
|
||||
bool res = handle_command_line(vm);
|
||||
CHECK_AND_ASSERT_MES(res, false, "Failed to handle command line");
|
||||
|
||||
m_fallback_seed_nodes_added = false;
|
||||
if (m_nettype == cryptonote::TESTNET)
|
||||
{
|
||||
memcpy(&m_network_id, &::config::testnet::NETWORK_ID, 16);
|
||||
full_addrs = get_seed_nodes(cryptonote::TESTNET);
|
||||
return get_seed_nodes(cryptonote::TESTNET);
|
||||
}
|
||||
else if (m_nettype == cryptonote::STAGENET)
|
||||
if (m_nettype == cryptonote::STAGENET)
|
||||
{
|
||||
memcpy(&m_network_id, &::config::stagenet::NETWORK_ID, 16);
|
||||
full_addrs = get_seed_nodes(cryptonote::STAGENET);
|
||||
return get_seed_nodes(cryptonote::STAGENET);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(&m_network_id, &::config::NETWORK_ID, 16);
|
||||
if (m_exclusive_peers.empty() && !m_offline)
|
||||
{
|
||||
|
||||
std::set<std::string> full_addrs;
|
||||
|
||||
// for each hostname in the seed nodes list, attempt to DNS resolve and
|
||||
// add the result addresses as seed nodes
|
||||
// TODO: at some point add IPv6 support, but that won't be relevant
|
||||
@ -754,17 +739,41 @@ namespace nodetool
|
||||
|
||||
for (const auto &peer: get_seed_nodes(cryptonote::MAINNET))
|
||||
full_addrs.insert(peer);
|
||||
m_fallback_seed_nodes_added = true;
|
||||
}
|
||||
}
|
||||
m_fallback_seed_nodes_added.test_and_set();
|
||||
}
|
||||
|
||||
for (const auto& full_addr : full_addrs)
|
||||
{
|
||||
MDEBUG("Seed node: " << full_addr);
|
||||
append_net_address(m_seed_nodes, full_addr, cryptonote::get_config(m_nettype).P2P_DEFAULT_PORT);
|
||||
return full_addrs;
|
||||
}
|
||||
//-----------------------------------------------------------------------------------
|
||||
template<class t_payload_net_handler>
|
||||
typename node_server<t_payload_net_handler>::network_zone& node_server<t_payload_net_handler>::add_zone(const epee::net_utils::zone zone)
|
||||
{
|
||||
const auto zone_ = m_network_zones.lower_bound(zone);
|
||||
if (zone_ != m_network_zones.end() && zone_->first == zone)
|
||||
return zone_->second;
|
||||
|
||||
network_zone& public_zone = m_network_zones[epee::net_utils::zone::public_];
|
||||
return m_network_zones.emplace_hint(zone_, std::piecewise_construct, std::make_tuple(zone), std::tie(public_zone.m_net_server.get_io_service()))->second;
|
||||
}
|
||||
//-----------------------------------------------------------------------------------
|
||||
template<class t_payload_net_handler>
|
||||
bool node_server<t_payload_net_handler>::init(const boost::program_options::variables_map& vm)
|
||||
{
|
||||
bool res = handle_command_line(vm);
|
||||
CHECK_AND_ASSERT_MES(res, false, "Failed to handle command line");
|
||||
|
||||
if (m_nettype == cryptonote::TESTNET)
|
||||
{
|
||||
memcpy(&m_network_id, &::config::testnet::NETWORK_ID, 16);
|
||||
}
|
||||
else if (m_nettype == cryptonote::STAGENET)
|
||||
{
|
||||
memcpy(&m_network_id, &::config::stagenet::NETWORK_ID, 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(&m_network_id, &::config::NETWORK_ID, 16);
|
||||
}
|
||||
MDEBUG("Number of seed nodes: " << m_seed_nodes.size());
|
||||
|
||||
m_config_folder = command_line::get_arg(vm, cryptonote::arg_data_dir);
|
||||
network_zone& public_zone = m_network_zones.at(epee::net_utils::zone::public_);
|
||||
@ -1541,6 +1550,20 @@ namespace nodetool
|
||||
template<class t_payload_net_handler>
|
||||
bool node_server<t_payload_net_handler>::connect_to_seed()
|
||||
{
|
||||
boost::upgrade_lock<boost::shared_mutex> seed_nodes_upgrade_lock(m_seed_nodes_lock);
|
||||
|
||||
if (!m_seed_nodes_initialized)
|
||||
{
|
||||
boost::upgrade_to_unique_lock<boost::shared_mutex> seed_nodes_lock(seed_nodes_upgrade_lock);
|
||||
m_seed_nodes_initialized = true;
|
||||
for (const auto& full_addr : get_seed_nodes())
|
||||
{
|
||||
MDEBUG("Seed node: " << full_addr);
|
||||
append_net_address(m_seed_nodes, full_addr, cryptonote::get_config(m_nettype).P2P_DEFAULT_PORT);
|
||||
}
|
||||
MDEBUG("Number of seed nodes: " << m_seed_nodes.size());
|
||||
}
|
||||
|
||||
if (m_seed_nodes.empty() || m_offline || !m_exclusive_peers.empty())
|
||||
return true;
|
||||
|
||||
@ -1561,16 +1584,19 @@ namespace nodetool
|
||||
break;
|
||||
if(++try_count > m_seed_nodes.size())
|
||||
{
|
||||
if (!m_fallback_seed_nodes_added)
|
||||
if (!m_fallback_seed_nodes_added.test_and_set())
|
||||
{
|
||||
MWARNING("Failed to connect to any of seed peers, trying fallback seeds");
|
||||
current_index = m_seed_nodes.size() - 1;
|
||||
{
|
||||
boost::upgrade_to_unique_lock<boost::shared_mutex> seed_nodes_lock(seed_nodes_upgrade_lock);
|
||||
|
||||
for (const auto &peer: get_seed_nodes(m_nettype))
|
||||
{
|
||||
MDEBUG("Fallback seed node: " << peer);
|
||||
append_net_address(m_seed_nodes, peer, cryptonote::get_config(m_nettype).P2P_DEFAULT_PORT);
|
||||
}
|
||||
m_fallback_seed_nodes_added = true;
|
||||
}
|
||||
if (current_index == m_seed_nodes.size() - 1)
|
||||
{
|
||||
MWARNING("No fallback seeds, continuing without seeds");
|
||||
@ -1604,9 +1630,8 @@ namespace nodetool
|
||||
// Only have seeds in the public zone right now.
|
||||
|
||||
size_t start_conn_count = get_public_outgoing_connections_count();
|
||||
if(!get_public_white_peers_count() && m_seed_nodes.size())
|
||||
if(!get_public_white_peers_count() && !connect_to_seed())
|
||||
{
|
||||
if (!connect_to_seed())
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user