From c2ad9caf013a7221022de79515ff2d65b62fa73a Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 3 Jul 2016 12:51:12 +0100 Subject: allow peers without port The default port is then used --- contrib/epee/include/string_tools.h | 13 +++++++++---- src/p2p/net_node.inl | 5 +++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/contrib/epee/include/string_tools.h b/contrib/epee/include/string_tools.h index b973c6d48..b3623298c 100644 --- a/contrib/epee/include/string_tools.h +++ b/contrib/epee/include/string_tools.h @@ -350,19 +350,24 @@ POP_WARNINGS { //parse ip and address std::string::size_type p = addres.find(':'); + std::string ip_str, port_str; if(p == std::string::npos) { - return false; + port = 0; + ip_str = addres; + } + else + { + ip_str = addres.substr(0, p); + port_str = addres.substr(p+1, addres.size()); } - std::string ip_str = addres.substr(0, p); - std::string port_str = addres.substr(p+1, addres.size()); if(!get_ip_int32_from_string(ip, ip_str)) { return false; } - if(!get_xtype_from_string(port, port_str)) + if(p != std::string::npos && !get_xtype_from_string(port, port_str)) { return false; } diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 0fab40322..75cc8b65a 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -262,6 +262,8 @@ namespace nodetool pe.id = crypto::rand(); bool r = parse_peer_from_string(pe.adr, pr_str); CHECK_AND_ASSERT_MES(r, false, "Failed to parse address from string: " << pr_str); + if (pe.adr.port == 0) + pe.adr.port = testnet ? ::config::testnet::P2P_DEFAULT_PORT : ::config::P2P_DEFAULT_PORT; m_command_line_peers.push_back(pe); } } @@ -1505,12 +1507,15 @@ namespace nodetool bool node_server::parse_peers_and_add_to_container(const boost::program_options::variables_map& vm, const command_line::arg_descriptor > & arg, Container& container) { std::vector perrs = command_line::get_arg(vm, arg); + bool testnet = command_line::get_arg(vm, command_line::arg_testnet_on); for(const std::string& pr_str: perrs) { nodetool::net_address na = AUTO_VAL_INIT(na); bool r = parse_peer_from_string(na, pr_str); CHECK_AND_ASSERT_MES(r, false, "Failed to parse address from string: " << pr_str); + if (na.port == 0) + na.port = testnet ? ::config::testnet::P2P_DEFAULT_PORT : ::config::P2P_DEFAULT_PORT; container.push_back(na); } -- cgit v1.2.3