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);
100 template<
class t_payload_net_handler>
114 inline bool append_net_address(std::vector<epee::net_utils::network_address> & seed_nodes, std::string
const & addr,
uint16_t default_port);
116 template<
class t_payload_net_handler>
149 template<
class t_payload_net_handler>
162 CATCH_ENTRY_L0(
"node_server::init_config",
false);
166 template<
class t_payload_net_handler>
177 template<
class t_payload_net_handler>
191 template<
class t_payload_net_handler>
196 const time_t now = time(
nullptr);
202 if (now >= it->second)
211 *t = it->second - now;
219 auto ipv4_address = address.template as<epee::net_utils::ipv4_network_address>();
220 std::map<epee::net_utils::ipv4_network_subnet, time_t>::iterator it;
223 if (now >= it->second)
225 MCLOG_CYAN(
el::Level::Info,
"global",
"Subnet " << it->first.host_str() <<
" unblocked.");
229 if (it->first.matches(ipv4_address))
232 *t = it->second - now;
243 template<
class t_payload_net_handler>
247 if (zone.m_current_number_of_in_peers >= zone.m_config.m_net_config.max_in_connection_count)
249 MWARNING(
"Exceeded max incoming connections, so dropping this one.");
255 MWARNING(
"CONNECTION FROM " << address.
host_str() <<
" REFUSED, too many connections from the same address");
263 template<
class t_payload_net_handler>
269 const time_t now = time(
nullptr);
274 if (now > std::numeric_limits<time_t>::max() - seconds)
275 limit = std::numeric_limits<time_t>::max();
277 limit = now + seconds;
285 bool matches_blocked_subnet =
false;
288 auto ipv4_address = addr.template as<epee::net_utils::ipv4_network_address>();
291 if (jt->first.matches(ipv4_address))
293 matches_blocked_subnet =
true;
298 if (!matches_blocked_subnet)
301 else if (it->second < limit || !add_only)
307 std::vector<boost::uuids::uuid> conns;
308 for(
auto& zone : m_network_zones)
310 zone.second.m_net_server.get_config_object().foreach_connection([&](
const p2p_connection_context& cntxt)
312 if (cntxt.m_remote_address.is_same_host(addr))
314 conns.push_back(cntxt.m_connection_id);
321 if (addr.
port() == 0)
323 zone.second.m_peerlist.evict_host_from_peerlist(
true, pe);
324 zone.second.m_peerlist.evict_host_from_peerlist(
false, pe);
328 zone.second.m_peerlist.remove_from_peer_white(pe);
329 zone.second.m_peerlist.remove_from_peer_gray(pe);
330 zone.second.m_peerlist.remove_from_peer_anchor(addr);
333 for (
const auto &c: conns)
334 zone.second.m_net_server.get_config_object().close(c,
false);
342 MINFO(
"Host " << host_str <<
" block time updated.");
346 template<
class t_payload_net_handler>
358 template<
class t_payload_net_handler>
361 const time_t now = time(
nullptr);
365 if (now > std::numeric_limits<time_t>::max() - seconds)
366 limit = std::numeric_limits<time_t>::max();
368 limit = now + seconds;
375 std::vector<boost::uuids::uuid> conns;
382 auto ipv4_address = cntxt.m_remote_address.template as<epee::net_utils::ipv4_network_address>();
385 conns.push_back(cntxt.m_connection_id);
389 for (
const auto &c: conns)
390 zone.second.m_net_server.get_config_object().close(c,
false);
392 for (
int i = 0; i < 2; ++i)
393 zone.second.m_peerlist.filter(i == 0, [&subnet](
const peerlist_entry &pe){
394 if (pe.adr.get_type_id() != epee::net_utils::ipv4_network_address::get_type_id())
396 return subnet.matches(pe.adr.as<const epee::net_utils::ipv4_network_address>());
405 MINFO(
"Subnet " << subnet.
host_str() <<
" blocked.");
409 template<
class t_payload_net_handler>
421 template<
class t_payload_net_handler>
429 MDEBUG(
"Host " << address.
host_str() <<
" fail score=" << fails);
440 template<
class t_payload_net_handler>
442 const boost::program_options::variables_map&
vm
461 MWARNING(
"UPnP port mapping support was removed. The --igd option is currently non-functional.");
473 for(
const std::string& pr_str: perrs)
482 pe.
adr = std::move(*adr);
486 CHECK_AND_ASSERT_MES(
490 std::vector<epee::net_utils::network_address> resolved_addrs;
492 CHECK_AND_ASSERT_MES(r,
false,
"Failed to parse or resolve address from string: " << pr_str);
497 m_command_line_peers.push_back(pe);
526 const boost::filesystem::path ban_list_path(ban_list);
527 boost::system::error_code ec;
528 if (!boost::filesystem::exists(ban_list_path, ec))
530 throw std::runtime_error(
"Can't find ban list file " + ban_list +
" - " + ec.message());
533 std::string banned_ips;
536 throw std::runtime_error(
"Failed to read ban list file " + ban_list);
539 std::istringstream iss(banned_ips);
540 for (std::string line; std::getline(iss, line); )
543 const size_t pound_idx =
line.find(
'#');
544 if (pound_idx != std::string::npos)
545 line.resize(pound_idx);
555 block_subnet(*subnet, std::numeric_limits<time_t>::max());
561 block_host(*parsed_addr, std::numeric_limits<time_t>::max());
564 MERROR(
"Invalid IP address or IPv4 subnet: " << line);
569 m_hide_my_port =
true;
572 m_payload_handler.set_no_sync(
true);
598 epee::byte_slice noise =
nullptr;
603 for (
auto&
proxy : *proxies)
606 if (
zone.m_connect !=
nullptr)
611 zone.m_connect = &socks_connect;
619 epee::byte_slice this_noise =
nullptr;
626 this_noise = noise.
clone();
629 zone.m_notifier = cryptonote::levin::notify{
630 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()
634 for (
const auto& zone : m_network_zones)
636 if (
zone.second.m_connect ==
nullptr)
647 const std::size_t tx_relay_zones = m_network_zones.size();
648 for (
auto& inbound : *inbounds)
650 network_zone&
zone = add_zone(inbound.our_address.get_zone());
652 if (!
zone.m_bind_ip.empty())
658 if (
zone.m_connect ==
nullptr && tx_relay_zones <= 1)
660 MERROR(
"Listed --" <<
arg_anonymous_inbound.name <<
" without listing any --" <<
arg_tx_proxy.name <<
". The latter is necessary for sending local txes over anonymity networks");
664 zone.m_bind_ip = std::move(inbound.local_ip);
665 zone.m_port = std::move(inbound.local_port);
666 zone.m_net_server.set_default_remote(std::move(inbound.default_remote));
667 zone.m_our_address = std::move(inbound.our_address);
669 if (!set_max_in_peers(zone, inbound.max_connections))
679 std::vector<epee::net_utils::network_address> & seed_nodes
680 , std::string
const & addr
684 using namespace boost::asio;
688 std::string port = std::to_string(default_port);
690 MINFO(
"Resolving node address: host=" << host <<
", port=" << port);
692 boost::system::error_code ec;
694 ip::tcp::resolver resolver(io_srv);
695 const auto results = resolver.resolve(host, port, boost::asio::ip::tcp::resolver::canonical_name, ec);
696 CHECK_AND_ASSERT_MES(!ec && !results.empty(),
false,
"Failed to resolve host name '" << host <<
"': " << ec.message() <<
':' << ec.value());
698 for (
const auto&
result : results)
700 const auto& endpoint =
result.endpoint();
701 if (endpoint.address().is_v4())
704 seed_nodes.push_back(na);
705 MINFO(
"Added node: " << na.
str());
710 seed_nodes.push_back(na);
711 MINFO(
"Added node: " << na.
str());
718 template<
class t_payload_net_handler>
721 std::set<std::string> full_addrs;
724 full_addrs.insert(
"176.9.0.187:28080");
725 full_addrs.insert(
"192.99.8.110:28080");
726 full_addrs.insert(
"37.187.74.171:28080");
727 full_addrs.insert(
"88.99.195.15:28080");
728 full_addrs.insert(
"5.104.84.64:28080");
732 full_addrs.insert(
"176.9.0.187:38080");
733 full_addrs.insert(
"192.99.8.110:38080");
734 full_addrs.insert(
"37.187.74.171:38080");
735 full_addrs.insert(
"88.99.195.15:38080");
736 full_addrs.insert(
"5.104.84.64:38080");
743 full_addrs.insert(
"176.9.0.187:18080");
744 full_addrs.insert(
"88.198.163.90:18080");
745 full_addrs.insert(
"192.99.8.110:18080");
746 full_addrs.insert(
"37.187.74.171:18080");
747 full_addrs.insert(
"88.99.195.15:18080");
748 full_addrs.insert(
"5.104.84.64:18080");
753 template<
class t_payload_net_handler>
779 std::set<std::string> full_addrs;
788 std::vector<std::vector<std::string>> dns_results;
792 const auto frame = std::make_shared<frame_t>();
799 boost::thread::attributes thread_attributes;
800 thread_attributes.set_stack_size(1024*1024);
802 std::list<boost::thread> dns_threads;
804 const std::weak_ptr<frame_t> frame_weak{frame};
807 boost::thread th = boost::thread(thread_attributes, [frame_weak, addr_str, result_index]
809 MDEBUG(
"dns_threads[" << result_index <<
"] created for: " << addr_str);
813 MINFO(
"dns_threads[" << result_index <<
"] addr_str: " << addr_str <<
" number of results: " << addr_list.size());
814 const auto frame = frame_weak.lock();
817 const boost::lock_guard<boost::mutex> lock{frame->sync};
818 frame->dns_results.at(result_index) = std::move(addr_list);
822 dns_threads.push_back(std::move(th));
827 boost::chrono::system_clock::time_point deadline = boost::chrono::system_clock::now() + boost::chrono::milliseconds(
CRYPTONOTE_DNS_TIMEOUT_MS);
829 for (boost::thread& th : dns_threads)
831 if (! th.try_join_until(deadline))
833 MWARNING(
"dns_threads[" << i <<
"] timed out");
840 const boost::lock_guard<boost::mutex> lock{frame->sync};
841 for (
const auto&
result : frame->dns_results)
847 for (
const auto& addr_string :
result)
856 if (full_addrs.empty())
857 MINFO(
"DNS seed node lookup either timed out or failed, falling back to defaults");
859 MINFO(
"Not enough DNS seed nodes found, using fallback defaults too");
862 full_addrs.insert(peer);
869 template<
class t_payload_net_handler>
880 "zbjkbsxc5munw3qusl7j2hpcmikhqocdf4pqhnhtpzw5nt5jrmofptid.onion:18083",
881 "plowsof3t5hogddwabaeiyrno25efmzfxyro2vligremt7sxpsclfaid.onion:18083",
882 "plowsoffjexmxalw73tkjmf422gq6575fc7vicuu4javzn2ynnte6tyd.onion:18083",
883 "plowsofe6cleftfmk2raiw5h2x66atrik3nja4bfd3zrfa2hdlgworad.onion:18083",
884 "aclc4e2jhhtr44guufbnwk5bzwhaecinax4yip4wr4tjn27sjsfg6zqd.onion:18083",
885 "lykcas4tus7mkm4bhsgqe4drtd4awi7gja24goscc47xfgzj54yofyqd.onion:18083",
893 "uqj3aphckqtjsitz7kxx5flqpwjlq5ppr3chazfued7xucv3nheq.b32.i2p",
894 "vdmnehdjkpkg57nthgnjfuaqgku673r5bpbqg56ix6fyqoywgqrq.b32.i2p",
895 "ugnlcdciyhghh2zert7c3kl4biwkirc43ke33jiy5slnd3mv2trq.b32.i2p",
902 throw std::logic_error{
"Bad zone given to get_seed_nodes"};
905 template<
class t_payload_net_handler>
910 return zone_->second;
916 template<
class t_payload_net_handler>
920 CHECK_AND_ASSERT_MES(res,
false,
"Failed to handle command line");
924 CHECK_AND_ASSERT_MES(endpoint,
false,
"Failed to parse proxy: " <<
proxy <<
" - " << endpoint.error().message());
956 CHECK_AND_ASSERT_MES(res,
false,
"Failed to init config.");
961 CHECK_AND_ASSERT_MES(res,
false,
"Failed to init peerlist.");
965 m_network_zones.at(p.adr.get_zone()).m_peerlist.append_with_peer_white(p);
982 zone.second.m_net_server.get_config_object().set_handler(
this);
985 if (!zone.second.m_bind_ip.empty())
987 std::string ipv6_addr =
"";
988 std::string ipv6_port =
"";
989 zone.second.m_net_server.set_connection_filter(
this);
990 zone.second.m_net_server.set_connection_limit(
this);
991 MINFO(
"Binding (IPv4) on " << zone.second.m_bind_ip <<
":" << zone.second.m_port);
992 if (!zone.second.m_bind_ipv6_address.empty() &&
m_use_ipv6)
994 ipv6_addr = zone.second.m_bind_ipv6_address;
995 ipv6_port = zone.second.m_port_ipv6;
996 MINFO(
"Binding (IPv6) on " << zone.second.m_bind_ipv6_address <<
":" << zone.second.m_port_ipv6);
999 CHECK_AND_ASSERT_MES(res,
false,
"Failed to bind server");
1016 template<
class t_payload_net_handler>
1022 template<
class t_payload_net_handler>
1028 _note(
"Thread monitor number of peers - start");
1035 unsigned int number_of_in_peers = 0;
1036 unsigned int number_of_out_peers = 0;
1039 if (cntxt.m_is_income)
1041 ++number_of_in_peers;
1045 ++number_of_out_peers;
1049 zone.second.m_current_number_of_in_peers = number_of_in_peers;
1050 zone.second.m_current_number_of_out_peers = number_of_out_peers;
1052 boost::this_thread::sleep_for(boost::chrono::seconds(1));
1054 _note(
"Thread monitor number of peers - done");
1062 int thrds_count = 10;
1063 boost::thread::attributes attrs;
1066 MINFO(
"Run net_service loop( " << thrds_count <<
" threads)...");
1069 LOG_ERROR(
"Failed to run net tcp server!");
1072 MINFO(
"net_service loop stopped.");
1076 template<
class t_payload_net_handler>
1085 template<
class t_payload_net_handler>
1093 zone.second.m_net_server.deinit_server();
1098 template<
class t_payload_net_handler>
1111 zone.second.m_peerlist.get_peerlist(active);
1116 MWARNING(
"Failed to save config to file " << state_file_path);
1119 CATCH_ENTRY_L0(
"node_server::store",
false);
1123 template<
class t_payload_net_handler>
1128 MDEBUG(
"[node] Stop signal already sent");
1131 MDEBUG(
"[node] stopping server payload handler");
1134 MDEBUG(
"[node] marking net servers as stopping");
1137 zone.second.m_net_server.mark_stop_signal_sent();
1140 MDEBUG(
"[node] closing connections");
1143 zone.second.m_net_server.close_server_connections();
1145 std::list<boost::uuids::uuid> connection_ids;
1148 connection_ids.push_back(cntxt.m_connection_id);
1151 for (
const auto &connection_id: connection_ids)
1153 MDEBUG(
"Closing connection " << connection_id);
1155 zone.second.m_net_server.get_config_object().close(connection_id,
true);
1156 MDEBUG(
"Closed connection " << connection_id);
1160 MDEBUG(
"[node] stopping net server io_contexts");
1163 zone.second.m_net_server.stop_io_context();
1165 MDEBUG(
"[node] Stop signal sent");
1169 template<
class t_payload_net_handler>
1180 std::atomic<bool> hsh_result(
false);
1181 bool timeout =
false;
1186 epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){ev.raise();});
1198 LOG_WARNING_CC(context,
"COMMAND_HANDSHAKE Failed, wrong network! (" << rsp.node_data.network_id <<
"), closing connection.");
1204 LOG_WARNING_CC(context,
"COMMAND_HANDSHAKE: failed to handle_remote_peerlist(...), closing connection.");
1209 if(!just_take_peerlist)
1211 if(!
m_payload_handler.process_payload_sync_data(rsp.payload_data, context,
true))
1213 LOG_WARNING_CC(context,
"COMMAND_HANDSHAKE invoked, but process_payload_sync_data returned false, dropping connection.");
1218 pi = context.peer_id = rsp.node_data.peer_id;
1219 context.m_rpc_port = rsp.node_data.rpc_port;
1220 context.m_rpc_credits_per_hash = rsp.node_data.rpc_credits_per_hash;
1221 context.support_flags = rsp.node_data.support_flags;
1222 const auto azone = context.m_remote_address.get_zone();
1224 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);
1229 LOG_DEBUG_CC(context,
"Connection to self detected, dropping connection");
1234 LOG_DEBUG_CC(context,
" COMMAND_HANDSHAKE INVOKED OK");
1237 LOG_DEBUG_CC(context,
" COMMAND_HANDSHAKE(AND CLOSE) INVOKED OK");
1251 zone.m_net_server.get_config_object().close(context_.m_connection_id,
false);
1253 else if (!just_take_peerlist)
1255 if (context_.support_flags == 0)
1256 try_get_support_flags(context_, [](p2p_connection_context& flags_context,
const uint32_t& support_flags)
1258 flags_context.support_flags = support_flags;
1265 template<
class t_payload_net_handler>
1275 context.m_in_timedsync = false;
1278 LOG_WARNING_CC(context,
"COMMAND_TIMED_SYNC invoke failed. (" << code <<
", " << epee::levin::get_err_descr(code) <<
")");
1284 LOG_WARNING_CC(context,
"COMMAND_TIMED_SYNC: failed to handle_remote_peerlist(...), closing connection.");
1285 m_network_zones.at(context.m_remote_address.get_zone()).m_net_server.get_config_object().close(context.m_connection_id, false);
1286 add_host_fail(context.m_remote_address);
1288 if(!context.m_is_income)
1289 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);
1292 m_network_zones.at(context.m_remote_address.get_zone()).m_net_server.get_config_object().close(context.m_connection_id, false);
1304 template<
class t_payload_net_handler>
1312 size_t res = (x*x*x)/(max_index*max_index*16*16*16);
1313 MDEBUG(
"Random connection index=" << res <<
"(x="<< x <<
", max_index=" << max_index <<
")");
1317 template<
class t_payload_net_handler>
1326 if(is_public && server->second.m_config.m_peer_id == peer.
id)
1330 server->second.m_net_server.get_config_object().foreach_connection([&, is_public](
const p2p_connection_context& cntxt)
1332 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))
1342 template<
class t_payload_net_handler>
1351 if(is_public && server->second.m_config.m_peer_id == peer.
id)
1355 server->second.m_net_server.get_config_object().foreach_connection([&, is_public](
const p2p_connection_context& cntxt)
1357 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))
1367 template<
class t_payload_net_handler>
1374 bool connected =
false;
1375 zone->second.m_net_server.get_config_object().foreach_connection([&](
const p2p_connection_context& cntxt)
1377 if(!cntxt.m_is_income && peer == cntxt.m_remote_address)
1388#define LOG_PRINT_CC_PRIORITY_NODE(priority, con, msg) \
1391 LOG_INFO_CC(con, "[priority]" << msg); \
1393 LOG_INFO_CC(con, msg); \
1397 template<
class t_payload_net_handler>
1401 if (zone.m_connect ==
nullptr)
1404 if (zone.m_our_address == na)
1407 if (zone.m_current_number_of_out_peers == zone.m_config.m_net_config.max_out_connection_count)
1411 else if (zone.m_current_number_of_out_peers > zone.m_config.m_net_config.max_out_connection_count)
1413 zone.m_net_server.get_config_object().del_out_connections(1);
1414 --(zone.m_current_number_of_out_peers);
1419 MDEBUG(
"Connecting to " << na.
str() <<
" (peer_type=" << peer_type <<
", last_seen: "
1433 con->m_anchor = peer_type ==
anchor;
1447 if(just_take_peerlist)
1449 zone.m_net_server.get_config_object().close(con->m_connection_id,
false);
1450 LOG_DEBUG_CC(*con,
"CONNECTION HANDSHAKED OK AND CLOSED.");
1461 pe_local.
rpc_port = con->m_rpc_port;
1463 zone.m_peerlist.append_with_peer_white(pe_local);
1469 ape.
first_seen = first_seen_stamp ? first_seen_stamp : time(
nullptr);
1471 zone.m_peerlist.append_with_peer_anchor(ape);
1472 zone.m_notifier.on_handshake_complete(con->m_connection_id, con->m_is_income);
1473 zone.m_notifier.new_out_connection();
1479 template<
class t_payload_net_handler>
1483 if (zone.m_connect ==
nullptr)
1486 LOG_PRINT_L1(
"Connecting to " << na.
str() <<
"(last_seen: "
1500 con->m_anchor =
false;
1511 zone.m_net_server.get_config_object().close(con->m_connection_id,
false);
1513 LOG_DEBUG_CC(*con,
"CONNECTION HANDSHAKED OK AND CLOSED.");
1518#undef LOG_PRINT_CC_PRIORITY_NODE
1521 template<
class t_payload_net_handler>
1528 template<
class t_payload_net_handler>
1542 template<
class t_payload_net_handler>
1545 for (
const auto& pe: anchor_peerlist) {
1546 _note(
"Considering connecting (out) to anchor peer: " << peerid_to_string(pe.
id) <<
" " << pe.
adr.
str());
1549 _note(
"Peer is used");
1561 MDEBUG(
"Selected peer: " << peerid_to_string(pe.
id) <<
" " << pe.
adr.
str()
1562 <<
"[peer_type=" <<
anchor
1566 _note(
"Handshake failed");
1577 template<
class t_payload_net_handler>
1586 if (actual_ip.is_v4_mapped())
1590 memcpy(&actual_ipv4, v4ip.to_bytes().data(),
sizeof(actual_ipv4));
1603 std::vector<peerlist_entry> peers;
1604 std::unordered_set<std::string> hosts;
1605 size_t total_peers_size = 0;
1606 zone.m_peerlist.foreach(use_white_list, [&peers, &hosts, &total_peers_size, &get_host_string](
const peerlist_entry &peer)
1609 const std::string host_string = get_host_string(peer.
adr);
1610 if (hosts.insert(host_string).second)
1612 peers.push_back(peer);
1619 const size_t peers_size = peers.size();
1620 MDEBUG(
"Looking at " << peers_size <<
" port-deduplicated peers out of " << total_peers_size
1621 <<
", i.e. dropping " << (total_peers_size - peers_size));
1623 std::set<uint64_t> tried_peers;
1626 size_t outer_loop_count = 0;
1627 while ((outer_loop_count < 3) && !zone.m_net_server.is_stop_signal_sent())
1635 std::set<uint32_t> connected_subnets;
1636 const uint32_t subnet_mask = ntohl(0xffffff00);
1646 connected_subnets.insert(actual_ip & subnet_mask);
1652 if (actual_ip.is_v4_mapped())
1656 memcpy(&actual_ipv4, v4ip.to_bytes().data(),
sizeof(actual_ipv4));
1657 connected_subnets.insert(actual_ipv4 & subnet_mask);
1664 std::vector<peerlist_entry> subnet_peers;
1665 std::vector<peerlist_entry> filtered;
1671 for (
int step = 0; step < 2; ++step)
1673 if ((step == 1) && !is_public_zone)
1676 const bool try_subnet_dedup = step == 0 && is_public_zone;
1677 const std::vector<peerlist_entry> &candidate_peers = try_subnet_dedup ? subnet_peers : peers;
1678 if (try_subnet_dedup)
1683 std::vector<size_t> shuffled_indexes(peers.size());
1684 std::iota(shuffled_indexes.begin(), shuffled_indexes.end(), 0);
1689 std::set<uint32_t> subnets = connected_subnets;
1690 for (
size_t index : shuffled_indexes)
1698 const uint32_t subnet = actual_ip & subnet_mask;
1699 take = subnets.find(subnet) == subnets.end();
1702 subnets.insert(subnet);
1708 if (actual_ip.is_v4_mapped())
1712 memcpy(&actual_ipv4, v4ip.to_bytes().data(),
sizeof(actual_ipv4));
1713 uint32_t subnet = actual_ipv4 & subnet_mask;
1714 take = subnets.find(subnet) == subnets.end();
1716 subnets.insert(subnet);
1721 subnet_peers.push_back(peer);
1727 return a.last_seen > b.last_seen;
1730 const size_t subnet_peers_size = subnet_peers.size();
1731 MDEBUG(
"Looking at " << subnet_peers_size <<
" subnet-deduplicated peers out of " << peers_size
1732 <<
", i.e. dropping " << (peers_size - subnet_peers_size));
1737 const size_t limit = use_white_list ? 20 : std::numeric_limits<size_t>::max();
1739 if (filtered.size() >= limit)
1741 if (tried_peers.count(peer.
id))
1745 if (next_needed_pruning_stripe == 0 || peer.
pruning_seed == 0)
1746 filtered.push_back(peer);
1748 filtered.insert(filtered.begin(), peer);
1752 if (!filtered.empty())
1756 if (filtered.empty())
1758 MINFO(
"No available peer in " << (use_white_list ?
"white" :
"gray") <<
" list filtered by " << next_needed_pruning_stripe);
1762 size_t random_index;
1774 for (
size_t i = 0; i < filtered.size(); ++i)
1779 MDEBUG(
"Reusing stripe " << next_needed_pruning_stripe <<
" peer " << peer.
adr.
str());
1788 CHECK_AND_ASSERT_MES(random_index < filtered.size(),
false,
"random_index < filtered.size() failed!!");
1793 if (tried_peers.count(candidate.
id))
1796 tried_peers.insert(candidate.
id);
1798 _note(
"Considering connecting (out) to " << (use_white_list ?
"white" :
"gray") <<
" list peer: " <<
1800 " (stripe " << next_needed_pruning_stripe <<
" needed), in loop pass " << outer_loop_count);
1802 if (zone.m_our_address == candidate.
adr)
1807 _note(
"Peer is used");
1812 _note(
"Not allowed");
1817 _note(
"Recently failed");
1821 MDEBUG(
"Selected peer: " << peerid_to_string(candidate.
id) <<
" " << candidate.
adr.
str()
1823 <<
"[peer_list=" << (use_white_list ?
white :
gray)
1826 const time_t begin_connect = time(NULL);
1828 time_t fail_connect = time(NULL);
1839 template<
class t_payload_net_handler>
1843 boost::upgrade_lock<boost::shared_mutex> seed_nodes_upgrade_lock(server.
m_seed_nodes_lock);
1848 boost::upgrade_to_unique_lock<boost::shared_mutex> seed_nodes_lock(seed_nodes_upgrade_lock);
1853 MDEBUG(
"Seed node: " << full_addr);
1856 MDEBUG(
"Number of seed nodes: " << server.
m_seed_nodes.size());
1862 size_t try_count = 0;
1863 bool is_connected_to_at_least_one_seed_node =
false;
1873 is_connected_to_at_least_one_seed_node =
true;
1881 MWARNING(
"Failed to connect to any of seed peers, trying fallback seeds");
1884 boost::upgrade_to_unique_lock<boost::shared_mutex> seed_nodes_lock(seed_nodes_upgrade_lock);
1888 MDEBUG(
"Fallback seed node: " << peer);
1894 MWARNING(
"No fallback seeds, continuing without seeds");
1901 if (!is_connected_to_at_least_one_seed_node)
1902 MWARNING(
"Failed to connect to any of seed peers, continuing without seeds");
1912 template<
class t_payload_net_handler>
1922 bool one_succeeded =
false;
1926 if(!zone.second.m_peerlist.get_white_peers_count() && !
connect_to_seed(zone.first))
1938 while(conn_count < zone.second.m_config.m_net_config.max_out_connection_count)
1940 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;
1941 if(conn_count < expected_white_connections)
1961 if(zone.second.m_net_server.is_stop_signal_sent())
1964 if (new_conn_count <= conn_count)
1968 boost::this_thread::sleep_for(boost::chrono::seconds(1));
1971 conn_count = new_conn_count;
1974 if (start_conn_count ==
get_outgoing_connections_count(zone.second) && start_conn_count < zone.second.m_config.m_net_config.max_out_connection_count)
1976 MINFO(
"Failed to connect to any, trying seeds");
1980 one_succeeded =
true;
1983 return one_succeeded;
1986 template<
class t_payload_net_handler>
1992 std::vector<anchor_peerlist_entry> apl;
1994 if (peer_type ==
anchor) {
1995 zone.m_peerlist.get_and_empty_anchor_peerlist(apl);
2000 if(conn_count < expected_connections)
2002 if(zone.m_net_server.is_stop_signal_sent())
2005 MDEBUG(
"Making expected connection, type " << peer_type <<
", " << conn_count <<
"/" << expected_connections <<
" connections");
2022 template<
class t_payload_net_handler>
2031 template<
class t_payload_net_handler>
2037 if(cntxt.m_is_income)
2044 template<
class t_payload_net_handler>
2050 if(!cntxt.m_is_income && !cntxt.
is_ping)
2060 zone.m_current_number_of_out_peers = count;
2065 template<
class t_payload_net_handler>
2074 template<
class t_payload_net_handler>
2082 if(cntxt.m_is_income)
2090 template<
class t_payload_net_handler>
2099 template<
class t_payload_net_handler>
2108 template<
class t_payload_net_handler>
2116 template<
class t_payload_net_handler>
2121 zone.second.m_peerlist.get_peerlist(
gray,
white);
2125 template<
class t_payload_net_handler>
2137 template<
class t_payload_net_handler>
2145 static const std::vector<std::string> dns_urls = {
2146 "blocklist.moneropulse.se"
2147 ,
"blocklist.moneropulse.org"
2148 ,
"blocklist.moneropulse.net"
2149 ,
"blocklist.moneropulse.co"
2150 ,
"blocklist.moneropulse.fr"
2151 ,
"blocklist.moneropulse.de"
2152 ,
"blocklist.moneropulse.ch"
2155 std::vector<std::string> records;
2159 unsigned good = 0, bad = 0;
2160 for (
const auto& record : records)
2162 std::vector<std::string> ips;
2163 boost::split(ips, record, boost::is_any_of(
";"));
2164 for (
const auto &ip: ips)
2182 MWARNING(
"Invalid IP address or subnet from DNS blocklist: " << ip <<
" - " << parsed_addr.
error());
2187 MINFO(good <<
" addresses added to the blocklist");
2191 template<
class t_payload_net_handler>
2202 MGINFO(
"Incoming connections disabled, enable them for full connectivity");
2207 MCLOG_RED(level,
"global",
"No incoming connections - check firewalls/routers allow port " <<
get_this_peer_port());
2213 template<
class t_payload_net_handler>
2216 MDEBUG(
"STARTED PEERLIST IDLE HANDSHAKE");
2217 typedef std::list<std::pair<epee::net_utils::connection_context_base, peerid_type> > local_connects_type;
2218 local_connects_type cncts;
2226 cncts.push_back(local_connects_type::value_type(cntxt, cntxt.
peer_id));
2232 std::for_each(cncts.begin(), cncts.end(), [&](
const typename local_connects_type::value_type& vl){do_peer_timed_sync(vl.first, vl.second);});
2234 MDEBUG(
"FINISHED PEERLIST IDLE HANDSHAKE");
2238 template<
class t_payload_net_handler>
2241 for (
size_t i = 0; i < local_peerlist.size(); ++i)
2243 bool ignore =
false;
2255 else if (ipv4.port() == be.
rpc_port)
2262 MDEBUG(
"Ignoring " << be.
adr.
str());
2263 std::swap(local_peerlist[i], local_peerlist[local_peerlist.size() - 1]);
2264 local_peerlist.resize(local_peerlist.size() - 1);
2268 local_peerlist[i].last_seen = 0;
2273 template<
class t_payload_net_handler>
2278 MWARNING(context <<
"peer sent " << peerlist.size() <<
" peers, considered spamming");
2281 std::vector<peerlist_entry> peerlist_ = peerlist;
2286 for(
const auto& peer : peerlist_)
2288 if(peer.adr.get_zone() != zone)
2290 MWARNING(context <<
" sent peerlist from another zone, dropping");
2295 LOG_DEBUG_CC(context,
"REMOTE PEERLIST: remote peerlist size=" << peerlist_.size());
2303 template<
class t_payload_net_handler>
2306 node_data.
peer_id = zone.m_config.m_peer_id;
2318 template<
class t_payload_net_handler>
2321 rsp.support_flags =
m_network_zones.at(context.m_remote_address.get_zone()).m_config.m_support_flags;
2325 template<
class t_payload_net_handler>
2328 m_network_zones.at(context.m_remote_address.get_zone()).m_net_server.get_config_object().request_callback(context.m_connection_id);
2331 template<
class t_payload_net_handler>
2335 std::sort(connections.begin(), connections.end());
2337 for(
const auto& c_id: connections)
2346 if (c_id.first <= zone->first)
2351 if (zone->first == c_id.first)
2352 zone->second.m_net_server.get_config_object().send(message.clone(), c_id.second);
2357 template<
class t_payload_net_handler>
2362 const auto send = [&txs, &
source, tx_relay] (std::pair<const enet::zone, network_zone>& network)
2364 if (network.second.m_notifier.send_txs(std::move(txs),
source, tx_relay))
2365 return network.first;
2366 return enet::zone::invalid;
2370 return enet::zone::invalid;
2372 if (origin != enet::zone::invalid)
2381 static_assert(std::is_same<std::underlying_type<enet::zone>::type, std::uint8_t>{},
"expected uint8_t zone");
2382 static_assert(unsigned(enet::zone::invalid) == 0,
"invalid expected to be 0");
2383 static_assert(unsigned(enet::zone::public_) == 1,
"public_ expected to be 1");
2384 static_assert(unsigned(enet::zone::i2p) == 2,
"i2p expected to be 2");
2385 static_assert(unsigned(enet::zone::tor) == 3,
"tor expected to be 3");
2390 if (enet::zone::tor < network->first)
2393 const auto status = network->second.m_notifier.get_status();
2394 if (status.has_noise && status.connections_filled)
2395 return send(*network);
2401 if (enet::zone::tor < network->first)
2404 const auto status = network->second.m_notifier.get_status();
2405 if (network->second.m_connect && status.has_outgoing)
2406 return send(*network);
2409 MWARNING(
"Unable to send " << txs.size() <<
" transaction(s): anonymity networks had no outgoing connections");
2410 return enet::zone::invalid;
2413 template<
class t_payload_net_handler>
2419 template<
class t_payload_net_handler>
2426 bool res = zone.m_net_server.get_config_object().send(message.finalize_notify(command), context.m_connection_id);
2430 template<
class t_payload_net_handler>
2433 m_network_zones.at(context.m_remote_address.get_zone()).m_net_server.get_config_object().close(context.m_connection_id,
false);
2437 template<
class t_payload_net_handler>
template<
class t_callback>
2444 CHECK_AND_ASSERT_MES(address_ok,
false,
2445 "Only IPv4 or IPv6 addresses are supported here");
2450 boost::asio::ip::address_v6 ipv6_addr;
2461 ip = ipv6_addr.to_string();
2466 if(!zone.m_peerlist.is_host_allowed(context.m_remote_address))
2481 bool r = zone.m_net_server.connect_async(ip, port, zone.m_config.m_net_config.ping_connection_timeout, [cb, address, pr,
this](
2483 const boost::system::error_code& ec)->bool
2487 LOG_WARNING_CC(ping_context,
"back ping connect failed to " << address.str());
2508 LOG_WARNING_CC(ping_context,
"Failed to invoke COMMAND_PING to " << address.str() <<
"(" << code <<
", " << epee::levin::get_err_descr(code) <<
")");
2515 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));
2516 zone.m_net_server.get_config_object().close(ping_context.m_connection_id, false);
2519 zone.m_net_server.get_config_object().close(ping_context.m_connection_id,
false);
2526 zone.m_net_server.get_config_object().close(ping_context.m_connection_id,
false);
2530 },
"0.0.0.0", m_ssl_support, p2p_connection_context{
true });
2533 LOG_WARNING_CC(context,
"Failed to call connect_async, network error.");
2538 template<
class t_payload_net_handler>
2549 support_flags_request,
2555 LOG_WARNING_CC(context_,
"COMMAND_REQUEST_SUPPORT_FLAGS invoke failed. (" << code <<
", " << epee::levin::get_err_descr(code) <<
")");
2559 f(context_, rsp.support_flags);
2567 template<
class t_payload_net_handler>
2570 if(!
m_payload_handler.process_payload_sync_data(arg.payload_data, context,
false))
2572 LOG_WARNING_CC(context,
"Failed to process_payload_sync_data(), dropping connection");
2582 const bool outgoing_to_same_zone = !context.m_is_income && zone.m_our_address.get_zone() == zone_type;
2585 std::vector<peerlist_entry> local_peerlist_new;
2586 zone.m_peerlist.get_peerlist_head(local_peerlist_new,
true, max_peerlist_size);
2594 if(outgoing_to_same_zone)
2596 local_peerlist_new.insert(
2597 local_peerlist_new.begin() +
crypto::rand_range(std::size_t(0), local_peerlist_new.size()),
2603 rsp.local_peerlist_new.reserve(local_peerlist_new.size());
2604 for (
auto &pe: local_peerlist_new)
2606 if (!context.sent_addresses.insert(pe.
adr).second)
2608 rsp.local_peerlist_new.push_back(std::move(pe));
2616 template<
class t_payload_net_handler>
2622 LOG_INFO_CC(context,
"WRONG NETWORK AGENT CONNECTED! id=" << arg.node_data.network_id);
2628 if(!context.m_is_income)
2630 LOG_WARNING_CC(context,
"COMMAND_HANDSHAKE came not from incoming connection");
2636 if(context.handshake_complete())
2638 LOG_WARNING_CC(context,
"COMMAND_HANDSHAKE came, but connection already completed a handshake (double COMMAND_HANDSHAKE?)");
2643 const auto azone = context.m_remote_address.get_zone();
2650 LOG_DEBUG_CC(context,
"Connection to self detected, dropping connection");
2655 if(!
m_payload_handler.process_payload_sync_data(arg.payload_data, context,
true))
2657 LOG_WARNING_CC(context,
"COMMAND_HANDSHAKE came, but process_payload_sync_data returned false, dropping connection.");
2662 zone.m_notifier.on_handshake_complete(context.m_connection_id, context.m_is_income);
2665 context.peer_id = arg.node_data.peer_id;
2666 context.m_in_timedsync =
false;
2667 context.m_rpc_port = arg.node_data.rpc_port;
2668 context.m_rpc_credits_per_hash = arg.node_data.rpc_credits_per_hash;
2669 context.support_flags = arg.node_data.support_flags;
2671 if(arg.node_data.my_port && zone.m_can_pingback)
2674 uint32_t port_l = arg.node_data.my_port;
2676 try_ping(arg.node_data, context, [peer_id_l, port_l, context,
this]()
2678 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(),
2679 "Only IPv4 or IPv6 addresses are supported here");
2682 const epee::net_utils::network_address na = context.m_remote_address;
2683 if (context.m_remote_address.get_type_id() == epee::net_utils::ipv4_network_address::get_type_id())
2685 pe.adr = epee::net_utils::ipv4_network_address(na.as<epee::net_utils::ipv4_network_address>().ip(), port_l);
2689 pe.adr = epee::net_utils::ipv6_network_address(na.as<epee::net_utils::ipv6_network_address>().ip(), port_l);
2698 this->m_network_zones.at(context.m_remote_address.get_zone()).m_peerlist.append_with_peer_white(pe);
2699 LOG_DEBUG_CC(context,
"PING SUCCESS " << context.m_remote_address.host_str() <<
":" << port_l);
2703 if (context.support_flags == 0)
2704 try_get_support_flags(context, [](p2p_connection_context& flags_context,
const uint32_t& support_flags)
2706 flags_context.support_flags = support_flags;
2710 zone.m_peerlist.get_peerlist_head(rsp.local_peerlist_new,
true);
2711 for (
const auto &e: rsp.local_peerlist_new)
2712 context.sent_addresses.insert(e.adr);
2713 get_local_node_data(rsp.node_data, zone);
2714 m_payload_handler.get_payload_sync_data(rsp.payload_data);
2719 template<
class t_payload_net_handler>
2724 rsp.peer_id =
m_network_zones.at(context.m_remote_address.get_zone()).m_config.m_peer_id;
2728 template<
class t_payload_net_handler>
2731 std::vector<peerlist_entry> pl_white;
2732 std::vector<peerlist_entry> pl_gray;
2734 zone.second.m_peerlist.get_peerlist(pl_gray, pl_white);
2739 template<
class t_payload_net_handler>
2746 template<
class t_payload_net_handler>
2750 std::stringstream ss;
2755 ss << cntxt.m_remote_address.str()
2756 <<
" \t\tpeer_id " << peerid_to_string(cntxt.
peer_id)
2757 <<
" \t\tconn_id " << cntxt.m_connection_id << (cntxt.m_is_income ?
" INC":
" OUT")
2762 std::string
s = ss.str();
2766 template<
class t_payload_net_handler>
2772 template<
class t_payload_net_handler>
2776 if (!zone.m_net_server.is_stop_signal_sent() && !context.m_is_income) {
2778 na = context.m_remote_address;
2780 zone.m_peerlist.remove_from_peer_anchor(na);
2783 if (!zone.m_net_server.is_stop_signal_sent()) {
2784 zone.m_notifier.on_connection_close(context.m_connection_id);
2791 template<
class t_payload_net_handler>
2797 template<
class t_payload_net_handler>
template <
class Container>
2815 template<
class t_payload_net_handler>
template <
class Container>
2820 for(
const std::string& pr_str: perrs)
2827 container.push_back(std::move(*adr));
2830 std::vector<epee::net_utils::network_address> resolved_addrs;
2832 CHECK_AND_ASSERT_MES(r,
false,
"Failed to parse or resolve address from string: " << pr_str);
2835 container.push_back(addr);
2842 template<
class t_payload_net_handler>
2849 zone.m_config.m_net_config.max_out_connection_count = max;
2853 template<
class t_payload_net_handler>
2856 zone.m_config.m_net_config.max_in_connection_count = max;
2860 template<
class t_payload_net_handler>
2867 public_zone->second.
m_config.m_net_config.max_out_connection_count = count;
2874 template<
class t_payload_net_handler>
2880 return public_zone->second.
m_config.m_net_config.max_out_connection_count;
2883 template<
class t_payload_net_handler>
2890 public_zone->second.
m_config.m_net_config.max_in_connection_count = count;
2896 template<
class t_payload_net_handler>
2902 return public_zone->second.
m_config.m_net_config.max_in_connection_count;
2905 template<
class t_payload_net_handler>
2912 _dbg1(
"Set ToS flag " << flag);
2916 template<
class t_payload_net_handler>
2926 MINFO(
"Set limit-up to " << limit <<
" kB/s");
2930 template<
class t_payload_net_handler>
2938 MINFO(
"Set limit-down to " << limit <<
" kB/s");
2942 template<
class t_payload_net_handler>
2960 MINFO(
"Set limit-up to " << limit_up <<
" kB/s");
2964 MINFO(
"Set limit-down to " << limit_down <<
" kB/s");
2970 template<
class t_payload_net_handler>
2995 template<
class t_payload_net_handler>
3006 if (zone.second.m_net_server.is_stop_signal_sent())
3009 if (zone.second.m_connect ==
nullptr)
3013 if (!zone.second.m_peerlist.get_random_gray_peer(pe))
3018 zone.second.m_peerlist.remove_from_peer_gray(pe);
3019 LOG_PRINT_L2(
"PEER EVICTED FROM GRAY PEER LIST: address: " << pe.
adr.
host_str() <<
" Peer ID: " << peerid_to_string(pe.
id));
3024 LOG_PRINT_L2(
"PEER PROMOTED TO WHITE PEER LIST IP address: " << pe.
adr.
host_str() <<
" Peer ID: " << peerid_to_string(pe.
id));
3030 template<
class t_payload_net_handler>
3038 MINFO(
"adding stripe " << stripe <<
" peer: " << context.m_remote_address.str());
3044 template<
class t_payload_net_handler>
3052 MINFO(
"removing stripe " << stripe <<
" peer: " << context.m_remote_address.str());
3057 template<
class t_payload_net_handler>
3061 MINFO(
"clearing used stripe peers");
3066 template<
typename t_payload_net_handler>
3067 boost::optional<p2p_connection_context_t<typename t_payload_net_handler::connection_context>>
3070 auto result =
socks_connect_internal(zone.m_net_server.get_stop_signal(), zone.m_net_server.get_io_context(), zone.m_proxy_address, remote);
3074 if (zone.m_net_server.add_connection(context, std::move(*
result), remote, ssl_support))
3075 return {std::move(context)};
3080 template<
typename t_payload_net_handler>
3081 boost::optional<p2p_connection_context_t<typename t_payload_net_handler::connection_context>>
3086 CHECK_AND_ASSERT_MES(is_ipv4 || is_ipv6, boost::none,
3087 "Only IPv4 or IPv6 addresses are supported here");
3089 std::string address;
3101 address = ipv6.ip().to_string();
3106 LOG_ERROR(
"Only IPv4 or IPv6 addresses are supported here");
3111 const bool res = zone.m_net_server.connect(address, port,
3112 zone.m_config.m_net_config.connection_timeout,
3113 con,
"0.0.0.0", ssl_support);
3116 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:483
bool is_stop_signal_sent() const noexcept
Definition abstract_tcp_server2.h:399
boost::asio::io_context & get_io_context()
Definition abstract_tcp_server2.h:452
epee::levin::async_protocol_handler< p2p_connection_context >::connection_context t_connection_context
Definition abstract_tcp_server2.h:359
int get_binded_port_ipv6()
Definition abstract_tcp_server2.h:443
t_protocol_handler::config_type & get_config_object()
Definition abstract_tcp_server2.h:430
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:1508
void set_threads_prefix(const std::string &prefix_name)
Definition abstract_tcp_server2.inl:1477
std::shared_ptr< typename t_protocol_handler::config_type > get_config_shared()
Definition abstract_tcp_server2.h:436
int get_binded_port()
Definition abstract_tcp_server2.h:442
Represents a single connection from a client.
Definition abstract_tcp_server2.h:100
Definition net_utils_base.h:70
static constexpr address_type get_type_id() noexcept
Definition net_utils_base.h:93
std::string host_str() const
Definition net_utils_base.cpp:33
Definition net_utils_base.h:126
bool matches(const ipv4_network_address &address) const
Definition net_utils_base.cpp:91
std::string host_str() const
Definition net_utils_base.cpp:88
Definition net_utils_base.h:173
static constexpr address_type get_type_id() noexcept
Definition net_utils_base.h:199
Definition net_utils_base.h:229
bool is_loopback() const
Definition net_utils_base.h:318
std::string str() const
Definition net_utils_base.h:316
address_type get_type_id() const
Definition net_utils_base.h:320
bool is_same_host(const network_address &other) const
Definition net_utils_base.cpp:120
std::uint16_t port() const
Definition net_utils_base.h:323
bool is_local() const
Definition net_utils_base.h:319
std::string host_str() const
Definition net_utils_base.h:317
zone get_zone() const
Definition net_utils_base.h:321
bool is_blockable() const
Definition net_utils_base.h:322
const Type & as() const
Definition net_utils_base.h:324
*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
#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:176
std::enable_if< std::is_integral< T >::value, T >::type rand_range(T range_min, T range_max)
Definition crypto.h:197
std::enable_if< std::is_unsigned< T >::value, T >::type rand_idx(T sz)
Definition crypto.h:206
@ 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
bool should_group_ipv6_by_prefix(const boost::asio::ip::address_v6 &ip)
Definition net_utils_base.cpp:56
const char * zone_to_string(zone value) noexcept
Definition net_utils_base.cpp:165
@ 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:151
boost::asio::ip::address_v6 get_ipv6_subnet_address(const boost::asio::ip::address_v6 &ip, const std::size_t prefix_bits)
Definition net_utils_base.cpp:63
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:50
@ e_ssl_support_disabled
Definition net_ssl.h:51
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:1388
#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:476
#define LOG_WARNING_CC(ct, message)
Definition net_utils_base.h:474
#define LOG_INFO_CC(ct, message)
Definition net_utils_base.h:475
#define LOG_TRACE_CC(ct, message)
Definition net_utils_base.h:477
#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
if(!cryptonote::get_account_address_from_str_or_url(info, cryptonote::TESTNET, "9uVsvEryzpN8WH2t1WWhFFCG5tS8cBNdmJYNRuckLENFimfauV5pZKeS1P2CbxGkSDTUPHXWwiYE5ZGSXDAGbaZgDxobqDN"))
Definition signature.cpp:53
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:371
const network_address m_remote_address
Definition net_utils_base.h:373
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