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>
67#undef MONERO_DEFAULT_LOG_CATEGORY
68#define MONERO_DEFAULT_LOG_CATEGORY "net.p2p"
70#define NET_MAKE_IP(b1,b2,b3,b4) ((LPARAM)(((DWORD)(b1)<<24)+((DWORD)(b2)<<16)+((DWORD)(b3)<<8)+((DWORD)(b4))))
72#define MIN_WANTED_SEED_NODES 12
76 const auto &bytes =
a.to_bytes();
78 v4 = (v4 << 8) | bytes[12];
79 v4 = (v4 << 8) | bytes[13];
80 v4 = (v4 << 8) | bytes[14];
81 v4 = (v4 << 8) | bytes[15];
82 return boost::asio::ip::address_v4(v4);
87 template<
class t_payload_net_handler>
92 for (
auto current = m_network_zones.begin(); current != m_network_zones.end(); )
95 current = m_network_zones.erase(current);
101 inline bool append_net_address(std::vector<epee::net_utils::network_address> & seed_nodes, std::string
const & addr,
uint16_t default_port);
103 template<
class t_payload_net_handler>
136 template<
class t_payload_net_handler>
142 m_peerlist_storage = std::move(*storage);
146 public_zone.
m_config.m_peer_id = crypto::rand<uint64_t>();
147 m_first_connection_maker_call =
true;
149 CATCH_ENTRY_L0(
"node_server::init_config",
false);
153 template<
class t_payload_net_handler>
156 for(
auto& zone : m_network_zones)
164 template<
class t_payload_net_handler>
167 for(
auto& zone : m_network_zones)
178 template<
class t_payload_net_handler>
183 const time_t now = time(
nullptr);
186 auto it = m_blocked_hosts.find(
address.host_str());
187 if (it != m_blocked_hosts.end())
189 if (now >= it->second)
191 m_blocked_hosts.erase(it);
193 it = m_blocked_hosts.end();
198 *t = it->second - now;
206 auto ipv4_address =
address.template as<epee::net_utils::ipv4_network_address>();
207 std::map<epee::net_utils::ipv4_network_subnet, time_t>::iterator it;
208 for (it = m_blocked_subnets.begin(); it != m_blocked_subnets.end(); )
210 if (now >= it->second)
212 it = m_blocked_subnets.erase(it);
213 MCLOG_CYAN(
el::Level::Info,
"global",
"Subnet " << it->first.host_str() <<
" unblocked.");
216 if (it->first.matches(ipv4_address))
219 *t = it->second - now;
230 template<
class t_payload_net_handler>
234 if (zone.m_current_number_of_in_peers >= zone.m_config.m_net_config.max_in_connection_count)
236 MWARNING(
"Exceeded max incoming connections, so dropping this one.");
240 if(has_too_many_connections(
address))
242 MWARNING(
"CONNECTION FROM " <<
address.host_str() <<
" REFUSED, too many connections from the same address");
250 template<
class t_payload_net_handler>
256 const time_t now = time(
nullptr);
261 if (now > std::numeric_limits<time_t>::max() - seconds)
262 limit = std::numeric_limits<time_t>::max();
264 limit = now + seconds;
265 const std::string host_str = addr.
host_str();
266 auto it = m_blocked_hosts.find(host_str);
267 if (it == m_blocked_hosts.end())
269 m_blocked_hosts[host_str] = limit;
272 bool matches_blocked_subnet =
false;
275 auto ipv4_address = addr.template as<epee::net_utils::ipv4_network_address>();
276 for (
auto jt = m_blocked_subnets.begin(); jt != m_blocked_subnets.end(); ++jt)
278 if (jt->first.matches(ipv4_address))
280 matches_blocked_subnet =
true;
285 if (!matches_blocked_subnet)
288 else if (it->second < limit || !add_only)
294 std::vector<boost::uuids::uuid> conns;
295 for(
auto& zone : m_network_zones)
299 if (cntxt.m_remote_address.is_same_host(addr))
301 conns.push_back(cntxt.m_connection_id);
308 if (addr.
port() == 0)
310 zone.second.m_peerlist.evict_host_from_peerlist(
true, pe);
311 zone.second.m_peerlist.evict_host_from_peerlist(
false, pe);
315 zone.second.m_peerlist.remove_from_peer_white(pe);
316 zone.second.m_peerlist.remove_from_peer_gray(pe);
317 zone.second.m_peerlist.remove_from_peer_anchor(addr);
320 for (
const auto &c: conns)
327 MCLOG_CYAN(
el::Level::Info,
"global",
"Host " << host_str <<
" blocked.");
329 MINFO(
"Host " << host_str <<
" block time updated.");
333 template<
class t_payload_net_handler>
337 auto i = m_blocked_hosts.find(
address.host_str());
338 if (i == m_blocked_hosts.end())
340 m_blocked_hosts.erase(i);
345 template<
class t_payload_net_handler>
348 const time_t now = time(
nullptr);
352 if (now > std::numeric_limits<time_t>::max() - seconds)
353 limit = std::numeric_limits<time_t>::max();
355 limit = now + seconds;
356 const bool added = m_blocked_subnets.find(subnet) == m_blocked_subnets.end();
357 m_blocked_subnets[subnet] = limit;
362 std::vector<boost::uuids::uuid> conns;
363 for(
auto& zone : m_network_zones)
369 auto ipv4_address = cntxt.m_remote_address.template as<epee::net_utils::ipv4_network_address>();
372 conns.push_back(cntxt.m_connection_id);
376 for (
const auto &c: conns)
377 zone.second.m_net_server.get_config_object().
close(c);
379 for (
int i = 0; i < 2; ++i)
381 if (pe.adr.get_type_id() != epee::net_utils::ipv4_network_address::get_type_id())
383 return subnet.matches(pe.adr.as<const epee::net_utils::ipv4_network_address>());
392 MINFO(
"Subnet " << subnet.
host_str() <<
" blocked.");
396 template<
class t_payload_net_handler>
400 auto i = m_blocked_subnets.find(subnet);
401 if (i == m_blocked_subnets.end())
403 m_blocked_subnets.erase(i);
408 template<
class t_payload_net_handler>
416 MDEBUG(
"Host " <<
address.host_str() <<
" fail score=" << fails);
419 auto it = m_host_fails_score.find(
address.host_str());
420 CHECK_AND_ASSERT_MES(it != m_host_fails_score.end(),
false,
"internal error");
427 template<
class t_payload_net_handler>
429 const boost::program_options::variables_map&
vm
448 if (sigd ==
"enabled")
452 MFATAL(
"Cannot have both --" <<
arg_no_igd.name <<
" and --" <<
arg_igd.name <<
" enabled");
457 else if (sigd ==
"disabled")
461 else if (sigd ==
"delayed")
465 MFATAL(
"Cannot have both --" <<
arg_no_igd.name <<
" and --" <<
arg_igd.name <<
" delayed");
468 m_igd = has_no_igd ? no_igd : delayed_igd;
472 MFATAL(
"Invalid value for --" <<
arg_igd.name <<
", expected enabled, disabled or delayed");
485 for(
const std::string& pr_str: perrs)
488 pe.
id = crypto::rand<uint64_t>();
493 add_zone(adr->get_zone());
494 pe.
adr = std::move(*adr);
495 m_command_line_peers.push_back(std::move(pe));
498 CHECK_AND_ASSERT_MES(
502 std::vector<epee::net_utils::network_address> resolved_addrs;
504 CHECK_AND_ASSERT_MES(r,
false,
"Failed to parse or resolve address from string: " << pr_str);
507 pe.
id = crypto::rand<uint64_t>();
509 m_command_line_peers.push_back(pe);
538 const boost::filesystem::path ban_list_path(ban_list);
539 boost::system::error_code ec;
540 if (!boost::filesystem::exists(ban_list_path, ec))
542 throw std::runtime_error(
"Can't find ban list file " + ban_list +
" - " + ec.message());
545 std::string banned_ips;
548 throw std::runtime_error(
"Failed to read ban list file " + ban_list);
551 std::istringstream iss(banned_ips);
552 for (std::string line; std::getline(iss, line); )
555 const size_t pound_idx =
line.find(
'#');
556 if (pound_idx != std::string::npos)
557 line.resize(pound_idx);
567 block_subnet(*subnet, std::numeric_limits<time_t>::max());
573 block_host(*parsed_addr, std::numeric_limits<time_t>::max());
576 MERROR(
"Invalid IP address or IPv4 subnet: " << line);
581 m_hide_my_port =
true;
584 m_payload_handler.set_no_sync(
true);
615 for (
auto& proxy : *proxies)
617 network_zone&
zone = add_zone(proxy.zone);
618 if (
zone.m_connect !=
nullptr)
623 zone.m_connect = &socks_connect;
624 zone.m_proxy_address = std::move(proxy.address);
626 if (!set_max_out_peers(zone, proxy.max_connections))
629 m_payload_handler.set_max_out_peers(proxy.zone, proxy.max_connections);
638 this_noise = noise.
clone();
642 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()
646 for (
const auto& zone : m_network_zones)
648 if (
zone.second.m_connect ==
nullptr)
659 const std::size_t tx_relay_zones = m_network_zones.size();
660 for (
auto& inbound : *inbounds)
662 network_zone&
zone = add_zone(inbound.our_address.get_zone());
664 if (!
zone.m_bind_ip.empty())
670 if (
zone.m_connect ==
nullptr && tx_relay_zones <= 1)
672 MERROR(
"Listed --" <<
arg_anonymous_inbound.name <<
" without listing any --" <<
arg_tx_proxy.name <<
". The latter is necessary for sending local txes over anonymity networks");
676 zone.m_bind_ip = std::move(inbound.local_ip);
677 zone.m_port = std::move(inbound.local_port);
678 zone.m_net_server.set_default_remote(std::move(inbound.default_remote));
679 zone.m_our_address = std::move(inbound.our_address);
681 if (!set_max_in_peers(zone, inbound.max_connections))
691 std::vector<epee::net_utils::network_address> & seed_nodes
692 , std::string
const & addr
696 using namespace boost::asio;
700 std::string
port = std::to_string(default_port);
702 MINFO(
"Resolving node address: host=" << host <<
", port=" <<
port);
704 boost::system::error_code ec;
706 ip::tcp::resolver resolver(io_srv);
707 const auto results = resolver.resolve(host,
port, boost::asio::ip::tcp::resolver::canonical_name, ec);
708 CHECK_AND_ASSERT_MES(!ec && !results.empty(),
false,
"Failed to resolve host name '" << host <<
"': " << ec.message() <<
':' << ec.value());
710 for (
const auto&
result : results)
712 const auto& endpoint =
result.endpoint();
713 if (endpoint.address().is_v4())
716 seed_nodes.push_back(na);
717 MINFO(
"Added node: " << na.str());
722 seed_nodes.push_back(na);
723 MINFO(
"Added node: " << na.str());
730 template<
class t_payload_net_handler>
733 std::set<std::string> full_addrs;
736 full_addrs.insert(
"176.9.0.187:28080");
737 full_addrs.insert(
"192.99.8.110:28080");
738 full_addrs.insert(
"37.187.74.171:28080");
739 full_addrs.insert(
"88.99.195.15:28080");
740 full_addrs.insert(
"5.104.84.64:28080");
744 full_addrs.insert(
"176.9.0.187:38080");
745 full_addrs.insert(
"192.99.8.110:38080");
746 full_addrs.insert(
"37.187.74.171:38080");
747 full_addrs.insert(
"88.99.195.15:38080");
748 full_addrs.insert(
"5.104.84.64:38080");
755 full_addrs.insert(
"176.9.0.187:18080");
756 full_addrs.insert(
"88.198.163.90:18080");
757 full_addrs.insert(
"192.99.8.110:18080");
758 full_addrs.insert(
"37.187.74.171:18080");
759 full_addrs.insert(
"88.99.195.15:18080");
760 full_addrs.insert(
"5.104.84.64:18080");
765 template<
class t_payload_net_handler>
768 if (!m_exclusive_peers.empty() || m_offline)
774 return get_ip_seed_nodes();
778 return get_ip_seed_nodes();
780 if (!m_enable_dns_seed_nodes)
783 m_fallback_seed_nodes_added.test_and_set();
784 return get_ip_seed_nodes();
787 std::set<std::string> full_addrs;
794 std::vector<std::vector<std::string>> dns_results;
795 dns_results.resize(m_seed_nodes_list.size());
801 boost::thread::attributes thread_attributes;
802 thread_attributes.set_stack_size(1024*1024);
804 std::list<boost::thread> dns_threads;
806 for (
const std::string& addr_str : m_seed_nodes_list)
808 boost::thread th = boost::thread(thread_attributes, [=, &dns_results, &addr_str]
810 MDEBUG(
"dns_threads[" << result_index <<
"] created for: " << addr_str);
813 std::vector<std::string> addr_list;
818 MDEBUG(
"dns_threads[" << result_index <<
"] DNS resolve done");
819 boost::this_thread::interruption_point();
821 catch(
const boost::thread_interrupted&)
826 MWARNING(
"dns_threads[" << result_index <<
"] interrupted");
830 MINFO(
"dns_threads[" << result_index <<
"] addr_str: " << addr_str <<
" number of results: " << addr_list.size());
831 dns_results[result_index] = addr_list;
834 dns_threads.push_back(std::move(th));
839 boost::chrono::system_clock::time_point deadline = boost::chrono::system_clock::now() + boost::chrono::milliseconds(
CRYPTONOTE_DNS_TIMEOUT_MS);
841 for (boost::thread& th : dns_threads)
843 if (! th.try_join_until(deadline))
845 MWARNING(
"dns_threads[" << i <<
"] timed out, sending interrupt");
852 for (
const auto&
result : dns_results)
854 MDEBUG(
"DNS lookup for " << m_seed_nodes_list[i] <<
": " <<
result.size() <<
" results");
858 for (
const auto& addr_string :
result)
867 if (full_addrs.empty())
868 MINFO(
"DNS seed node lookup either timed out or failed, falling back to defaults");
870 MINFO(
"Not enough DNS seed nodes found, using fallback defaults too");
872 for (
const auto &peer: get_ip_seed_nodes())
873 full_addrs.insert(peer);
874 m_fallback_seed_nodes_added.test_and_set();
880 template<
class t_payload_net_handler>
886 return get_dns_seed_nodes();
891 "zbjkbsxc5munw3qusl7j2hpcmikhqocdf4pqhnhtpzw5nt5jrmofptid.onion:18083",
892 "plowsof3t5hogddwabaeiyrno25efmzfxyro2vligremt7sxpsclfaid.onion:18083",
893 "plowsoffjexmxalw73tkjmf422gq6575fc7vicuu4javzn2ynnte6tyd.onion:18083",
894 "plowsofe6cleftfmk2raiw5h2x66atrik3nja4bfd3zrfa2hdlgworad.onion:18083",
895 "aclc4e2jhhtr44guufbnwk5bzwhaecinax4yip4wr4tjn27sjsfg6zqd.onion:18083",
896 "lykcas4tus7mkm4bhsgqe4drtd4awi7gja24goscc47xfgzj54yofyqd.onion:18083",
904 "uqj3aphckqtjsitz7kxx5flqpwjlq5ppr3chazfued7xucv3nheq.b32.i2p",
905 "vdmnehdjkpkg57nthgnjfuaqgku673r5bpbqg56ix6fyqoywgqrq.b32.i2p",
906 "ugnlcdciyhghh2zert7c3kl4biwkirc43ke33jiy5slnd3mv2trq.b32.i2p",
913 throw std::logic_error{
"Bad zone given to get_seed_nodes"};
916 template<
class t_payload_net_handler>
919 const auto zone_ = m_network_zones.lower_bound(zone);
920 if (
zone_ != m_network_zones.end() &&
zone_->first == zone)
921 return zone_->second;
924 return m_network_zones.emplace_hint(
zone_, std::piecewise_construct, std::make_tuple(zone), std::tie(public_zone.
m_net_server.
get_io_context()))->second;
927 template<
class t_payload_net_handler>
930 bool res = handle_command_line(
vm);
931 CHECK_AND_ASSERT_MES(
res,
false,
"Failed to handle command line");
935 CHECK_AND_ASSERT_MES(endpoint,
false,
"Failed to parse proxy: " <<
proxy <<
" - " << endpoint.error());
940 m_enable_dns_seed_nodes &= proxy_dns_leaks_allowed;
941 m_enable_dns_blocklist &= proxy_dns_leaks_allowed;
963 m_config_folder = m_config_folder +
"/" + public_zone.
m_port;
967 CHECK_AND_ASSERT_MES(
res,
false,
"Failed to init config.");
969 for (
auto& zone : m_network_zones)
971 res = zone.second.m_peerlist.init(m_peerlist_storage.take_zone(zone.first), m_allow_local_ip);
972 CHECK_AND_ASSERT_MES(
res,
false,
"Failed to init peerlist.");
975 for(
const auto& p: m_command_line_peers)
976 m_network_zones.at(p.adr.get_zone()).m_peerlist.append_with_peer_white(p);
979 m_have_address =
true;
991 for (
auto& zone : m_network_zones)
993 zone.second.m_net_server.get_config_object().set_handler(
this);
996 if (!zone.second.m_bind_ip.empty())
998 std::string ipv6_addr =
"";
999 std::string ipv6_port =
"";
1000 zone.second.m_net_server.set_connection_filter(
this);
1001 zone.second.m_net_server.set_connection_limit(
this);
1002 MINFO(
"Binding (IPv4) on " << zone.second.m_bind_ip <<
":" << zone.second.m_port);
1003 if (!zone.second.m_bind_ipv6_address.empty() && m_use_ipv6)
1005 ipv6_addr = zone.second.m_bind_ipv6_address;
1006 ipv6_port = zone.second.m_port_ipv6;
1007 MINFO(
"Binding (IPv6) on " << zone.second.m_bind_ipv6_address <<
":" << zone.second.m_port_ipv6);
1010 CHECK_AND_ASSERT_MES(
res,
false,
"Failed to bind server");
1022 MDEBUG(
"External port defined as " << m_external_port);
1027 add_upnp_port_mapping_v4(m_listening_port);
1030 add_upnp_port_mapping_v6(m_listening_port_ipv6);
1037 template<
class t_payload_net_handler>
1040 return m_payload_handler;
1043 template<
class t_payload_net_handler>
1047 mPeersLoggerThread.reset(
new boost::thread([&]()
1049 _note(
"Thread monitor number of peers - start");
1054 for (
auto& zone : m_network_zones)
1056 unsigned int number_of_in_peers = 0;
1057 unsigned int number_of_out_peers = 0;
1060 if (cntxt.m_is_income)
1062 ++number_of_in_peers;
1066 ++number_of_out_peers;
1070 zone.second.m_current_number_of_in_peers = number_of_in_peers;
1071 zone.second.m_current_number_of_out_peers = number_of_out_peers;
1073 boost::this_thread::sleep_for(boost::chrono::seconds(1));
1075 _note(
"Thread monitor number of peers - done");
1083 int thrds_count = 10;
1084 boost::thread::attributes attrs;
1087 MINFO(
"Run net_service loop( " << thrds_count <<
" threads)...");
1090 LOG_ERROR(
"Failed to run net tcp server!");
1093 MINFO(
"net_service loop stopped.");
1097 template<
class t_payload_net_handler>
1101 if (public_zone == m_network_zones.end())
1106 template<
class t_payload_net_handler>
1113 for(
auto& zone : m_network_zones)
1114 zone.second.m_net_server.deinit_server();
1117 delete_upnp_port_mapping(m_listening_port);
1119 return store_config();
1122 template<
class t_payload_net_handler>
1129 MWARNING(
"Failed to create data directory \"" << m_config_folder);
1134 for (
auto& zone : m_network_zones)
1135 zone.second.m_peerlist.get_peerlist(
active);
1138 if (!m_peerlist_storage.store(state_file_path,
active))
1140 MWARNING(
"Failed to save config to file " << state_file_path);
1143 CATCH_ENTRY_L0(
"node_server::store",
false);
1147 template<
class t_payload_net_handler>
1150 MDEBUG(
"[node] sending stop signal");
1151 for (
auto& zone : m_network_zones)
1152 zone.second.m_net_server.send_stop_signal();
1153 MDEBUG(
"[node] Stop signal sent");
1155 for (
auto& zone : m_network_zones)
1157 std::list<boost::uuids::uuid> connection_ids;
1158 zone.second.m_net_server.get_config_object().foreach_connection([&](
const p2p_connection_context& cntxt) {
1159 connection_ids.push_back(cntxt.m_connection_id);
1162 for (
const auto &connection_id: connection_ids)
1163 zone.second.m_net_server.get_config_object().close(connection_id);
1165 m_payload_handler.stop();
1169 template<
class t_payload_net_handler>
1172 network_zone& zone = m_network_zones.at(context_.m_remote_address.get_zone());
1176 get_local_node_data(arg.node_data, zone);
1177 m_payload_handler.get_payload_sync_data(arg.payload_data);
1180 std::atomic<bool> hsh_result(
false);
1181 bool timeout =
false;
1183 bool r = epee::net_utils::async_invoke_remote_command2<typename COMMAND_HANDSHAKE::response>(context_, COMMAND_HANDSHAKE::ID, arg, zone.m_net_server.get_config_object(),
1186 epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){ev.raise();});
1196 if(rsp.node_data.network_id != m_network_id)
1198 LOG_WARNING_CC(context,
"COMMAND_HANDSHAKE Failed, wrong network! (" << rsp.node_data.network_id <<
"), closing connection.");
1202 if(!handle_remote_peerlist(rsp.local_peerlist_new, context))
1204 LOG_WARNING_CC(context,
"COMMAND_HANDSHAKE: failed to handle_remote_peerlist(...), closing connection.");
1205 add_host_fail(context.m_remote_address);
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);
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>
1269 m_payload_handler.get_payload_sync_data(arg.payload_data);
1272 bool r = epee::net_utils::async_invoke_remote_command2<typename COMMAND_TIMED_SYNC::response>(context_, COMMAND_TIMED_SYNC::ID, arg, zone.m_net_server.get_config_object(),
1275 context.m_in_timedsync = false;
1278 LOG_WARNING_CC(context,
"COMMAND_TIMED_SYNC invoke failed. (" << code <<
", " << epee::levin::get_err_descr(code) <<
")");
1282 if(!handle_remote_peerlist(rsp.local_peerlist_new, context))
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 );
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);
1290 if (!m_payload_handler.process_payload_sync_data(rsp.payload_data, context,
false))
1292 m_network_zones.at(context.m_remote_address.get_zone()).m_net_server.get_config_object().close(context.m_connection_id );
1304 template<
class t_payload_net_handler>
1311 size_t x = crypto::rand<size_t>()%(16*max_index+1);
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>
1320 const auto zone = peer.
adr.get_zone();
1321 const auto server = m_network_zones.find(zone);
1322 if (
server == m_network_zones.end())
1326 if(is_public &&
server->second.m_config.m_peer_id == peer.
id)
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>
1345 const auto zone = peer.
adr.get_zone();
1346 const auto server = m_network_zones.find(zone);
1347 if (
server == m_network_zones.end())
1351 if(is_public &&
server->second.m_config.m_peer_id == peer.
id)
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>
1370 const auto zone = m_network_zones.find(peer.
get_zone());
1371 if (zone == m_network_zones.end())
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: "
1423 auto con = zone.m_connect(zone, na, m_ssl_support);
1426 bool is_priority = is_priority_node(na);
1429 record_addr_failed(na);
1433 con->m_anchor = peer_type == anchor;
1435 bool res = do_handshake_with_peer(pi, *con, just_take_peerlist);
1439 bool is_priority = is_priority_node(na);
1443 record_addr_failed(na);
1447 if(just_take_peerlist)
1449 zone.m_net_server.get_config_object().close(con->m_connection_id);
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: "
1490 auto con = zone.m_connect(zone, na, m_ssl_support);
1492 bool is_priority = is_priority_node(na);
1495 record_addr_failed(na);
1500 con->m_anchor =
false;
1502 const bool res = do_handshake_with_peer(pi, *con,
true);
1504 bool is_priority = is_priority_node(na);
1507 record_addr_failed(na);
1511 zone.m_net_server.get_config_object().close(con->m_connection_id);
1513 LOG_DEBUG_CC(*con,
"CONNECTION HANDSHAKED OK AND CLOSED.");
1518#undef LOG_PRINT_CC_PRIORITY_NODE
1521 template<
class t_payload_net_handler>
1525 m_conn_fails_cache[addr.
host_str()] = time(NULL);
1528 template<
class t_payload_net_handler>
1532 auto it = m_conn_fails_cache.find(addr.
host_str());
1533 if(it == m_conn_fails_cache.end())
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());
1548 if(is_peer_used(pe)) {
1549 _note(
"Peer is used");
1553 if(!is_remote_host_allowed(pe.
adr)) {
1557 if(is_addr_recently_failed(pe.
adr)) {
1561 MDEBUG(
"Selected peer: " << peerid_to_string(pe.
id) <<
" " << pe.
adr.str()
1562 <<
"[peer_type=" << anchor
1565 if(!try_to_connect_and_handshake_with_new_peer(pe.
adr,
false, 0, anchor, pe.first_seen)) {
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())
1631 const uint32_t next_needed_pruning_stripe = m_payload_handler.get_next_needed_pruning_stripe().second;
1635 std::set<uint32_t> connected_subnets;
1636 const uint32_t subnet_mask = ntohl(0xffffff00);
1644 const epee::net_utils::network_address na = cntxt.m_remote_address;
1645 const uint32_t actual_ip = na.as<const epee::net_utils::ipv4_network_address>().ip();
1646 connected_subnets.insert(actual_ip & subnet_mask);
1650 const epee::net_utils::network_address na = cntxt.m_remote_address;
1651 const boost::asio::ip::address_v6 &actual_ip = na.as<const epee::net_utils::ipv6_network_address>().ip();
1652 if (actual_ip.is_v4_mapped())
1654 boost::asio::ip::address_v4 v4ip = make_address_v4_from_v6(actual_ip);
1655 uint32_t actual_ipv4;
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;
1767 random_index = get_random_index_with_fixed_probability(filtered.size() - 1);
1770 if (next_needed_pruning_stripe > 0 && next_needed_pruning_stripe <= (1ul <<
CRYPTONOTE_PRUNING_LOG_STRIPES) && !m_used_stripe_peers[next_needed_pruning_stripe-1].empty())
1773 m_used_stripe_peers[next_needed_pruning_stripe-1].pop_front();
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)
1806 if (is_peer_used(candidate)) {
1807 _note(
"Peer is used");
1811 if (!is_remote_host_allowed(candidate.
adr)) {
1812 _note(
"Not allowed");
1816 if (is_addr_recently_failed(candidate.
adr)) {
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);
1827 if (!try_to_connect_and_handshake_with_new_peer(candidate.
adr,
false, candidate.
last_seen, use_white_list ? white : gray)) {
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);
1845 if (!
server.m_seed_nodes_initialized)
1848 boost::upgrade_to_unique_lock<boost::shared_mutex> seed_nodes_lock(seed_nodes_upgrade_lock);
1849 server.m_seed_nodes_initialized =
true;
1850 for (
const auto& full_addr : get_seed_nodes(zone))
1853 MDEBUG(
"Seed node: " << full_addr);
1856 MDEBUG(
"Number of seed nodes: " <<
server.m_seed_nodes.size());
1859 if (
server.m_seed_nodes.empty() || m_offline || !m_exclusive_peers.empty())
1862 size_t try_count = 0;
1863 bool is_connected_to_at_least_one_seed_node =
false;
1867 if(
server.m_net_server.is_stop_signal_sent())
1871 pe_seed.
adr =
server.m_seed_nodes[current_index];
1872 if (is_peer_used(pe_seed))
1873 is_connected_to_at_least_one_seed_node =
true;
1874 else if (try_to_connect_and_handshake_with_new_peer(
server.m_seed_nodes[current_index],
true))
1876 if(++try_count >
server.m_seed_nodes.size())
1881 MWARNING(
"Failed to connect to any of seed peers, trying fallback seeds");
1882 current_index =
server.m_seed_nodes.size() - 1;
1884 boost::upgrade_to_unique_lock<boost::shared_mutex> seed_nodes_lock(seed_nodes_upgrade_lock);
1886 for (
const auto &peer: get_ip_seed_nodes())
1888 MDEBUG(
"Fallback seed node: " << peer);
1892 if (current_index ==
server.m_seed_nodes.size() - 1)
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");
1906 if(++current_index >=
server.m_seed_nodes.size())
1912 template<
class t_payload_net_handler>
1917 if (m_offline)
return true;
1918 if (!connect_to_peerlist(m_exclusive_peers))
return false;
1920 if (!m_exclusive_peers.empty())
return true;
1922 bool one_succeeded =
false;
1923 for(
auto& zone : m_network_zones)
1925 size_t start_conn_count = get_outgoing_connections_count(zone.second);
1926 if(!zone.second.m_peerlist.get_white_peers_count() && !connect_to_seed(zone.first))
1931 if (zone.first == zone_type::public_ && !connect_to_peerlist(m_priority_peers))
continue;
1937 size_t conn_count = get_outgoing_connections_count(zone.second);
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)
1947 while (get_outgoing_connections_count(zone.second) < expected_white_connections
1948 && make_expected_connections_count(zone.second, white, expected_white_connections));
1950 while (get_outgoing_connections_count(zone.second) < zone.second.m_config.m_net_config.max_out_connection_count
1951 && make_expected_connections_count(zone.second, gray, zone.second.m_config.m_net_config.max_out_connection_count));
1955 while (get_outgoing_connections_count(zone.second) < zone.second.m_config.m_net_config.max_out_connection_count
1956 && make_expected_connections_count(zone.second, gray, zone.second.m_config.m_net_config.max_out_connection_count));
1958 while (get_outgoing_connections_count(zone.second) < zone.second.m_config.m_net_config.max_out_connection_count
1959 && make_expected_connections_count(zone.second, white, zone.second.m_config.m_net_config.max_out_connection_count));
1961 if(zone.second.m_net_server.is_stop_signal_sent())
1963 size_t new_conn_count = get_outgoing_connections_count(zone.second);
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");
1977 if (!connect_to_seed(zone.first))
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);
1998 size_t conn_count = get_outgoing_connections_count(zone);
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");
2007 if (peer_type == anchor && !make_new_connection_from_anchor_peerlist(apl)) {
2011 if (peer_type == white && !make_new_connection_from_peerlist(zone,
true)) {
2015 if (peer_type == gray && !make_new_connection_from_peerlist(zone,
false)) {
2022 template<
class t_payload_net_handler>
2026 if (public_zone == m_network_zones.end())
2028 return get_outgoing_connections_count(public_zone->second);
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>
2069 for(
auto& zone : m_network_zones)
2070 count += get_outgoing_connections_count(zone.second);
2074 template<
class t_payload_net_handler>
2078 for (
auto& zone : m_network_zones)
2082 if(cntxt.m_is_income)
2090 template<
class t_payload_net_handler>
2094 if (public_zone == m_network_zones.end())
2099 template<
class t_payload_net_handler>
2103 if (public_zone == m_network_zones.end())
2108 template<
class t_payload_net_handler>
2112 if (public_zone != m_network_zones.end())
2116 template<
class t_payload_net_handler>
2119 for (
auto &zone: m_network_zones)
2121 zone.second.m_peerlist.get_peerlist(gray, white);
2125 template<
class t_payload_net_handler>
2137 template<
class t_payload_net_handler>
2140 if (!m_enable_dns_blocklist)
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>
2198 if (public_zone != m_network_zones.end() && get_incoming_connections_count(public_zone->second) == 0)
2200 if (m_hide_my_port || public_zone->second.
m_config.m_net_config.max_in_connection_count == 0)
2202 MGINFO(
"Incoming connections disabled, enable them for full connectivity");
2206 if (m_igd == delayed_igd)
2208 MWARNING(
"No incoming connections, trying to setup IGD");
2209 add_upnp_port_mapping(m_listening_port);
2215 MCLOG_RED(level,
"global",
"No incoming connections - check firewalls/routers allow port " << get_this_peer_port());
2222 template<
class t_payload_net_handler>
2225 MDEBUG(
"STARTED PEERLIST IDLE HANDSHAKE");
2226 typedef std::list<std::pair<epee::net_utils::connection_context_base, peerid_type> > local_connects_type;
2227 local_connects_type cncts;
2228 for(
auto& zone : m_network_zones)
2235 cncts.push_back(local_connects_type::value_type(cntxt, cntxt.
peer_id));
2241 std::for_each(cncts.begin(), cncts.end(), [&](
const typename local_connects_type::value_type& vl){do_peer_timed_sync(vl.first, vl.second);});
2243 MDEBUG(
"FINISHED PEERLIST IDLE HANDSHAKE");
2247 template<
class t_payload_net_handler>
2250 for (
size_t i = 0; i < local_peerlist.size(); ++i)
2252 bool ignore =
false;
2264 else if (ipv4.port() == be.
rpc_port)
2271 MDEBUG(
"Ignoring " << be.
adr.str());
2272 std::swap(local_peerlist[i], local_peerlist[local_peerlist.size() - 1]);
2273 local_peerlist.resize(local_peerlist.size() - 1);
2277 local_peerlist[i].last_seen = 0;
2282 template<
class t_payload_net_handler>
2287 MWARNING(context <<
"peer sent " << peerlist.size() <<
" peers, considered spamming");
2290 std::vector<peerlist_entry> peerlist_ = peerlist;
2291 if(!sanitize_peerlist(peerlist_))
2295 for(
const auto& peer : peerlist_)
2297 if(peer.adr.get_zone() != zone)
2299 MWARNING(context <<
" sent peerlist from another zone, dropping");
2304 LOG_DEBUG_CC(context,
"REMOTE PEERLIST: remote peerlist size=" << peerlist_.size());
2307 return m_network_zones.at(context.m_remote_address.get_zone()).m_peerlist.merge_peerlist(peerlist_, [
this](
const peerlist_entry &pe) {
2308 return !is_addr_recently_failed(pe.
adr) && is_remote_host_allowed(pe.
adr);
2312 template<
class t_payload_net_handler>
2315 node_data.
peer_id = zone.m_config.m_peer_id;
2316 if(!m_hide_my_port && zone.m_can_pingback)
2317 node_data.
my_port = m_external_port ? m_external_port : m_listening_port;
2320 node_data.
rpc_port = zone.m_can_pingback ? m_rpc_port : 0;
2327 template<
class t_payload_net_handler>
2330 rsp.support_flags = m_network_zones.at(context.m_remote_address.get_zone()).m_config.m_support_flags;
2334 template<
class t_payload_net_handler>
2337 m_network_zones.at(context.m_remote_address.get_zone()).m_net_server.get_config_object().
request_callback(context.m_connection_id);
2340 template<
class t_payload_net_handler>
2344 std::sort(connections.begin(), connections.end());
2345 auto zone = m_network_zones.begin();
2346 for(
const auto& c_id: connections)
2350 if (zone == m_network_zones.end())
2355 if (c_id.first <= zone->first)
2360 if (zone->first == c_id.first)
2361 zone->second.m_net_server.get_config_object().send(message.clone(), c_id.second);
2366 template<
class t_payload_net_handler>
2371 const auto send = [&txs, &
source,
tx_relay] (std::pair<const enet::zone, network_zone>& network)
2373 if (network.second.m_notifier.send_txs(std::move(txs),
source,
tx_relay))
2374 return network.first;
2375 return enet::zone::invalid;
2378 if (m_network_zones.empty())
2379 return enet::zone::invalid;
2381 if (origin != enet::zone::invalid)
2382 return send(*m_network_zones.begin());
2384 if (m_network_zones.size() <= 2)
2385 return send(*m_network_zones.rbegin());
2390 static_assert(std::is_same<std::underlying_type<enet::zone>::type, std::uint8_t>{},
"expected uint8_t zone");
2391 static_assert(unsigned(enet::zone::invalid) == 0,
"invalid expected to be 0");
2392 static_assert(unsigned(enet::zone::public_) == 1,
"public_ expected to be 1");
2393 static_assert(unsigned(enet::zone::i2p) == 2,
"i2p expected to be 2");
2394 static_assert(unsigned(enet::zone::tor) == 3,
"tor expected to be 3");
2397 for (
auto network = ++m_network_zones.begin(); network != m_network_zones.end(); ++network)
2399 if (enet::zone::tor < network->first)
2402 const auto status = network->second.m_notifier.get_status();
2403 if (status.has_noise && status.connections_filled)
2404 return send(*network);
2408 for (
auto network = ++m_network_zones.begin(); network != m_network_zones.end(); ++network)
2410 if (enet::zone::tor < network->first)
2413 const auto status = network->second.m_notifier.get_status();
2414 if (network->second.m_connect && status.has_outgoing)
2415 return send(*network);
2418 MWARNING(
"Unable to send " << txs.size() <<
" transaction(s): anonymity networks had no outgoing connections");
2419 return enet::zone::invalid;
2422 template<
class t_payload_net_handler>
2425 m_payload_handler.on_callback(context);
2428 template<
class t_payload_net_handler>
2434 network_zone& zone = m_network_zones.at(context.m_remote_address.get_zone());
2435 int res = zone.m_net_server.get_config_object().send(message.finalize_notify(command), context.m_connection_id);
2439 template<
class t_payload_net_handler>
2442 m_network_zones.at(context.m_remote_address.get_zone()).m_net_server.get_config_object().close(context.m_connection_id);
2446 template<
class t_payload_net_handler>
template<
class t_callback>
2453 CHECK_AND_ASSERT_MES(address_ok,
false,
2454 "Only IPv4 or IPv6 addresses are supported here");
2459 boost::asio::ip::address_v6 ipv6_addr;
2470 ip = ipv6_addr.to_string();
2475 if(!zone.m_peerlist.is_host_allowed(context.m_remote_address))
2490 bool r = zone.m_net_server.connect_async(
ip,
port, zone.m_config.m_net_config.ping_connection_timeout, [cb,
address, pr,
this](
2492 const boost::system::error_code& ec)->bool
2496 LOG_WARNING_CC(ping_context,
"back ping connect failed to " << address.str());
2512 bool inv_call_res = epee::net_utils::async_invoke_remote_command2<COMMAND_PING::response>(ping_context, COMMAND_PING::ID, req, zone.m_net_server.get_config_object(),
2517 LOG_WARNING_CC(ping_context,
"Failed to invoke COMMAND_PING to " << address.str() <<
"(" << code <<
", " << epee::levin::get_err_descr(code) <<
")");
2524 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));
2525 zone.m_net_server.get_config_object().close(ping_context.m_connection_id);
2528 zone.m_net_server.get_config_object().close(ping_context.m_connection_id);
2535 zone.m_net_server.get_config_object().close(ping_context.m_connection_id);
2539 },
"0.0.0.0", m_ssl_support, p2p_connection_context{
true });
2542 LOG_WARNING_CC(context,
"Failed to call connect_async, network error.");
2547 template<
class t_payload_net_handler>
2554 bool r = epee::net_utils::async_invoke_remote_command2<typename COMMAND_REQUEST_SUPPORT_FLAGS::response>
2557 COMMAND_REQUEST_SUPPORT_FLAGS::ID,
2558 support_flags_request,
2564 LOG_WARNING_CC(context_,
"COMMAND_REQUEST_SUPPORT_FLAGS invoke failed. (" << code <<
", " << epee::levin::get_err_descr(code) <<
")");
2568 f(context_, rsp.support_flags);
2576 template<
class t_payload_net_handler>
2579 if(!m_payload_handler.process_payload_sync_data(arg.payload_data, context,
false))
2581 LOG_WARNING_CC(context,
"Failed to process_payload_sync_data(), dropping connection");
2582 drop_connection(context);
2591 const bool outgoing_to_same_zone = !context.m_is_income && zone.m_our_address.get_zone() == zone_type;
2594 std::vector<peerlist_entry> local_peerlist_new;
2595 zone.m_peerlist.get_peerlist_head(local_peerlist_new,
true, max_peerlist_size);
2603 if(outgoing_to_same_zone)
2605 local_peerlist_new.insert(
2606 local_peerlist_new.begin() +
crypto::rand_range(std::size_t(0), local_peerlist_new.size()),
2612 rsp.local_peerlist_new.reserve(local_peerlist_new.size());
2613 for (
auto &pe: local_peerlist_new)
2615 if (!context.sent_addresses.insert(pe.
adr).second)
2617 rsp.local_peerlist_new.push_back(std::move(pe));
2619 m_payload_handler.get_payload_sync_data(rsp.payload_data);
2625 template<
class t_payload_net_handler>
2628 if(arg.node_data.network_id != m_network_id)
2631 LOG_INFO_CC(context,
"WRONG NETWORK AGENT CONNECTED! id=" << arg.node_data.network_id);
2632 drop_connection(context);
2633 add_host_fail(context.m_remote_address);
2637 if(!context.m_is_income)
2639 LOG_WARNING_CC(context,
"COMMAND_HANDSHAKE came not from incoming connection");
2640 drop_connection(context);
2641 add_host_fail(context.m_remote_address);
2647 LOG_WARNING_CC(context,
"COMMAND_HANDSHAKE came, but seems that connection already have associated peer_id (double COMMAND_HANDSHAKE?)");
2648 drop_connection(context);
2652 const auto azone = context.m_remote_address.get_zone();
2659 LOG_DEBUG_CC(context,
"Connection to self detected, dropping connection");
2660 drop_connection(context);
2664 if(!m_payload_handler.process_payload_sync_data(arg.payload_data, context,
true))
2666 LOG_WARNING_CC(context,
"COMMAND_HANDSHAKE came, but process_payload_sync_data returned false, dropping connection.");
2667 drop_connection(context);
2671 zone.m_notifier.on_handshake_complete(context.m_connection_id, context.m_is_income);
2674 context.peer_id = arg.node_data.peer_id;
2675 context.m_in_timedsync =
false;
2676 context.m_rpc_port = arg.node_data.rpc_port;
2677 context.m_rpc_credits_per_hash = arg.node_data.rpc_credits_per_hash;
2678 context.support_flags = arg.node_data.support_flags;
2680 if(arg.node_data.my_port && zone.m_can_pingback)
2683 uint32_t port_l = arg.node_data.my_port;
2685 try_ping(arg.node_data, context, [peer_id_l, port_l, context,
this]()
2687 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(),
2688 "Only IPv4 or IPv6 addresses are supported here");
2691 const epee::net_utils::network_address na = context.m_remote_address;
2692 if (context.m_remote_address.get_type_id() == epee::net_utils::ipv4_network_address::get_type_id())
2694 pe.adr = epee::net_utils::ipv4_network_address(na.as<epee::net_utils::ipv4_network_address>().ip(), port_l);
2698 pe.adr = epee::net_utils::ipv6_network_address(na.as<epee::net_utils::ipv6_network_address>().ip(), port_l);
2707 this->m_network_zones.at(context.m_remote_address.get_zone()).m_peerlist.append_with_peer_white(pe);
2708 LOG_DEBUG_CC(context,
"PING SUCCESS " << context.m_remote_address.host_str() <<
":" << port_l);
2712 if (context.support_flags == 0)
2713 try_get_support_flags(context, [](p2p_connection_context& flags_context,
const uint32_t& support_flags)
2715 flags_context.support_flags = support_flags;
2719 zone.m_peerlist.get_peerlist_head(rsp.local_peerlist_new,
true);
2720 for (
const auto &e: rsp.local_peerlist_new)
2721 context.sent_addresses.insert(e.adr);
2722 get_local_node_data(rsp.node_data, zone);
2723 m_payload_handler.get_payload_sync_data(rsp.payload_data);
2728 template<
class t_payload_net_handler>
2733 rsp.peer_id = m_network_zones.at(context.m_remote_address.get_zone()).m_config.m_peer_id;
2737 template<
class t_payload_net_handler>
2740 std::vector<peerlist_entry> pl_white;
2741 std::vector<peerlist_entry> pl_gray;
2742 for (
auto& zone : m_network_zones)
2743 zone.second.m_peerlist.get_peerlist(pl_gray, pl_white);
2748 template<
class t_payload_net_handler>
2751 MINFO(
"Connections: \r\n" << print_connections_container() );
2755 template<
class t_payload_net_handler>
2759 std::stringstream ss;
2760 for (
auto& zone : m_network_zones)
2764 ss << cntxt.m_remote_address.str()
2765 <<
" \t\tpeer_id " << peerid_to_string(cntxt.
peer_id)
2766 <<
" \t\tconn_id " << cntxt.m_connection_id << (cntxt.m_is_income ?
" INC":
" OUT")
2771 std::string
s = ss.str();
2775 template<
class t_payload_net_handler>
2781 template<
class t_payload_net_handler>
2784 network_zone& zone = m_network_zones.at(context.m_remote_address.get_zone());
2785 if (!zone.m_net_server.is_stop_signal_sent() && !context.m_is_income) {
2787 na = context.m_remote_address;
2789 zone.m_peerlist.remove_from_peer_anchor(na);
2792 if (!zone.m_net_server.is_stop_signal_sent()) {
2793 zone.m_notifier.on_connection_close(context.m_connection_id);
2795 m_payload_handler.on_connection_close(context);
2800 template<
class t_payload_net_handler>
2803 return (std::find(m_priority_peers.begin(), m_priority_peers.end(), na) != m_priority_peers.end()) || (std::find(m_exclusive_peers.begin(), m_exclusive_peers.end(), na) != m_exclusive_peers.end());
2806 template<
class t_payload_net_handler>
template <
class Container>
2815 if(is_addr_connected(na))
2818 try_to_connect_and_handshake_with_new_peer(na);
2824 template<
class t_payload_net_handler>
template <
class Container>
2829 for(
const std::string& pr_str: perrs)
2835 add_zone(adr->get_zone());
2836 container.push_back(std::move(*adr));
2839 std::vector<epee::net_utils::network_address> resolved_addrs;
2841 CHECK_AND_ASSERT_MES(r,
false,
"Failed to parse or resolve address from string: " << pr_str);
2844 container.push_back(addr);
2851 template<
class t_payload_net_handler>
2858 zone.m_config.m_net_config.max_out_connection_count = max;
2862 template<
class t_payload_net_handler>
2865 zone.m_config.m_net_config.max_in_connection_count = max;
2869 template<
class t_payload_net_handler>
2873 if (public_zone != m_network_zones.end())
2876 public_zone->second.
m_config.m_net_config.max_out_connection_count =
count;
2883 template<
class t_payload_net_handler>
2887 if (public_zone == m_network_zones.end())
2889 return public_zone->second.
m_config.m_net_config.max_out_connection_count;
2892 template<
class t_payload_net_handler>
2896 if (public_zone != m_network_zones.end())
2899 public_zone->second.
m_config.m_net_config.max_in_connection_count =
count;
2905 template<
class t_payload_net_handler>
2909 if (public_zone == m_network_zones.end())
2911 return public_zone->second.
m_config.m_net_config.max_in_connection_count;
2914 template<
class t_payload_net_handler>
2921 _dbg1(
"Set ToS flag " << flag);
2925 template<
class t_payload_net_handler>
2935 MINFO(
"Set limit-up to " << limit <<
" kB/s");
2939 template<
class t_payload_net_handler>
2947 MINFO(
"Set limit-down to " << limit <<
" kB/s");
2951 template<
class t_payload_net_handler>
2967 if(!this->islimitup) {
2969 MINFO(
"Set limit-up to " << limit_up <<
" kB/s");
2971 if(!this->islimitdown) {
2973 MINFO(
"Set limit-down to " << limit_down <<
" kB/s");
2979 template<
class t_payload_net_handler>
2989 if (cntxt.m_is_income && cntxt.m_remote_address.is_same_host(
address)) {
2993 if (count >= max_connections) {
3001 return count >= max_connections;
3004 template<
class t_payload_net_handler>
3007 if (m_offline)
return true;
3008 if (!m_exclusive_peers.empty())
return true;
3010 for (
auto& zone : m_network_zones)
3012 if (m_payload_handler.needs_new_sync_connections(zone.first))
3015 if (zone.second.m_net_server.is_stop_signal_sent())
3018 if (zone.second.m_connect ==
nullptr)
3022 if (!zone.second.m_peerlist.get_random_gray_peer(pe))
3025 if (!check_connection_and_handshake_with_peer(pe.
adr, pe.
last_seen))
3027 zone.second.m_peerlist.remove_from_peer_gray(pe);
3028 LOG_PRINT_L2(
"PEER EVICTED FROM GRAY PEER LIST: address: " << pe.
adr.host_str() <<
" Peer ID: " << peerid_to_string(pe.
id));
3033 LOG_PRINT_L2(
"PEER PROMOTED TO WHITE PEER LIST IP address: " << pe.
adr.host_str() <<
" Peer ID: " << peerid_to_string(pe.
id));
3039 template<
class t_payload_net_handler>
3047 MINFO(
"adding stripe " << stripe <<
" peer: " << context.m_remote_address.str());
3048 m_used_stripe_peers[index].erase(std::remove_if(m_used_stripe_peers[index].begin(), m_used_stripe_peers[index].end(),
3050 m_used_stripe_peers[index].push_back(context.m_remote_address);
3053 template<
class t_payload_net_handler>
3061 MINFO(
"removing stripe " << stripe <<
" peer: " << context.m_remote_address.str());
3062 m_used_stripe_peers[index].erase(std::remove_if(m_used_stripe_peers[index].begin(), m_used_stripe_peers[index].end(),
3066 template<
class t_payload_net_handler>
3070 MINFO(
"clearing used stripe peers");
3071 for (
auto &e: m_used_stripe_peers)
3075 template<
class t_payload_net_handler>
3078 std::string ipversion = ipv6 ?
"(IPv6)" :
"(IPv4)";
3079 MDEBUG(
"Attempting to add IGD port mapping " << ipversion <<
".");
3081 const int ipv6_arg = ipv6 ? 1 : 0;
3083#if MINIUPNPC_API_VERSION > 13
3085 unsigned char ttl = 2;
3092 char lanAddress[64];
3097 std::ostringstream portString;
3103 int portMappingResult;
3105 if (portMappingResult != 0) {
3106 LOG_ERROR(
"UPNP_AddPortMapping failed, error: " <<
strupnperror(portMappingResult));
3110 }
else if (
result == 2) {
3111 MWARNING(
"IGD was found but reported as not connected.");
3112 }
else if (
result == 3) {
3113 MWARNING(
"UPnP device was found but not recognized as IGD.");
3115 MWARNING(
"UPNP_GetValidIGD returned an unknown result code.");
3120 MINFO(
"No IGD was found.");
3124 template<
class t_payload_net_handler>
3127 add_upnp_port_mapping_impl(
port,
false);
3130 template<
class t_payload_net_handler>
3133 add_upnp_port_mapping_impl(
port,
true);
3136 template<
class t_payload_net_handler>
3139 if (ipv4) add_upnp_port_mapping_v4(
port);
3140 if (ipv6) add_upnp_port_mapping_v6(
port);
3144 template<
class t_payload_net_handler>
3147 std::string ipversion = ipv6 ?
"(IPv6)" :
"(IPv4)";
3148 MDEBUG(
"Attempting to delete IGD port mapping " << ipversion <<
".");
3150 const int ipv6_arg = ipv6 ? 1 : 0;
3151#if MINIUPNPC_API_VERSION > 13
3153 unsigned char ttl = 2;
3160 char lanAddress[64];
3165 std::ostringstream portString;
3168 int portMappingResult;
3170 if (portMappingResult != 0) {
3171 LOG_ERROR(
"UPNP_DeletePortMapping failed, error: " <<
strupnperror(portMappingResult));
3175 }
else if (
result == 2) {
3176 MWARNING(
"IGD was found but reported as not connected.");
3177 }
else if (
result == 3) {
3178 MWARNING(
"UPnP device was found but not recognized as IGD.");
3180 MWARNING(
"UPNP_GetValidIGD returned an unknown result code.");
3185 MINFO(
"No IGD was found.");
3189 template<
class t_payload_net_handler>
3192 delete_upnp_port_mapping_impl(
port,
false);
3195 template<
class t_payload_net_handler>
3198 delete_upnp_port_mapping_impl(
port,
true);
3201 template<
class t_payload_net_handler>
3204 delete_upnp_port_mapping_v4(
port);
3205 delete_upnp_port_mapping_v6(
port);
3208 template<
typename t_payload_net_handler>
3209 boost::optional<p2p_connection_context_t<typename t_payload_net_handler::connection_context>>
3212 auto result =
socks_connect_internal(zone.m_net_server.get_stop_signal(), zone.m_net_server.get_io_context(), zone.m_proxy_address, remote);
3216 if (zone.m_net_server.add_connection(context, std::move(*
result), remote, ssl_support))
3217 return {std::move(context)};
3222 template<
typename t_payload_net_handler>
3223 boost::optional<p2p_connection_context_t<typename t_payload_net_handler::connection_context>>
3228 CHECK_AND_ASSERT_MES(is_ipv4 || is_ipv6, boost::none,
3229 "Only IPv4 or IPv6 addresses are supported here");
3243 address = ipv6.ip().to_string();
3248 LOG_ERROR(
"Only IPv4 or IPv6 addresses are supported here");
3254 zone.m_config.m_net_config.connection_timeout,
3255 con,
"0.0.0.0", ssl_support);
3258 return {std::move(con)};
#define s(x, c)
Definition aesb.c:47
cryptonote::block b
Definition block.cpp:40
static void close()
Definition blockchain_blackball.cpp:279
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
t_protocol_handler::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:1455
void set_threads_prefix(const std::string &prefix_name)
Definition abstract_tcp_server2.inl:1424
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
constexpr uint16_t port() const noexcept
Definition net_utils_base.h:87
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
uint16_t port() const noexcept
Definition net_utils_base.h:193
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
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
std::error_code error() const noexcept
Definition expect.h:277
#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 CRYPTONOTE_NAME
Definition cryptonote_config.h:165
#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
int * count
Definition gmock_stress_test.cc:176
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
relay_method tx_relay
Definition levin_notify.cpp:549
std::shared_ptr< detail::zone > zone_
Definition levin_notify.cpp:313
epee::byte_slice active
Definition levin_notify.cpp:257
static int server(unsigned short port, const char *expected_file_name, int ipv6)
Definition minihttptestserver.c:544
uint32_t address
Definition getifaddr.c:269
MINIUPNP_LIBSPEC void freeUPNPDevlist(struct UPNPDev *devlist)
Definition upnpdev.c:13
MINIUPNP_LIBSPEC struct UPNPDev * upnpDiscover(int delay, const char *multicastif, const char *minissdpdsock, int localport, int ipv6, unsigned char ttl, int *error)
Definition miniupnpc.c:342
MINIUPNP_LIBSPEC void FreeUPNPUrls(struct UPNPUrls *urls)
Definition miniupnpc.c:497
MINIUPNP_LIBSPEC int UPNP_GetValidIGD(struct UPNPDev *devlist, struct UPNPUrls *urls, struct IGDdatas *data, char *lanaddr, int lanaddrlen)
Definition miniupnpc.c:544
#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
list second
Definition compare.py:9
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
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
const command_line::arg_descriptor< std::string, false, true, 2 > arg_data_dir
Definition cryptonote_core.cpp:100
@ 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_offline
Definition cryptonote_core.cpp:113
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< 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.
@ Info
Mainly useful to represent current progress of application.
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
zone
Definition enums.h:50
std::string print_connection_context(const connection_context_base &ctx)
Definition net_utils_base.cpp:121
ssl_support_t
Definition net_ssl.h:49
expect< epee::net_utils::network_address > get_network_address(const boost::string_ref address, const std::uint16_t default_port)
Definition parse.cpp:67
expect< boost::asio::ip::tcp::endpoint > get_tcp_endpoint(const boost::string_ref address)
Definition parse.cpp:134
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:39
@ unsupported_address
Type not supported by get_network_address
expect< epee::net_utils::ipv4_network_subnet > get_ipv4_subnet_address(const boost::string_ref address, bool allow_implicit_32)
Definition parse.cpp:112
c
Definition pymoduletest.py:79
r
Definition testupnpigd.py:61
#define LOG_PRINT_CC_PRIORITY_NODE(priority, con, msg)
Definition net_node.inl:1388
#define MIN_WANTED_SEED_NODES
Definition net_node.inl:72
static boost::asio::ip::address_v4 make_address_v4_from_v6(const boost::asio::ip::address_v6 &a)
Definition net_node.inl:74
#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
const portMappingElt code
Definition portlistingparse.c:22
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
boost::endian::big_uint16_t port
Definition socks.cpp:61
boost::endian::big_uint32_t ip
Definition socks.cpp:62
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 igd_desc_parse.h:23
struct IGDdatas_service first
Definition igd_desc_parse.h:33
Definition miniupnpc.h:99
char * controlURL
Definition miniupnpc.h:100
Definition command_line.h:53
uint16_t const P2P_DEFAULT_PORT
Definition cryptonote_config.h:314
Definition levin_base.h:63
Definition misc_language.h:104
Definition net_utils_base.h:367
const network_address m_remote_address
Definition net_utils_base.h:369
Definition p2p_protocol_defs.h:103
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
Definition net_node.h:112
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
Definition p2p_protocol_defs.h:73
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
MINIUPNP_LIBSPEC int UPNP_DeletePortMapping(const char *controlURL, const char *servicetype, const char *extPort, const char *proto, const char *remoteHost)
Definition upnpcommands.c:471
MINIUPNP_LIBSPEC int UPNP_AddPortMapping(const char *controlURL, const char *servicetype, const char *extPort, const char *inPort, const char *inClient, const char *desc, const char *proto, const char *remoteHost, const char *leaseDuration)
Definition upnpcommands.c:339
const char * strupnperror(int err)
Definition upnperrors.c:15