34#include <boost/bind/bind.hpp>
35#include <boost/date_time/posix_time/posix_time.hpp>
36#include <boost/filesystem/operations.hpp>
37#include <boost/optional/optional.hpp>
38#include <boost/thread/thread.hpp>
39#include <boost/uuid/uuid_io.hpp>
40#include <boost/algorithm/string.hpp>
64#undef MONERO_DEFAULT_LOG_CATEGORY
65#define MONERO_DEFAULT_LOG_CATEGORY "net.p2p"
67#define NET_MAKE_IP(b1,b2,b3,b4) ((LPARAM)(((DWORD)(b1)<<24)+((DWORD)(b2)<<16)+((DWORD)(b3)<<8)+((DWORD)(b4))))
69#define MIN_WANTED_SEED_NODES 12
73 const auto &bytes =
a.to_bytes();
75 v4 = (v4 << 8) | bytes[12];
76 v4 = (v4 << 8) | bytes[13];
77 v4 = (v4 << 8) | bytes[14];
78 v4 = (v4 << 8) | bytes[15];
79 return boost::asio::ip::address_v4(v4);
84 template<
class t_payload_net_handler>
98 inline bool append_net_address(std::vector<epee::net_utils::network_address> & seed_nodes, std::string
const & addr,
uint16_t default_port);
100 template<
class t_payload_net_handler>
133 template<
class t_payload_net_handler>
146 CATCH_ENTRY_L0(
"node_server::init_config",
false);
150 template<
class t_payload_net_handler>
161 template<
class t_payload_net_handler>
175 template<
class t_payload_net_handler>
180 const time_t now = time(
nullptr);
186 if (now >= it->second)
195 *t = it->second - now;
203 auto ipv4_address =
address.template as<epee::net_utils::ipv4_network_address>();
204 std::map<epee::net_utils::ipv4_network_subnet, time_t>::iterator it;
207 if (now >= it->second)
210 MCLOG_CYAN(
el::Level::Info,
"global",
"Subnet " << it->first.host_str() <<
" unblocked.");
213 if (it->first.matches(ipv4_address))
216 *t = it->second - now;
227 template<
class t_payload_net_handler>
231 if (zone.m_current_number_of_in_peers >= zone.m_config.m_net_config.max_in_connection_count)
233 MWARNING(
"Exceeded max incoming connections, so dropping this one.");
239 MWARNING(
"CONNECTION FROM " <<
address.host_str() <<
" REFUSED, too many connections from the same address");
247 template<
class t_payload_net_handler>
253 const time_t now = time(
nullptr);
258 if (now > std::numeric_limits<time_t>::max() - seconds)
259 limit = std::numeric_limits<time_t>::max();
261 limit = now + seconds;
269 bool matches_blocked_subnet =
false;
272 auto ipv4_address = addr.template as<epee::net_utils::ipv4_network_address>();
275 if (jt->first.matches(ipv4_address))
277 matches_blocked_subnet =
true;
282 if (!matches_blocked_subnet)
285 else if (it->second < limit || !add_only)
291 std::vector<boost::uuids::uuid> conns;
296 if (cntxt.m_remote_address.is_same_host(addr))
298 conns.push_back(cntxt.m_connection_id);
305 if (addr.
port() == 0)
307 zone.second.m_peerlist.evict_host_from_peerlist(
true, pe);
308 zone.second.m_peerlist.evict_host_from_peerlist(
false, pe);
312 zone.second.m_peerlist.remove_from_peer_white(pe);
313 zone.second.m_peerlist.remove_from_peer_gray(pe);
314 zone.second.m_peerlist.remove_from_peer_anchor(addr);
317 for (
const auto &c: conns)
318 zone.second.m_net_server.get_config_object().close(c,
false);
324 MCLOG_CYAN(
el::Level::Info,
"global",
"Host " << host_str <<
" blocked.");
326 MINFO(
"Host " << host_str <<
" block time updated.");
330 template<
class t_payload_net_handler>
342 template<
class t_payload_net_handler>
345 const time_t now = time(
nullptr);
349 if (now > std::numeric_limits<time_t>::max() - seconds)
350 limit = std::numeric_limits<time_t>::max();
352 limit = now + seconds;
359 std::vector<boost::uuids::uuid> conns;
366 auto ipv4_address = cntxt.m_remote_address.template as<epee::net_utils::ipv4_network_address>();
369 conns.push_back(cntxt.m_connection_id);
373 for (
const auto &c: conns)
374 zone.second.m_net_server.get_config_object().close(c,
false);
376 for (
int i = 0; i < 2; ++i)
378 if (pe.adr.get_type_id() != epee::net_utils::ipv4_network_address::get_type_id())
380 return subnet.matches(pe.adr.as<const epee::net_utils::ipv4_network_address>());
389 MINFO(
"Subnet " << subnet.
host_str() <<
" blocked.");
393 template<
class t_payload_net_handler>
405 template<
class t_payload_net_handler>
413 MDEBUG(
"Host " <<
address.host_str() <<
" fail score=" << fails);
424 template<
class t_payload_net_handler>
426 const boost::program_options::variables_map&
vm
445 MWARNING(
"UPnP port mapping support was removed. The --igd option is currently non-functional.");
457 for(
const std::string& pr_str: perrs)
466 pe.
adr = std::move(*adr);
470 CHECK_AND_ASSERT_MES(
474 std::vector<epee::net_utils::network_address> resolved_addrs;
476 CHECK_AND_ASSERT_MES(r,
false,
"Failed to parse or resolve address from string: " << pr_str);
510 const boost::filesystem::path ban_list_path(ban_list);
511 boost::system::error_code ec;
512 if (!boost::filesystem::exists(ban_list_path, ec))
514 throw std::runtime_error(
"Can't find ban list file " + ban_list +
" - " + ec.message());
517 std::string banned_ips;
520 throw std::runtime_error(
"Failed to read ban list file " + ban_list);
523 std::istringstream iss(banned_ips);
524 for (std::string line; std::getline(iss, line); )
527 const size_t pound_idx =
line.find(
'#');
528 if (pound_idx != std::string::npos)
529 line.resize(pound_idx);
539 block_subnet(*subnet, std::numeric_limits<time_t>::max());
545 block_host(*parsed_addr, std::numeric_limits<time_t>::max());
548 MERROR(
"Invalid IP address or IPv4 subnet: " << line);
553 m_hide_my_port =
true;
556 m_payload_handler.set_no_sync(
true);
582 epee::byte_slice noise =
nullptr;
587 for (
auto&
proxy : *proxies)
590 if (
zone.m_connect !=
nullptr)
595 zone.m_connect = &socks_connect;
603 epee::byte_slice this_noise =
nullptr;
610 this_noise = noise.
clone();
613 zone.m_notifier = cryptonote::levin::notify{
614 zone.m_net_server.get_io_context(),
zone.m_net_server.get_config_shared(), std::move(this_noise),
proxy.
zone, pad_txs, m_payload_handler.get_core()
618 for (
const auto& zone : m_network_zones)
620 if (
zone.second.m_connect ==
nullptr)
631 const std::size_t tx_relay_zones = m_network_zones.size();
632 for (
auto& inbound : *inbounds)
634 network_zone&
zone = add_zone(inbound.our_address.get_zone());
636 if (!
zone.m_bind_ip.empty())
642 if (
zone.m_connect ==
nullptr && tx_relay_zones <= 1)
644 MERROR(
"Listed --" <<
arg_anonymous_inbound.name <<
" without listing any --" <<
arg_tx_proxy.name <<
". The latter is necessary for sending local txes over anonymity networks");
648 zone.m_bind_ip = std::move(inbound.local_ip);
649 zone.m_port = std::move(inbound.local_port);
650 zone.m_net_server.set_default_remote(std::move(inbound.default_remote));
651 zone.m_our_address = std::move(inbound.our_address);
653 if (!set_max_in_peers(zone, inbound.max_connections))
663 std::vector<epee::net_utils::network_address> & seed_nodes
664 , std::string
const & addr
668 using namespace boost::asio;
672 std::string port = std::to_string(default_port);
674 MINFO(
"Resolving node address: host=" << host <<
", port=" << port);
676 boost::system::error_code ec;
678 ip::tcp::resolver resolver(io_srv);
679 const auto results = resolver.resolve(host, port, boost::asio::ip::tcp::resolver::canonical_name, ec);
680 CHECK_AND_ASSERT_MES(!ec && !results.empty(),
false,
"Failed to resolve host name '" << host <<
"': " << ec.message() <<
':' << ec.value());
682 for (
const auto&
result : results)
684 const auto& endpoint =
result.endpoint();
685 if (endpoint.address().is_v4())
688 seed_nodes.push_back(na);
689 MINFO(
"Added node: " << na.
str());
694 seed_nodes.push_back(na);
695 MINFO(
"Added node: " << na.
str());
702 template<
class t_payload_net_handler>
705 std::set<std::string> full_addrs;
708 full_addrs.insert(
"176.9.0.187:28080");
709 full_addrs.insert(
"192.99.8.110:28080");
710 full_addrs.insert(
"37.187.74.171:28080");
711 full_addrs.insert(
"88.99.195.15:28080");
712 full_addrs.insert(
"5.104.84.64:28080");
716 full_addrs.insert(
"176.9.0.187:38080");
717 full_addrs.insert(
"192.99.8.110:38080");
718 full_addrs.insert(
"37.187.74.171:38080");
719 full_addrs.insert(
"88.99.195.15:38080");
720 full_addrs.insert(
"5.104.84.64:38080");
727 full_addrs.insert(
"176.9.0.187:18080");
728 full_addrs.insert(
"88.198.163.90:18080");
729 full_addrs.insert(
"192.99.8.110:18080");
730 full_addrs.insert(
"37.187.74.171:18080");
731 full_addrs.insert(
"88.99.195.15:18080");
732 full_addrs.insert(
"5.104.84.64:18080");
737 template<
class t_payload_net_handler>
763 std::set<std::string> full_addrs;
772 std::vector<std::vector<std::string>> dns_results;
776 const auto frame = std::make_shared<frame_t>();
783 boost::thread::attributes thread_attributes;
784 thread_attributes.set_stack_size(1024*1024);
786 std::list<boost::thread> dns_threads;
788 const std::weak_ptr<frame_t> frame_weak{frame};
791 boost::thread th = boost::thread(thread_attributes, [frame_weak, addr_str, result_index]
793 MDEBUG(
"dns_threads[" << result_index <<
"] created for: " << addr_str);
797 MINFO(
"dns_threads[" << result_index <<
"] addr_str: " << addr_str <<
" number of results: " << addr_list.size());
798 const auto frame = frame_weak.lock();
801 const boost::lock_guard<boost::mutex> lock{frame->sync};
802 frame->dns_results.at(result_index) = std::move(addr_list);
806 dns_threads.push_back(std::move(th));
811 boost::chrono::system_clock::time_point deadline = boost::chrono::system_clock::now() + boost::chrono::milliseconds(
CRYPTONOTE_DNS_TIMEOUT_MS);
813 for (boost::thread& th : dns_threads)
815 if (! th.try_join_until(deadline))
817 MWARNING(
"dns_threads[" << i <<
"] timed out");
824 const boost::lock_guard<boost::mutex> lock{frame->sync};
825 for (
const auto&
result : frame->dns_results)
831 for (
const auto& addr_string :
result)
840 if (full_addrs.empty())
841 MINFO(
"DNS seed node lookup either timed out or failed, falling back to defaults");
843 MINFO(
"Not enough DNS seed nodes found, using fallback defaults too");
846 full_addrs.insert(peer);
853 template<
class t_payload_net_handler>
864 "zbjkbsxc5munw3qusl7j2hpcmikhqocdf4pqhnhtpzw5nt5jrmofptid.onion:18083",
865 "plowsof3t5hogddwabaeiyrno25efmzfxyro2vligremt7sxpsclfaid.onion:18083",
866 "plowsoffjexmxalw73tkjmf422gq6575fc7vicuu4javzn2ynnte6tyd.onion:18083",
867 "plowsofe6cleftfmk2raiw5h2x66atrik3nja4bfd3zrfa2hdlgworad.onion:18083",
868 "aclc4e2jhhtr44guufbnwk5bzwhaecinax4yip4wr4tjn27sjsfg6zqd.onion:18083",
869 "lykcas4tus7mkm4bhsgqe4drtd4awi7gja24goscc47xfgzj54yofyqd.onion:18083",
877 "uqj3aphckqtjsitz7kxx5flqpwjlq5ppr3chazfued7xucv3nheq.b32.i2p",
878 "vdmnehdjkpkg57nthgnjfuaqgku673r5bpbqg56ix6fyqoywgqrq.b32.i2p",
879 "ugnlcdciyhghh2zert7c3kl4biwkirc43ke33jiy5slnd3mv2trq.b32.i2p",
886 throw std::logic_error{
"Bad zone given to get_seed_nodes"};
889 template<
class t_payload_net_handler>
894 return zone_->second;
900 template<
class t_payload_net_handler>
904 CHECK_AND_ASSERT_MES(
res,
false,
"Failed to handle command line");
908 CHECK_AND_ASSERT_MES(endpoint,
false,
"Failed to parse proxy: " <<
proxy <<
" - " << endpoint.error().message());
940 CHECK_AND_ASSERT_MES(
res,
false,
"Failed to init config.");
945 CHECK_AND_ASSERT_MES(
res,
false,
"Failed to init peerlist.");
949 m_network_zones.at(p.adr.get_zone()).m_peerlist.append_with_peer_white(p);
966 zone.second.m_net_server.get_config_object().set_handler(
this);
969 if (!zone.second.m_bind_ip.empty())
971 std::string ipv6_addr =
"";
972 std::string ipv6_port =
"";
973 zone.second.m_net_server.set_connection_filter(
this);
974 zone.second.m_net_server.set_connection_limit(
this);
975 MINFO(
"Binding (IPv4) on " << zone.second.m_bind_ip <<
":" << zone.second.m_port);
976 if (!zone.second.m_bind_ipv6_address.empty() &&
m_use_ipv6)
978 ipv6_addr = zone.second.m_bind_ipv6_address;
979 ipv6_port = zone.second.m_port_ipv6;
980 MINFO(
"Binding (IPv6) on " << zone.second.m_bind_ipv6_address <<
":" << zone.second.m_port_ipv6);
983 CHECK_AND_ASSERT_MES(
res,
false,
"Failed to bind server");
1000 template<
class t_payload_net_handler>
1006 template<
class t_payload_net_handler>
1012 _note(
"Thread monitor number of peers - start");
1019 unsigned int number_of_in_peers = 0;
1020 unsigned int number_of_out_peers = 0;
1023 if (cntxt.m_is_income)
1025 ++number_of_in_peers;
1029 ++number_of_out_peers;
1033 zone.second.m_current_number_of_in_peers = number_of_in_peers;
1034 zone.second.m_current_number_of_out_peers = number_of_out_peers;
1036 boost::this_thread::sleep_for(boost::chrono::seconds(1));
1038 _note(
"Thread monitor number of peers - done");
1046 int thrds_count = 10;
1047 boost::thread::attributes attrs;
1050 MINFO(
"Run net_service loop( " << thrds_count <<
" threads)...");
1053 LOG_ERROR(
"Failed to run net tcp server!");
1056 MINFO(
"net_service loop stopped.");
1060 template<
class t_payload_net_handler>
1069 template<
class t_payload_net_handler>
1077 zone.second.m_net_server.deinit_server();
1082 template<
class t_payload_net_handler>
1095 zone.second.m_peerlist.get_peerlist(active);
1100 MWARNING(
"Failed to save config to file " << state_file_path);
1103 CATCH_ENTRY_L0(
"node_server::store",
false);
1107 template<
class t_payload_net_handler>
1110 MDEBUG(
"[node] stopping server payload handler");
1112 MDEBUG(
"[node] sending stop signal");
1115 const auto close_all_connections = [&,
this]()
1117 std::list<boost::uuids::uuid> connection_ids;
1118 zone.second.m_net_server.get_config_object().foreach_connection([&](
const p2p_connection_context& cntxt) {
1119 connection_ids.push_back(cntxt.m_connection_id);
1122 for (
const auto &connection_id: connection_ids)
1124 MDEBUG(
"Closing connection " << connection_id);
1126 zone.second.m_net_server.get_config_object().close(connection_id,
true);
1127 MDEBUG(
"Closed connection " << connection_id);
1131 zone.second.m_net_server.send_stop_signal(close_all_connections);
1133 MDEBUG(
"[node] Stop signal sent");
1137 template<
class t_payload_net_handler>
1148 std::atomic<bool> hsh_result(
false);
1149 bool timeout =
false;
1154 epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){ev.raise();});
1166 LOG_WARNING_CC(context,
"COMMAND_HANDSHAKE Failed, wrong network! (" << rsp.node_data.network_id <<
"), closing connection.");
1172 LOG_WARNING_CC(context,
"COMMAND_HANDSHAKE: failed to handle_remote_peerlist(...), closing connection.");
1177 if(!just_take_peerlist)
1179 if(!
m_payload_handler.process_payload_sync_data(rsp.payload_data, context,
true))
1181 LOG_WARNING_CC(context,
"COMMAND_HANDSHAKE invoked, but process_payload_sync_data returned false, dropping connection.");
1186 pi = context.peer_id = rsp.node_data.peer_id;
1187 context.m_rpc_port = rsp.node_data.rpc_port;
1188 context.m_rpc_credits_per_hash = rsp.node_data.rpc_credits_per_hash;
1189 context.support_flags = rsp.node_data.support_flags;
1190 const auto azone = context.m_remote_address.get_zone();
1192 zone.m_peerlist.set_peer_just_seen(rsp.node_data.peer_id, context.m_remote_address, context.m_pruning_seed, context.m_rpc_port, context.m_rpc_credits_per_hash);
1197 LOG_DEBUG_CC(context,
"Connection to self detected, dropping connection");
1202 LOG_DEBUG_CC(context,
" COMMAND_HANDSHAKE INVOKED OK");
1205 LOG_DEBUG_CC(context,
" COMMAND_HANDSHAKE(AND CLOSE) INVOKED OK");
1219 zone.m_net_server.get_config_object().close(context_.m_connection_id,
false);
1221 else if (!just_take_peerlist)
1223 if (context_.support_flags == 0)
1224 try_get_support_flags(context_, [](p2p_connection_context& flags_context,
const uint32_t& support_flags)
1226 flags_context.support_flags = support_flags;
1233 template<
class t_payload_net_handler>
1243 context.m_in_timedsync = false;
1246 LOG_WARNING_CC(context,
"COMMAND_TIMED_SYNC invoke failed. (" << code <<
", " << epee::levin::get_err_descr(code) <<
")");
1252 LOG_WARNING_CC(context,
"COMMAND_TIMED_SYNC: failed to handle_remote_peerlist(...), closing connection.");
1253 m_network_zones.at(context.m_remote_address.get_zone()).m_net_server.get_config_object().close(context.m_connection_id, false);
1254 add_host_fail(context.m_remote_address);
1256 if(!context.m_is_income)
1257 m_network_zones.at(context.m_remote_address.get_zone()).m_peerlist.set_peer_just_seen(context.peer_id, context.m_remote_address, context.m_pruning_seed, context.m_rpc_port, context.m_rpc_credits_per_hash);
1260 m_network_zones.at(context.m_remote_address.get_zone()).m_net_server.get_config_object().close(context.m_connection_id, false);
1272 template<
class t_payload_net_handler>
1280 size_t res = (x*x*x)/(max_index*max_index*16*16*16);
1281 MDEBUG(
"Random connection index=" <<
res <<
"(x="<< x <<
", max_index=" << max_index <<
")");
1285 template<
class t_payload_net_handler>
1294 if(is_public && server->second.m_config.m_peer_id == peer.
id)
1298 server->second.m_net_server.get_config_object().foreach_connection([&, is_public](
const p2p_connection_context& cntxt)
1300 if((is_public && cntxt.
peer_id == peer.
id && peer.
adr.
is_same_host(cntxt.m_remote_address)) || (!cntxt.m_is_income && peer.
adr == cntxt.m_remote_address))
1310 template<
class t_payload_net_handler>
1319 if(is_public && server->second.m_config.m_peer_id == peer.
id)
1323 server->second.m_net_server.get_config_object().foreach_connection([&, is_public](
const p2p_connection_context& cntxt)
1325 if((is_public && cntxt.
peer_id == peer.
id && peer.
adr.
is_same_host(cntxt.m_remote_address)) || (!cntxt.m_is_income && peer.
adr == cntxt.m_remote_address))
1335 template<
class t_payload_net_handler>
1342 bool connected =
false;
1343 zone->second.m_net_server.get_config_object().foreach_connection([&](
const p2p_connection_context& cntxt)
1345 if(!cntxt.m_is_income && peer == cntxt.m_remote_address)
1356#define LOG_PRINT_CC_PRIORITY_NODE(priority, con, msg) \
1359 LOG_INFO_CC(con, "[priority]" << msg); \
1361 LOG_INFO_CC(con, msg); \
1365 template<
class t_payload_net_handler>
1369 if (zone.m_connect ==
nullptr)
1372 if (zone.m_our_address == na)
1375 if (zone.m_current_number_of_out_peers == zone.m_config.m_net_config.max_out_connection_count)
1379 else if (zone.m_current_number_of_out_peers > zone.m_config.m_net_config.max_out_connection_count)
1381 zone.m_net_server.get_config_object().del_out_connections(1);
1382 --(zone.m_current_number_of_out_peers);
1387 MDEBUG(
"Connecting to " << na.
str() <<
" (peer_type=" << peer_type <<
", last_seen: "
1401 con->m_anchor = peer_type ==
anchor;
1415 if(just_take_peerlist)
1417 zone.m_net_server.get_config_object().close(con->m_connection_id,
false);
1418 LOG_DEBUG_CC(*con,
"CONNECTION HANDSHAKED OK AND CLOSED.");
1429 pe_local.
rpc_port = con->m_rpc_port;
1431 zone.m_peerlist.append_with_peer_white(pe_local);
1437 ape.
first_seen = first_seen_stamp ? first_seen_stamp : time(
nullptr);
1439 zone.m_peerlist.append_with_peer_anchor(ape);
1440 zone.m_notifier.on_handshake_complete(con->m_connection_id, con->m_is_income);
1441 zone.m_notifier.new_out_connection();
1447 template<
class t_payload_net_handler>
1451 if (zone.m_connect ==
nullptr)
1454 LOG_PRINT_L1(
"Connecting to " << na.
str() <<
"(last_seen: "
1468 con->m_anchor =
false;
1479 zone.m_net_server.get_config_object().close(con->m_connection_id,
false);
1481 LOG_DEBUG_CC(*con,
"CONNECTION HANDSHAKED OK AND CLOSED.");
1486#undef LOG_PRINT_CC_PRIORITY_NODE
1489 template<
class t_payload_net_handler>
1496 template<
class t_payload_net_handler>
1510 template<
class t_payload_net_handler>
1513 for (
const auto& pe: anchor_peerlist) {
1517 _note(
"Peer is used");
1530 <<
"[peer_type=" <<
anchor
1534 _note(
"Handshake failed");
1545 template<
class t_payload_net_handler>
1554 if (actual_ip.is_v4_mapped())
1558 memcpy(&actual_ipv4, v4ip.to_bytes().data(),
sizeof(actual_ipv4));
1571 std::vector<peerlist_entry> peers;
1572 std::unordered_set<std::string> hosts;
1573 size_t total_peers_size = 0;
1574 zone.m_peerlist.foreach(use_white_list, [&peers, &hosts, &total_peers_size, &get_host_string](
const peerlist_entry &peer)
1577 const std::string host_string = get_host_string(peer.
adr);
1578 if (hosts.insert(host_string).second)
1580 peers.push_back(peer);
1587 const size_t peers_size = peers.size();
1588 MDEBUG(
"Looking at " << peers_size <<
" port-deduplicated peers out of " << total_peers_size
1589 <<
", i.e. dropping " << (total_peers_size - peers_size));
1591 std::set<uint64_t> tried_peers;
1594 size_t outer_loop_count = 0;
1595 while ((outer_loop_count < 3) && !zone.m_net_server.is_stop_signal_sent())
1603 std::set<uint32_t> connected_subnets;
1604 const uint32_t subnet_mask = ntohl(0xffffff00);
1614 connected_subnets.insert(actual_ip & subnet_mask);
1620 if (actual_ip.is_v4_mapped())
1624 memcpy(&actual_ipv4, v4ip.to_bytes().data(),
sizeof(actual_ipv4));
1625 connected_subnets.insert(actual_ipv4 & subnet_mask);
1632 std::vector<peerlist_entry> subnet_peers;
1633 std::vector<peerlist_entry> filtered;
1639 for (
int step = 0; step < 2; ++step)
1641 if ((step == 1) && !is_public_zone)
1644 const bool try_subnet_dedup = step == 0 && is_public_zone;
1645 const std::vector<peerlist_entry> &candidate_peers = try_subnet_dedup ? subnet_peers : peers;
1646 if (try_subnet_dedup)
1651 std::vector<size_t> shuffled_indexes(peers.size());
1652 std::iota(shuffled_indexes.begin(), shuffled_indexes.end(), 0);
1657 std::set<uint32_t> subnets = connected_subnets;
1658 for (
size_t index : shuffled_indexes)
1666 const uint32_t subnet = actual_ip & subnet_mask;
1667 take = subnets.find(subnet) == subnets.end();
1670 subnets.insert(subnet);
1676 if (actual_ip.is_v4_mapped())
1680 memcpy(&actual_ipv4, v4ip.to_bytes().data(),
sizeof(actual_ipv4));
1681 uint32_t subnet = actual_ipv4 & subnet_mask;
1682 take = subnets.find(subnet) == subnets.end();
1684 subnets.insert(subnet);
1689 subnet_peers.push_back(peer);
1695 return a.last_seen > b.last_seen;
1698 const size_t subnet_peers_size = subnet_peers.size();
1699 MDEBUG(
"Looking at " << subnet_peers_size <<
" subnet-deduplicated peers out of " << peers_size
1700 <<
", i.e. dropping " << (peers_size - subnet_peers_size));
1705 const size_t limit = use_white_list ? 20 : std::numeric_limits<size_t>::max();
1707 if (filtered.size() >= limit)
1709 if (tried_peers.count(peer.
id))
1713 if (next_needed_pruning_stripe == 0 || peer.
pruning_seed == 0)
1714 filtered.push_back(peer);
1716 filtered.insert(filtered.begin(), peer);
1720 if (!filtered.empty())
1724 if (filtered.empty())
1726 MINFO(
"No available peer in " << (use_white_list ?
"white" :
"gray") <<
" list filtered by " << next_needed_pruning_stripe);
1730 size_t random_index;
1742 for (
size_t i = 0; i < filtered.size(); ++i)
1747 MDEBUG(
"Reusing stripe " << next_needed_pruning_stripe <<
" peer " << peer.
adr.
str());
1756 CHECK_AND_ASSERT_MES(random_index < filtered.size(),
false,
"random_index < filtered.size() failed!!");
1761 if (tried_peers.count(candidate.
id))
1764 tried_peers.insert(candidate.
id);
1766 _note(
"Considering connecting (out) to " << (use_white_list ?
"white" :
"gray") <<
" list peer: " <<
1768 " (stripe " << next_needed_pruning_stripe <<
" needed), in loop pass " << outer_loop_count);
1770 if (zone.m_our_address == candidate.
adr)
1775 _note(
"Peer is used");
1780 _note(
"Not allowed");
1785 _note(
"Recently failed");
1791 <<
"[peer_list=" << (use_white_list ?
white :
gray)
1794 const time_t begin_connect = time(NULL);
1796 time_t fail_connect = time(NULL);
1807 template<
class t_payload_net_handler>
1811 boost::upgrade_lock<boost::shared_mutex> seed_nodes_upgrade_lock(server.
m_seed_nodes_lock);
1816 boost::upgrade_to_unique_lock<boost::shared_mutex> seed_nodes_lock(seed_nodes_upgrade_lock);
1821 MDEBUG(
"Seed node: " << full_addr);
1824 MDEBUG(
"Number of seed nodes: " << server.
m_seed_nodes.size());
1830 size_t try_count = 0;
1831 bool is_connected_to_at_least_one_seed_node =
false;
1841 is_connected_to_at_least_one_seed_node =
true;
1849 MWARNING(
"Failed to connect to any of seed peers, trying fallback seeds");
1852 boost::upgrade_to_unique_lock<boost::shared_mutex> seed_nodes_lock(seed_nodes_upgrade_lock);
1856 MDEBUG(
"Fallback seed node: " << peer);
1862 MWARNING(
"No fallback seeds, continuing without seeds");
1869 if (!is_connected_to_at_least_one_seed_node)
1870 MWARNING(
"Failed to connect to any of seed peers, continuing without seeds");
1880 template<
class t_payload_net_handler>
1890 bool one_succeeded =
false;
1894 if(!zone.second.m_peerlist.get_white_peers_count() && !
connect_to_seed(zone.first))
1906 while(conn_count < zone.second.m_config.m_net_config.max_out_connection_count)
1908 const size_t expected_white_connections =
m_payload_handler.get_next_needed_pruning_stripe().second ? zone.second.m_config.m_net_config.max_out_connection_count : base_expected_white_connections;
1909 if(conn_count < expected_white_connections)
1929 if(zone.second.m_net_server.is_stop_signal_sent())
1932 if (new_conn_count <= conn_count)
1936 boost::this_thread::sleep_for(boost::chrono::seconds(1));
1939 conn_count = new_conn_count;
1942 if (start_conn_count ==
get_outgoing_connections_count(zone.second) && start_conn_count < zone.second.m_config.m_net_config.max_out_connection_count)
1944 MINFO(
"Failed to connect to any, trying seeds");
1948 one_succeeded =
true;
1951 return one_succeeded;
1954 template<
class t_payload_net_handler>
1960 std::vector<anchor_peerlist_entry> apl;
1962 if (peer_type ==
anchor) {
1963 zone.m_peerlist.get_and_empty_anchor_peerlist(apl);
1968 if(conn_count < expected_connections)
1970 if(zone.m_net_server.is_stop_signal_sent())
1973 MDEBUG(
"Making expected connection, type " << peer_type <<
", " << conn_count <<
"/" << expected_connections <<
" connections");
1990 template<
class t_payload_net_handler>
1999 template<
class t_payload_net_handler>
2005 if(cntxt.m_is_income)
2012 template<
class t_payload_net_handler>
2018 if(!cntxt.m_is_income && !cntxt.
is_ping)
2028 zone.m_current_number_of_out_peers = count;
2033 template<
class t_payload_net_handler>
2042 template<
class t_payload_net_handler>
2050 if(cntxt.m_is_income)
2058 template<
class t_payload_net_handler>
2067 template<
class t_payload_net_handler>
2076 template<
class t_payload_net_handler>
2084 template<
class t_payload_net_handler>
2089 zone.second.m_peerlist.get_peerlist(
gray,
white);
2093 template<
class t_payload_net_handler>
2105 template<
class t_payload_net_handler>
2113 static const std::vector<std::string> dns_urls = {
2114 "blocklist.moneropulse.se"
2115 ,
"blocklist.moneropulse.org"
2116 ,
"blocklist.moneropulse.net"
2117 ,
"blocklist.moneropulse.co"
2118 ,
"blocklist.moneropulse.fr"
2119 ,
"blocklist.moneropulse.de"
2120 ,
"blocklist.moneropulse.ch"
2123 std::vector<std::string> records;
2127 unsigned good = 0, bad = 0;
2128 for (
const auto& record : records)
2130 std::vector<std::string> ips;
2131 boost::split(ips, record, boost::is_any_of(
";"));
2132 for (
const auto &ip: ips)
2150 MWARNING(
"Invalid IP address or subnet from DNS blocklist: " << ip <<
" - " << parsed_addr.
error());
2155 MINFO(good <<
" addresses added to the blocklist");
2159 template<
class t_payload_net_handler>
2170 MGINFO(
"Incoming connections disabled, enable them for full connectivity");
2175 MCLOG_RED(level,
"global",
"No incoming connections - check firewalls/routers allow port " <<
get_this_peer_port());
2181 template<
class t_payload_net_handler>
2184 MDEBUG(
"STARTED PEERLIST IDLE HANDSHAKE");
2185 typedef std::list<std::pair<epee::net_utils::connection_context_base, peerid_type> > local_connects_type;
2186 local_connects_type cncts;
2194 cncts.push_back(local_connects_type::value_type(cntxt, cntxt.
peer_id));
2200 std::for_each(cncts.begin(), cncts.end(), [&](
const typename local_connects_type::value_type& vl){do_peer_timed_sync(vl.first, vl.second);});
2202 MDEBUG(
"FINISHED PEERLIST IDLE HANDSHAKE");
2206 template<
class t_payload_net_handler>
2209 for (
size_t i = 0; i < local_peerlist.size(); ++i)
2211 bool ignore =
false;
2223 else if (ipv4.port() == be.
rpc_port)
2230 MDEBUG(
"Ignoring " << be.
adr.
str());
2231 std::swap(local_peerlist[i], local_peerlist[local_peerlist.size() - 1]);
2232 local_peerlist.resize(local_peerlist.size() - 1);
2236 local_peerlist[i].last_seen = 0;
2241 template<
class t_payload_net_handler>
2246 MWARNING(context <<
"peer sent " << peerlist.size() <<
" peers, considered spamming");
2249 std::vector<peerlist_entry> peerlist_ = peerlist;
2254 for(
const auto& peer : peerlist_)
2256 if(peer.adr.get_zone() != zone)
2258 MWARNING(context <<
" sent peerlist from another zone, dropping");
2263 LOG_DEBUG_CC(context,
"REMOTE PEERLIST: remote peerlist size=" << peerlist_.size());
2271 template<
class t_payload_net_handler>
2274 node_data.
peer_id = zone.m_config.m_peer_id;
2286 template<
class t_payload_net_handler>
2289 rsp.support_flags =
m_network_zones.at(context.m_remote_address.get_zone()).m_config.m_support_flags;
2293 template<
class t_payload_net_handler>
2296 m_network_zones.at(context.m_remote_address.get_zone()).m_net_server.get_config_object().request_callback(context.m_connection_id);
2299 template<
class t_payload_net_handler>
2303 std::sort(connections.begin(), connections.end());
2305 for(
const auto& c_id: connections)
2314 if (c_id.first <= zone->first)
2319 if (zone->first == c_id.first)
2320 zone->second.m_net_server.get_config_object().send(message.clone(), c_id.second);
2325 template<
class t_payload_net_handler>
2330 const auto send = [&txs, &
source, tx_relay] (std::pair<const enet::zone, network_zone>& network)
2332 if (network.second.m_notifier.send_txs(std::move(txs),
source, tx_relay))
2333 return network.first;
2334 return enet::zone::invalid;
2338 return enet::zone::invalid;
2340 if (origin != enet::zone::invalid)
2349 static_assert(std::is_same<std::underlying_type<enet::zone>::type, std::uint8_t>{},
"expected uint8_t zone");
2350 static_assert(unsigned(enet::zone::invalid) == 0,
"invalid expected to be 0");
2351 static_assert(unsigned(enet::zone::public_) == 1,
"public_ expected to be 1");
2352 static_assert(unsigned(enet::zone::i2p) == 2,
"i2p expected to be 2");
2353 static_assert(unsigned(enet::zone::tor) == 3,
"tor expected to be 3");
2358 if (enet::zone::tor < network->first)
2361 const auto status = network->second.m_notifier.get_status();
2362 if (status.has_noise && status.connections_filled)
2363 return send(*network);
2369 if (enet::zone::tor < network->first)
2372 const auto status = network->second.m_notifier.get_status();
2373 if (network->second.m_connect && status.has_outgoing)
2374 return send(*network);
2377 MWARNING(
"Unable to send " << txs.size() <<
" transaction(s): anonymity networks had no outgoing connections");
2378 return enet::zone::invalid;
2381 template<
class t_payload_net_handler>
2387 template<
class t_payload_net_handler>
2394 int res = zone.m_net_server.get_config_object().send(message.finalize_notify(command), context.m_connection_id);
2398 template<
class t_payload_net_handler>
2401 m_network_zones.at(context.m_remote_address.get_zone()).m_net_server.get_config_object().close(context.m_connection_id,
false);
2405 template<
class t_payload_net_handler>
template<
class t_callback>
2412 CHECK_AND_ASSERT_MES(address_ok,
false,
2413 "Only IPv4 or IPv6 addresses are supported here");
2418 boost::asio::ip::address_v6 ipv6_addr;
2429 ip = ipv6_addr.to_string();
2434 if(!zone.m_peerlist.is_host_allowed(context.m_remote_address))
2449 bool r = zone.m_net_server.connect_async(ip, port, zone.m_config.m_net_config.ping_connection_timeout, [cb,
address, pr,
this](
2451 const boost::system::error_code& ec)->bool
2455 LOG_WARNING_CC(ping_context,
"back ping connect failed to " << address.str());
2476 LOG_WARNING_CC(ping_context,
"Failed to invoke COMMAND_PING to " << address.str() <<
"(" << code <<
", " << epee::levin::get_err_descr(code) <<
")");
2483 LOG_WARNING_CC(ping_context,
"back ping invoke wrong response \"" << rsp.status <<
"\" from" << address.str() <<
", hsh_peer_id=" << pr_ <<
", rsp.peer_id=" << peerid_to_string(rsp.peer_id));
2484 zone.m_net_server.get_config_object().close(ping_context.m_connection_id, false);
2487 zone.m_net_server.get_config_object().close(ping_context.m_connection_id,
false);
2494 zone.m_net_server.get_config_object().close(ping_context.m_connection_id,
false);
2498 },
"0.0.0.0", m_ssl_support, p2p_connection_context{
true });
2501 LOG_WARNING_CC(context,
"Failed to call connect_async, network error.");
2506 template<
class t_payload_net_handler>
2517 support_flags_request,
2523 LOG_WARNING_CC(context_,
"COMMAND_REQUEST_SUPPORT_FLAGS invoke failed. (" << code <<
", " << epee::levin::get_err_descr(code) <<
")");
2527 f(context_, rsp.support_flags);
2535 template<
class t_payload_net_handler>
2538 if(!
m_payload_handler.process_payload_sync_data(arg.payload_data, context,
false))
2540 LOG_WARNING_CC(context,
"Failed to process_payload_sync_data(), dropping connection");
2550 const bool outgoing_to_same_zone = !context.m_is_income && zone.m_our_address.get_zone() == zone_type;
2553 std::vector<peerlist_entry> local_peerlist_new;
2554 zone.m_peerlist.get_peerlist_head(local_peerlist_new,
true, max_peerlist_size);
2562 if(outgoing_to_same_zone)
2564 local_peerlist_new.insert(
2565 local_peerlist_new.begin() +
crypto::rand_range(std::size_t(0), local_peerlist_new.size()),
2571 rsp.local_peerlist_new.reserve(local_peerlist_new.size());
2572 for (
auto &pe: local_peerlist_new)
2574 if (!context.sent_addresses.insert(pe.
adr).second)
2576 rsp.local_peerlist_new.push_back(std::move(pe));
2584 template<
class t_payload_net_handler>
2590 LOG_INFO_CC(context,
"WRONG NETWORK AGENT CONNECTED! id=" << arg.node_data.network_id);
2596 if(!context.m_is_income)
2598 LOG_WARNING_CC(context,
"COMMAND_HANDSHAKE came not from incoming connection");
2606 LOG_WARNING_CC(context,
"COMMAND_HANDSHAKE came, but seems that connection already have associated peer_id (double COMMAND_HANDSHAKE?)");
2611 const auto azone = context.m_remote_address.get_zone();
2618 LOG_DEBUG_CC(context,
"Connection to self detected, dropping connection");
2623 if(!
m_payload_handler.process_payload_sync_data(arg.payload_data, context,
true))
2625 LOG_WARNING_CC(context,
"COMMAND_HANDSHAKE came, but process_payload_sync_data returned false, dropping connection.");
2630 zone.m_notifier.on_handshake_complete(context.m_connection_id, context.m_is_income);
2633 context.peer_id = arg.node_data.peer_id;
2634 context.m_in_timedsync =
false;
2635 context.m_rpc_port = arg.node_data.rpc_port;
2636 context.m_rpc_credits_per_hash = arg.node_data.rpc_credits_per_hash;
2637 context.support_flags = arg.node_data.support_flags;
2639 if(arg.node_data.my_port && zone.m_can_pingback)
2642 uint32_t port_l = arg.node_data.my_port;
2644 try_ping(arg.node_data, context, [peer_id_l, port_l, context,
this]()
2646 CHECK_AND_ASSERT_MES((context.m_remote_address.get_type_id() == epee::net_utils::ipv4_network_address::get_type_id() || context.m_remote_address.get_type_id() == epee::net_utils::ipv6_network_address::get_type_id()), void(),
2647 "Only IPv4 or IPv6 addresses are supported here");
2650 const epee::net_utils::network_address na = context.m_remote_address;
2651 if (context.m_remote_address.get_type_id() == epee::net_utils::ipv4_network_address::get_type_id())
2653 pe.adr = epee::net_utils::ipv4_network_address(na.as<epee::net_utils::ipv4_network_address>().ip(), port_l);
2657 pe.adr = epee::net_utils::ipv6_network_address(na.as<epee::net_utils::ipv6_network_address>().ip(), port_l);
2666 this->m_network_zones.at(context.m_remote_address.get_zone()).m_peerlist.append_with_peer_white(pe);
2667 LOG_DEBUG_CC(context,
"PING SUCCESS " << context.m_remote_address.host_str() <<
":" << port_l);
2671 if (context.support_flags == 0)
2672 try_get_support_flags(context, [](p2p_connection_context& flags_context,
const uint32_t& support_flags)
2674 flags_context.support_flags = support_flags;
2678 zone.m_peerlist.get_peerlist_head(rsp.local_peerlist_new,
true);
2679 for (
const auto &e: rsp.local_peerlist_new)
2680 context.sent_addresses.insert(e.adr);
2681 get_local_node_data(rsp.node_data, zone);
2682 m_payload_handler.get_payload_sync_data(rsp.payload_data);
2687 template<
class t_payload_net_handler>
2692 rsp.peer_id =
m_network_zones.at(context.m_remote_address.get_zone()).m_config.m_peer_id;
2696 template<
class t_payload_net_handler>
2699 std::vector<peerlist_entry> pl_white;
2700 std::vector<peerlist_entry> pl_gray;
2702 zone.second.m_peerlist.get_peerlist(pl_gray, pl_white);
2707 template<
class t_payload_net_handler>
2714 template<
class t_payload_net_handler>
2718 std::stringstream ss;
2723 ss << cntxt.m_remote_address.str()
2725 <<
" \t\tconn_id " << cntxt.m_connection_id << (cntxt.m_is_income ?
" INC":
" OUT")
2730 std::string
s = ss.str();
2734 template<
class t_payload_net_handler>
2740 template<
class t_payload_net_handler>
2744 if (!zone.m_net_server.is_stop_signal_sent() && !context.m_is_income) {
2746 na = context.m_remote_address;
2748 zone.m_peerlist.remove_from_peer_anchor(na);
2751 if (!zone.m_net_server.is_stop_signal_sent()) {
2752 zone.m_notifier.on_connection_close(context.m_connection_id);
2759 template<
class t_payload_net_handler>
2765 template<
class t_payload_net_handler>
template <
class Container>
2783 template<
class t_payload_net_handler>
template <
class Container>
2788 for(
const std::string& pr_str: perrs)
2795 container.push_back(std::move(*adr));
2798 std::vector<epee::net_utils::network_address> resolved_addrs;
2800 CHECK_AND_ASSERT_MES(r,
false,
"Failed to parse or resolve address from string: " << pr_str);
2803 container.push_back(addr);
2810 template<
class t_payload_net_handler>
2817 zone.m_config.m_net_config.max_out_connection_count = max;
2821 template<
class t_payload_net_handler>
2824 zone.m_config.m_net_config.max_in_connection_count = max;
2828 template<
class t_payload_net_handler>
2835 public_zone->second.
m_config.m_net_config.max_out_connection_count = count;
2842 template<
class t_payload_net_handler>
2848 return public_zone->second.
m_config.m_net_config.max_out_connection_count;
2851 template<
class t_payload_net_handler>
2858 public_zone->second.
m_config.m_net_config.max_in_connection_count = count;
2864 template<
class t_payload_net_handler>
2870 return public_zone->second.
m_config.m_net_config.max_in_connection_count;
2873 template<
class t_payload_net_handler>
2880 _dbg1(
"Set ToS flag " << flag);
2884 template<
class t_payload_net_handler>
2894 MINFO(
"Set limit-up to " << limit <<
" kB/s");
2898 template<
class t_payload_net_handler>
2906 MINFO(
"Set limit-down to " << limit <<
" kB/s");
2910 template<
class t_payload_net_handler>
2928 MINFO(
"Set limit-up to " << limit_up <<
" kB/s");
2932 MINFO(
"Set limit-down to " << limit_down <<
" kB/s");
2938 template<
class t_payload_net_handler>
2948 if (cntxt.m_is_income && cntxt.m_remote_address.is_same_host(
address)) {
2963 template<
class t_payload_net_handler>
2974 if (zone.second.m_net_server.is_stop_signal_sent())
2977 if (zone.second.m_connect ==
nullptr)
2981 if (!zone.second.m_peerlist.get_random_gray_peer(pe))
2986 zone.second.m_peerlist.remove_from_peer_gray(pe);
2998 template<
class t_payload_net_handler>
3006 MINFO(
"adding stripe " << stripe <<
" peer: " << context.m_remote_address.str());
3012 template<
class t_payload_net_handler>
3020 MINFO(
"removing stripe " << stripe <<
" peer: " << context.m_remote_address.str());
3025 template<
class t_payload_net_handler>
3029 MINFO(
"clearing used stripe peers");
3034 template<
typename t_payload_net_handler>
3035 boost::optional<p2p_connection_context_t<typename t_payload_net_handler::connection_context>>
3038 auto result =
socks_connect_internal(zone.m_net_server.get_stop_signal(), zone.m_net_server.get_io_context(), zone.m_proxy_address, remote);
3042 if (zone.m_net_server.add_connection(context, std::move(*
result), remote, ssl_support))
3043 return {std::move(context)};
3048 template<
typename t_payload_net_handler>
3049 boost::optional<p2p_connection_context_t<typename t_payload_net_handler::connection_context>>
3054 CHECK_AND_ASSERT_MES(is_ipv4 || is_ipv6, boost::none,
3055 "Only IPv4 or IPv6 addresses are supported here");
3069 address = ipv6.ip().to_string();
3074 LOG_ERROR(
"Only IPv4 or IPv6 addresses are supported here");
3079 const bool res = zone.m_net_server.connect(
address, port,
3080 zone.m_config.m_net_config.connection_timeout,
3081 con,
"0.0.0.0", ssl_support);
3084 return {std::move(con)};
#define s(x, c)
Definition aesb.c:47
cryptonote::block b
Definition block.cpp:40
Provides tx notification privacy.
Definition levin_notify.h:70
Definition byte_slice.h:69
byte_slice clone() const noexcept
Definition byte_slice.h:124
bool empty() const noexcept
Definition byte_slice.h:132
Provides space for levin (p2p) header, so that payload can be sent without copy.
Definition levin_base.h:132
byte_slice finalize_notify(uint32_t command)
Definition levin_base.h:152
bool add_idle_handler(t_handler t_callback, uint64_t timeout_ms)
Definition abstract_tcp_server2.h:468
bool is_stop_signal_sent() const noexcept
Definition abstract_tcp_server2.h:384
boost::asio::io_context & get_io_context()
Definition abstract_tcp_server2.h:437
epee::levin::async_protocol_handler< p2p_connection_context >::connection_context t_connection_context
Definition abstract_tcp_server2.h:357
int get_binded_port_ipv6()
Definition abstract_tcp_server2.h:428
t_protocol_handler::config_type & get_config_object()
Definition abstract_tcp_server2.h:415
bool run_server(size_t threads_count, bool wait=true, const boost::thread::attributes &attrs=boost::thread::attributes())
Run the server's io_context loop.
Definition abstract_tcp_server2.inl:1490
void set_threads_prefix(const std::string &prefix_name)
Definition abstract_tcp_server2.inl:1459
std::shared_ptr< typename t_protocol_handler::config_type > get_config_shared()
Definition abstract_tcp_server2.h:421
int get_binded_port()
Definition abstract_tcp_server2.h:427
Represents a single connection from a client.
Definition abstract_tcp_server2.h:100
Definition net_utils_base.h:69
static constexpr address_type get_type_id() noexcept
Definition net_utils_base.h:92
std::string host_str() const
Definition net_utils_base.cpp:31
Definition net_utils_base.h:125
bool matches(const ipv4_network_address &address) const
Definition net_utils_base.cpp:61
std::string host_str() const
Definition net_utils_base.cpp:58
Definition net_utils_base.h:172
static constexpr address_type get_type_id() noexcept
Definition net_utils_base.h:198
Definition net_utils_base.h:225
bool is_loopback() const
Definition net_utils_base.h:314
std::string str() const
Definition net_utils_base.h:312
address_type get_type_id() const
Definition net_utils_base.h:316
bool is_same_host(const network_address &other) const
Definition net_utils_base.cpp:90
std::uint16_t port() const
Definition net_utils_base.h:319
bool is_local() const
Definition net_utils_base.h:315
std::string host_str() const
Definition net_utils_base.h:313
zone get_zone() const
Definition net_utils_base.h:317
bool is_blockable() const
Definition net_utils_base.h:318
const Type & as() const
Definition net_utils_base.h:320
*return False if otherwise error()
#define CRYPTONOTE_NOISE_BYTES
Definition cryptonote_config.h:118
#define P2P_MAX_PEERS_IN_HANDSHAKE
Definition cryptonote_config.h:143
#define P2P_SUPPORT_FLAGS
Definition cryptonote_config.h:161
#define P2P_NET_DATA_FILENAME
Definition cryptonote_config.h:168
#define P2P_FAILED_ADDR_FORGET_SECONDS
Definition cryptonote_config.h:155
#define P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT
Definition cryptonote_config.h:148
#define P2P_DEFAULT_PEERS_IN_HANDSHAKE
Definition cryptonote_config.h:142
#define CRYPTONOTE_PRUNING_LOG_STRIPES
Definition cryptonote_config.h:207
#define P2P_DEFAULT_ANCHOR_CONNECTIONS_COUNT
Definition cryptonote_config.h:150
#define P2P_DEFAULT_INVOKE_TIMEOUT
Definition cryptonote_config.h:147
#define THREAD_STACK_SIZE
Definition cryptonote_config.h:172
#define P2P_DEFAULT_CONNECTIONS_COUNT
Definition cryptonote_config.h:139
#define P2P_DEFAULT_WHITELIST_CONNECTIONS_PERCENT
Definition cryptonote_config.h:149
#define DNS_BLOCKLIST_LIFETIME
Definition cryptonote_config.h:212
#define P2P_IP_FAILS_BEFORE_BLOCK
Definition cryptonote_config.h:157
#define CRYPTONOTE_DNS_TIMEOUT_MS
Definition cryptonote_config.h:38
#define MONERO_UNWRAP(...)
Definition expect.h:61
void * memcpy(void *a, const void *b, size_t c)
Definition glibc_compat.cpp:16
const char * res
Definition hmac_keccak.cpp:42
#define LEVIN_ERROR_CONNECTION_DESTROYED
Definition levin_base.h:105
#define LEVIN_ERROR_CONNECTION_TIMEDOUT
Definition levin_base.h:106
#define AUTO_VAL_INIT(v)
Definition misc_language.h:36
line
Definition check.py:23
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
Definition command_line.h:187
bool is_arg_defaulted(const boost::program_options::variables_map &vm, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg)
Definition command_line.h:263
std::enable_if<!std::is_same< T, bool >::value, bool >::type has_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg)
Definition command_line.h:256
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
Definition command_line.h:269
boost::uuids::uuid const NETWORK_ID
Definition cryptonote_config.h:291
uint16_t const P2P_DEFAULT_PORT
Definition cryptonote_config.h:288
boost::uuids::uuid const NETWORK_ID
Definition cryptonote_config.h:276
uint16_t const P2P_DEFAULT_PORT
Definition cryptonote_config.h:273
boost::uuids::uuid const NETWORK_ID
Definition cryptonote_config.h:233
uint16_t const P2P_DEFAULT_PORT
Definition cryptonote_config.h:230
T rand()
Definition crypto.h:174
std::enable_if< std::is_integral< T >::value, T >::type rand_range(T range_min, T range_max)
Definition crypto.h:195
std::enable_if< std::is_unsigned< T >::value, T >::type rand_idx(T sz)
Definition crypto.h:204
@ FAKECHAIN
Definition cryptonote_config.h:306
@ TESTNET
Definition cryptonote_config.h:304
@ MAINNET
Definition cryptonote_config.h:303
@ STAGENET
Definition cryptonote_config.h:305
const command_line::arg_descriptor< bool > arg_regtest_on
Definition cryptonote_core.cpp:85
const command_line::arg_descriptor< bool > arg_offline
Definition cryptonote_core.cpp:115
relay_method
Methods tracking how a tx was received and relayed.
Definition enums.h:37
const command_line::arg_descriptor< bool, false > arg_testnet_on
Definition cryptonote_core.cpp:75
const command_line::arg_descriptor< std::string, false, true, 3 > arg_data_dir
Definition cryptonote_core.cpp:100
const command_line::arg_descriptor< bool, false > arg_stagenet_on
Definition cryptonote_core.cpp:80
const config_t & get_config(network_type nettype)
Definition cryptonote_config.h:321
Level
Represents enumeration for severity level used to determine level of logging.
Definition easylogging++.h:591
@ Warning
Useful when application has potentially harmful situtaions.
Definition easylogging++.h:603
@ Info
Mainly useful to represent current progress of application.
Definition easylogging++.h:607
bool load_file_to_string(const std::string &path_to_file, std::string &target_str, size_t max_size=1000000000)
Definition file_io_utils.cpp:105
const char * get_err_descr(int err)
Definition levin_base.h:113
byte_slice make_noise_notify(std::size_t noise_bytes)
Definition levin_base.cpp:69
std::string get_time_interval_string(const time_t &time_)
Definition time_helper.h:58
Definition abstract_http_client.h:36
const char * zone_to_string(zone value) noexcept
Definition net_utils_base.cpp:135
@ ipv4
Definition enums.h:43
zone
Definition enums.h:50
@ public_
Definition enums.h:52
@ i2p
Definition enums.h:53
@ tor
Definition enums.h:54
std::string print_connection_context(const connection_context_base &ctx)
Definition net_utils_base.cpp:121
bool async_invoke_remote_command2(const epee::net_utils::connection_context_base &context, int command, const t_arg &out_struct, t_transport &transport, const callback_t &cb, size_t inv_timeout=LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED)
Definition levin_abstract_invoke2.h:87
ssl_support_t
Definition net_ssl.h:49
@ e_ssl_support_disabled
Definition net_ssl.h:50
expect< epee::net_utils::network_address > get_network_address(const boost::string_ref address, const std::uint16_t default_port)
Definition parse.cpp:159
void get_network_address_host_and_port(const std::string &address, std::string &host, std::string &port)
Takes a valid address string (IP, Tor, I2P, or DNS name) and splits it into host and port.
Definition parse.cpp:131
@ unsupported_address
Type not supported by get_network_address.
Definition error.h:52
expect< epee::net_utils::ipv4_network_subnet > get_ipv4_subnet_address(const boost::string_ref address, bool allow_implicit_32)
Definition parse.cpp:203
#define LOG_PRINT_CC_PRIORITY_NODE(priority, con, msg)
Definition net_node.inl:1356
#define MIN_WANTED_SEED_NODES
Definition net_node.inl:69
static boost::asio::ip::address_v4 make_address_v4_from_v6(const boost::asio::ip::address_v6 &a)
Definition net_node.inl:71
#define LOG_DEBUG_CC(ct, message)
Definition net_utils_base.h:472
#define LOG_WARNING_CC(ct, message)
Definition net_utils_base.h:470
#define LOG_INFO_CC(ct, message)
Definition net_utils_base.h:471
#define LOG_TRACE_CC(ct, message)
Definition net_utils_base.h:473
#define PING_OK_RESPONSE_STATUS_TEXT
Definition p2p_protocol_defs.h:286
const CharType(& source)[N]
Definition pointer.h:1147
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1124
tools::wallet2::message_signature_result_t result
Definition signature.cpp:62
static cryptonote::account_public_address address
Definition signature.cpp:38
unsigned short uint16_t
Definition stdint.h:125
signed __int64 int64_t
Definition stdint.h:135
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
Definition command_line.h:53
uint16_t const P2P_DEFAULT_PORT
Definition cryptonote_config.h:314
Definition net_utils_base.h:367
const network_address m_remote_address
Definition net_utils_base.h:369
static expect< endpoint > get(boost::string_ref uri)
Definition parse.cpp:270
int64_t first_seen
Definition p2p_protocol_defs.h:106
AddressType adr
Definition p2p_protocol_defs.h:104
peerid_type id
Definition p2p_protocol_defs.h:105
uint32_t support_flags
Definition net_node.h:121
bool is_ping
Definition net_node.h:123
peerid_type peer_id
Definition net_node.h:120
bool m_in_timedsync
Definition net_node.h:122
uint32_t pruning_seed
Definition p2p_protocol_defs.h:77
AddressType adr
Definition p2p_protocol_defs.h:74
uint16_t rpc_port
Definition p2p_protocol_defs.h:78
peerid_type id
Definition p2p_protocol_defs.h:75
int64_t last_seen
Definition p2p_protocol_defs.h:76
uint32_t rpc_credits_per_hash
Definition p2p_protocol_defs.h:79
#define CRITICAL_REGION_LOCAL(x)
Definition syncobj.h:153
randomx_vm * vm
Definition tests.cpp:20