mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
p2p+rpc: don't skip p2p or rpc port bind failure by default
This commit is contained in:
parent
d66db18c06
commit
d4d2b5c79a
7 changed files with 50 additions and 15 deletions
|
@ -152,7 +152,7 @@ namespace nodetool
|
|||
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<bool> arg_p2p_use_ipv6 = {"p2p-use-ipv6", "Enable IPv6 for p2p", false};
|
||||
const command_line::arg_descriptor<bool> arg_p2p_require_ipv4 = {"p2p-require-ipv4", "Require successful IPv4 bind for p2p", true};
|
||||
const command_line::arg_descriptor<bool> arg_p2p_ignore_ipv4 = {"p2p-ignore-ipv4", "Ignore unsuccessful IPv4 bind for p2p", false};
|
||||
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<int> arg_tos_flag = {"tos-flag", "set TOS flag", -1};
|
||||
|
|
|
@ -510,7 +510,7 @@ namespace nodetool
|
|||
extern const command_line::arg_descriptor<std::string, false, true, 2> arg_p2p_bind_port;
|
||||
extern const command_line::arg_descriptor<std::string, false, true, 2> arg_p2p_bind_port_ipv6;
|
||||
extern const command_line::arg_descriptor<bool> arg_p2p_use_ipv6;
|
||||
extern const command_line::arg_descriptor<bool> arg_p2p_require_ipv4;
|
||||
extern const command_line::arg_descriptor<bool> arg_p2p_ignore_ipv4;
|
||||
extern const command_line::arg_descriptor<uint32_t> arg_p2p_external_port;
|
||||
extern const command_line::arg_descriptor<bool> arg_p2p_allow_local_ip;
|
||||
extern const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_add_peer;
|
||||
|
|
|
@ -97,7 +97,7 @@ namespace nodetool
|
|||
command_line::add_arg(desc, arg_p2p_bind_port, false);
|
||||
command_line::add_arg(desc, arg_p2p_bind_port_ipv6, false);
|
||||
command_line::add_arg(desc, arg_p2p_use_ipv6);
|
||||
command_line::add_arg(desc, arg_p2p_require_ipv4);
|
||||
command_line::add_arg(desc, arg_p2p_ignore_ipv4);
|
||||
command_line::add_arg(desc, arg_p2p_external_port);
|
||||
command_line::add_arg(desc, arg_p2p_allow_local_ip);
|
||||
command_line::add_arg(desc, arg_p2p_add_peer);
|
||||
|
@ -382,7 +382,7 @@ namespace nodetool
|
|||
}
|
||||
m_offline = command_line::get_arg(vm, cryptonote::arg_offline);
|
||||
m_use_ipv6 = command_line::get_arg(vm, arg_p2p_use_ipv6);
|
||||
m_require_ipv4 = command_line::get_arg(vm, arg_p2p_require_ipv4);
|
||||
m_require_ipv4 = !command_line::get_arg(vm, arg_p2p_ignore_ipv4);
|
||||
public_zone.m_notifier = cryptonote::levin::notify{
|
||||
public_zone.m_net_server.get_io_service(), public_zone.m_net_server.get_config_shared(), nullptr, true
|
||||
};
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace cryptonote
|
|||
: rpc_bind_ip({"rpc-bind-ip", rpc_args::tr("Specify IP to bind RPC server"), "127.0.0.1"})
|
||||
, rpc_bind_ipv6_address({"rpc-bind-ipv6-address", rpc_args::tr("Specify IPv6 address to bind RPC server"), "::1"})
|
||||
, rpc_use_ipv6({"rpc-use-ipv6", rpc_args::tr("Allow IPv6 for RPC"), false})
|
||||
, rpc_require_ipv4({"rpc-require-ipv4", rpc_args::tr("Require successful IPv4 bind for RPC"), true})
|
||||
, rpc_ignore_ipv4({"rpc-ignore-ipv4", rpc_args::tr("Ignore unsuccessful IPv4 bind for RPC"), false})
|
||||
, rpc_login({"rpc-login", rpc_args::tr("Specify username[:password] required for RPC server"), "", true})
|
||||
, confirm_external_bind({"confirm-external-bind", rpc_args::tr("Confirm rpc-bind-ip value is NOT a loopback (local) IP")})
|
||||
, rpc_access_control_origins({"rpc-access-control-origins", rpc_args::tr("Specify a comma separated list of origins to allow cross origin resource sharing"), ""})
|
||||
|
@ -113,7 +113,7 @@ namespace cryptonote
|
|||
command_line::add_arg(desc, arg.rpc_bind_ip);
|
||||
command_line::add_arg(desc, arg.rpc_bind_ipv6_address);
|
||||
command_line::add_arg(desc, arg.rpc_use_ipv6);
|
||||
command_line::add_arg(desc, arg.rpc_require_ipv4);
|
||||
command_line::add_arg(desc, arg.rpc_ignore_ipv4);
|
||||
command_line::add_arg(desc, arg.rpc_login);
|
||||
command_line::add_arg(desc, arg.confirm_external_bind);
|
||||
command_line::add_arg(desc, arg.rpc_access_control_origins);
|
||||
|
@ -135,7 +135,7 @@ namespace cryptonote
|
|||
config.bind_ip = command_line::get_arg(vm, arg.rpc_bind_ip);
|
||||
config.bind_ipv6_address = command_line::get_arg(vm, arg.rpc_bind_ipv6_address);
|
||||
config.use_ipv6 = command_line::get_arg(vm, arg.rpc_use_ipv6);
|
||||
config.require_ipv4 = command_line::get_arg(vm, arg.rpc_require_ipv4);
|
||||
config.require_ipv4 = !command_line::get_arg(vm, arg.rpc_ignore_ipv4);
|
||||
if (!config.bind_ip.empty())
|
||||
{
|
||||
// always parse IP here for error consistency
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace cryptonote
|
|||
const command_line::arg_descriptor<std::string> rpc_bind_ip;
|
||||
const command_line::arg_descriptor<std::string> rpc_bind_ipv6_address;
|
||||
const command_line::arg_descriptor<bool> rpc_use_ipv6;
|
||||
const command_line::arg_descriptor<bool> rpc_require_ipv4;
|
||||
const command_line::arg_descriptor<bool> rpc_ignore_ipv4;
|
||||
const command_line::arg_descriptor<std::string> rpc_login;
|
||||
const command_line::arg_descriptor<bool> confirm_external_bind;
|
||||
const command_line::arg_descriptor<std::string> rpc_access_control_origins;
|
||||
|
|
|
@ -30,7 +30,6 @@ set(unit_tests_sources
|
|||
account.cpp
|
||||
apply_permutation.cpp
|
||||
address_from_url.cpp
|
||||
ban.cpp
|
||||
base58.cpp
|
||||
blockchain_db.cpp
|
||||
block_queue.cpp
|
||||
|
@ -68,6 +67,7 @@ set(unit_tests_sources
|
|||
multiexp.cpp
|
||||
multisig.cpp
|
||||
net.cpp
|
||||
node_server.cpp
|
||||
notify.cpp
|
||||
output_distribution.cpp
|
||||
parse_amount.cpp
|
||||
|
|
|
@ -56,13 +56,13 @@ public:
|
|||
bool get_stat_info(cryptonote::core_stat_info& st_inf) const {return true;}
|
||||
bool have_block(const crypto::hash& id) const {return true;}
|
||||
void get_blockchain_top(uint64_t& height, crypto::hash& top_id)const{height=0;top_id=crypto::null_hash;}
|
||||
bool handle_incoming_tx(const cryptonote::tx_blob_entry& tx_blob, cryptonote::tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { return true; }
|
||||
bool handle_incoming_txs(const std::vector<cryptonote::tx_blob_entry>& tx_blob, std::vector<cryptonote::tx_verification_context>& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { return true; }
|
||||
bool handle_incoming_tx(const cryptonote::blobdata& tx_blob, cryptonote::tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { return true; }
|
||||
bool handle_incoming_txs(const std::vector<cryptonote::blobdata>& tx_blob, std::vector<cryptonote::tx_verification_context>& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { return true; }
|
||||
bool handle_incoming_block(const cryptonote::blobdata& block_blob, const cryptonote::block *block, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true) { return true; }
|
||||
void pause_mine(){}
|
||||
void resume_mine(){}
|
||||
bool on_idle(){return true;}
|
||||
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, bool clip_pruned, cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp){return true;}
|
||||
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp){return true;}
|
||||
bool handle_get_objects(cryptonote::NOTIFY_REQUEST_GET_OBJECTS::request& arg, cryptonote::NOTIFY_RESPONSE_GET_OBJECTS::request& rsp, cryptonote::cryptonote_connection_context& context){return true;}
|
||||
cryptonote::blockchain_storage &get_blockchain_storage() { throw std::runtime_error("Called invalid member function: please never call get_blockchain_storage on the TESTING class test_core."); }
|
||||
bool get_test_drop_download() const {return true;}
|
||||
|
@ -84,12 +84,10 @@ public:
|
|||
uint64_t get_earliest_ideal_height_for_version(uint8_t version) const { return 0; }
|
||||
cryptonote::difficulty_type get_block_cumulative_difficulty(uint64_t height) const { return 0; }
|
||||
bool fluffy_blocks_enabled() const { return false; }
|
||||
uint64_t prevalidate_block_hashes(uint64_t height, const std::vector<crypto::hash> &hashes, const std::vector<uint64_t> &weights) { return 0; }
|
||||
uint64_t prevalidate_block_hashes(uint64_t height, const std::vector<crypto::hash> &hashes) { return 0; }
|
||||
bool pad_transactions() { return false; }
|
||||
uint32_t get_blockchain_pruning_seed() const { return 0; }
|
||||
bool prune_blockchain(uint32_t pruning_seed = 0) { return true; }
|
||||
bool is_within_compiled_block_hash_area(uint64_t height) const { return false; }
|
||||
bool has_block_weights(uint64_t height, uint64_t nblocks) const { return false; }
|
||||
void stop() {}
|
||||
};
|
||||
|
||||
|
@ -260,5 +258,42 @@ TEST(ban, ignores_port)
|
|||
ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS_PORT(1,2,3,4,6)));
|
||||
}
|
||||
|
||||
TEST(node_server, bind_same_p2p_port)
|
||||
{
|
||||
const auto new_node = []() -> std::unique_ptr<Server> {
|
||||
test_core pr_core;
|
||||
cryptonote::t_cryptonote_protocol_handler<test_core> cprotocol(pr_core, NULL);
|
||||
std::unique_ptr<Server> server(new Server(cprotocol));
|
||||
cprotocol.set_p2p_endpoint(server.get());
|
||||
|
||||
return server;
|
||||
};
|
||||
|
||||
const auto init = [](const std::unique_ptr<Server>& server, const char* port) -> bool {
|
||||
boost::program_options::options_description desc_options("Command line options");
|
||||
cryptonote::core::init_options(desc_options);
|
||||
Server::init_options(desc_options);
|
||||
|
||||
const char *argv[2] = {nullptr, nullptr};
|
||||
boost::program_options::variables_map vm;
|
||||
boost::program_options::store(boost::program_options::parse_command_line(1, argv, desc_options), vm);
|
||||
|
||||
vm.find(nodetool::arg_p2p_bind_port.name)->second = boost::program_options::variable_value(std::string(port), false);
|
||||
|
||||
boost::program_options::notify(vm);
|
||||
|
||||
return server->init(vm);
|
||||
};
|
||||
|
||||
constexpr char port[] = "48080";
|
||||
constexpr char port_another[] = "58080";
|
||||
|
||||
const auto node = new_node();
|
||||
EXPECT_TRUE(init(node, port));
|
||||
|
||||
EXPECT_FALSE(init(new_node(), port));
|
||||
EXPECT_TRUE(init(new_node(), port_another));
|
||||
}
|
||||
|
||||
namespace nodetool { template class node_server<cryptonote::t_cryptonote_protocol_handler<test_core>>; }
|
||||
namespace cryptonote { template class t_cryptonote_protocol_handler<test_core>; }
|
Loading…
Reference in a new issue