Merge pull request #5610

068fa1c p2p: delay IGP probing on startup (moneromooo-monero)
This commit is contained in:
luigi1111 2019-07-24 14:35:11 -05:00
commit 61512cf798
No known key found for this signature in database
GPG key ID: F4ACA0183641E010
3 changed files with 54 additions and 7 deletions

View file

@ -135,6 +135,7 @@ namespace nodetool
const command_line::arg_descriptor<bool> arg_no_sync = {"no-sync", "Don't synchronize the blockchain with other peers", false}; const command_line::arg_descriptor<bool> arg_no_sync = {"no-sync", "Don't synchronize the blockchain with other peers", false};
const command_line::arg_descriptor<bool> arg_no_igd = {"no-igd", "Disable UPnP port mapping"}; const command_line::arg_descriptor<bool> arg_no_igd = {"no-igd", "Disable UPnP port mapping"};
const command_line::arg_descriptor<std::string> arg_igd = {"igd", "UPnP port mapping (disabled, enabled, delayed)", "delayed"};
const command_line::arg_descriptor<int64_t> arg_out_peers = {"out-peers", "set max number of out peers", -1}; const command_line::arg_descriptor<int64_t> arg_out_peers = {"out-peers", "set max number of out peers", -1};
const command_line::arg_descriptor<int64_t> arg_in_peers = {"in-peers", "set max number of in peers", -1}; const command_line::arg_descriptor<int64_t> arg_in_peers = {"in-peers", "set max number of in peers", -1};
const command_line::arg_descriptor<int> arg_tos_flag = {"tos-flag", "set TOS flag", -1}; const command_line::arg_descriptor<int> arg_tos_flag = {"tos-flag", "set TOS flag", -1};

View file

@ -205,6 +205,13 @@ namespace nodetool
} }
}; };
enum igd_t
{
no_igd,
igd,
delayed_igd,
};
public: public:
typedef t_payload_net_handler payload_net_handler; typedef t_payload_net_handler payload_net_handler;
@ -214,7 +221,7 @@ namespace nodetool
m_rpc_port(0), m_rpc_port(0),
m_allow_local_ip(false), m_allow_local_ip(false),
m_hide_my_port(false), m_hide_my_port(false),
m_no_igd(false), m_igd(no_igd),
m_offline(false), m_offline(false),
is_closing(false), is_closing(false),
m_network_id() m_network_id()
@ -416,7 +423,7 @@ namespace nodetool
uint16_t m_rpc_port; uint16_t m_rpc_port;
bool m_allow_local_ip; bool m_allow_local_ip;
bool m_hide_my_port; bool m_hide_my_port;
bool m_no_igd; igd_t m_igd;
bool m_offline; bool m_offline;
std::atomic<bool> is_closing; std::atomic<bool> is_closing;
std::unique_ptr<boost::thread> mPeersLoggerThread; std::unique_ptr<boost::thread> mPeersLoggerThread;
@ -491,6 +498,7 @@ namespace nodetool
extern const command_line::arg_descriptor<bool> arg_no_sync; extern const command_line::arg_descriptor<bool> arg_no_sync;
extern const command_line::arg_descriptor<bool> arg_no_igd; extern const command_line::arg_descriptor<bool> arg_no_igd;
extern const command_line::arg_descriptor<std::string> arg_igd;
extern const command_line::arg_descriptor<bool> arg_offline; extern const command_line::arg_descriptor<bool> arg_offline;
extern const command_line::arg_descriptor<int64_t> arg_out_peers; extern const command_line::arg_descriptor<int64_t> arg_out_peers;
extern const command_line::arg_descriptor<int64_t> arg_in_peers; extern const command_line::arg_descriptor<int64_t> arg_in_peers;

View file

@ -105,6 +105,7 @@ namespace nodetool
command_line::add_arg(desc, arg_p2p_hide_my_port); command_line::add_arg(desc, arg_p2p_hide_my_port);
command_line::add_arg(desc, arg_no_sync); command_line::add_arg(desc, arg_no_sync);
command_line::add_arg(desc, arg_no_igd); command_line::add_arg(desc, arg_no_igd);
command_line::add_arg(desc, arg_igd);
command_line::add_arg(desc, arg_out_peers); command_line::add_arg(desc, arg_out_peers);
command_line::add_arg(desc, arg_in_peers); command_line::add_arg(desc, arg_in_peers);
command_line::add_arg(desc, arg_tos_flag); command_line::add_arg(desc, arg_tos_flag);
@ -344,7 +345,35 @@ namespace nodetool
public_zone.m_can_pingback = true; public_zone.m_can_pingback = true;
m_external_port = command_line::get_arg(vm, arg_p2p_external_port); m_external_port = command_line::get_arg(vm, arg_p2p_external_port);
m_allow_local_ip = command_line::get_arg(vm, arg_p2p_allow_local_ip); m_allow_local_ip = command_line::get_arg(vm, arg_p2p_allow_local_ip);
m_no_igd = command_line::get_arg(vm, arg_no_igd); const bool has_no_igd = command_line::get_arg(vm, arg_no_igd);
const std::string sigd = command_line::get_arg(vm, arg_igd);
if (sigd == "enabled")
{
if (has_no_igd)
{
MFATAL("Cannot have both --" << arg_no_igd.name << " and --" << arg_igd.name << " enabled");
return false;
}
m_igd = igd;
}
else if (sigd == "disabled")
{
m_igd = no_igd;
}
else if (sigd == "delayed")
{
if (has_no_igd && !command_line::is_arg_defaulted(vm, arg_igd))
{
MFATAL("Cannot have both --" << arg_no_igd.name << " and --" << arg_igd.name << " delayed");
return false;
}
m_igd = has_no_igd ? no_igd : delayed_igd;
}
else
{
MFATAL("Invalid value for --" << arg_igd.name << ", expected enabled, disabled or delayed");
return false;
}
m_offline = command_line::get_arg(vm, cryptonote::arg_offline); m_offline = command_line::get_arg(vm, cryptonote::arg_offline);
if (command_line::has_arg(vm, arg_p2p_add_peer)) if (command_line::has_arg(vm, arg_p2p_add_peer))
@ -764,7 +793,7 @@ namespace nodetool
MDEBUG("External port defined as " << m_external_port); MDEBUG("External port defined as " << m_external_port);
// add UPnP port mapping // add UPnP port mapping
if(!m_no_igd) if(m_igd == igd)
add_upnp_port_mapping(m_listening_port); add_upnp_port_mapping(m_listening_port);
return res; return res;
@ -858,7 +887,7 @@ namespace nodetool
for(auto& zone : m_network_zones) for(auto& zone : m_network_zones)
zone.second.m_net_server.deinit_server(); zone.second.m_net_server.deinit_server();
// remove UPnP port mapping // remove UPnP port mapping
if(!m_no_igd) if(m_igd == igd)
delete_upnp_port_mapping(m_listening_port); delete_upnp_port_mapping(m_listening_port);
} }
return store_config(); return store_config();
@ -1700,11 +1729,20 @@ namespace nodetool
MGINFO("Incoming connections disabled, enable them for full connectivity"); MGINFO("Incoming connections disabled, enable them for full connectivity");
} }
else else
{
if (m_igd == delayed_igd)
{
MWARNING("No incoming connections, trying to setup IGD");
add_upnp_port_mapping(m_listening_port);
m_igd = igd;
}
else
{ {
const el::Level level = el::Level::Warning; const el::Level level = el::Level::Warning;
MCLOG_RED(level, "global", "No incoming connections - check firewalls/routers allow port " << get_this_peer_port()); MCLOG_RED(level, "global", "No incoming connections - check firewalls/routers allow port " << get_this_peer_port());
} }
} }
}
return true; return true;
} }
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------