p2p: fix exclusive node DNS resolution for certain hosts

Fixes #8633. The function `append_net_address` did not parse hostname + port addresses (e.g. `bar:29080`) correctly if the hostname did not contain a `'.'` character.

@vtnerd comments 1

clear up 2nd conditional statement
This commit is contained in:
Jeffrey Ryan 2022-11-16 15:53:15 -06:00
parent 365fd45b03
commit faaf2af43b
4 changed files with 55 additions and 14 deletions

View file

@ -936,6 +936,41 @@ TEST(get_network_address, ipv4subnet)
EXPECT_STREQ("12.34.0.0/16", address->str().c_str());
}
namespace
{
void na_host_and_port_test(std::string addr, std::string exp_host, std::string exp_port)
{
std::string host{"xxxxx"};
std::string port{"xxxxx"};
net::get_network_address_host_and_port(addr, host, port);
EXPECT_EQ(exp_host, host);
EXPECT_EQ(exp_port, port);
}
} // anonymous namespace
TEST(get_network_address_host_and_port, ipv4)
{
na_host_and_port_test("9.9.9.9", "9.9.9.9", "xxxxx");
na_host_and_port_test("9.9.9.9:18081", "9.9.9.9", "18081");
}
TEST(get_network_address_host_and_port, ipv6)
{
na_host_and_port_test("::ffff", "::ffff", "xxxxx");
na_host_and_port_test("[::ffff]", "::ffff", "xxxxx");
na_host_and_port_test("[::ffff]:00231", "::ffff", "00231");
na_host_and_port_test("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "xxxxx");
na_host_and_port_test("[7777:7777:7777:7777:7777:7777:7777:7777]", "7777:7777:7777:7777:7777:7777:7777:7777", "xxxxx");
na_host_and_port_test("[7777:7777:7777:7777:7777:7777:7777:7777]:48080", "7777:7777:7777:7777:7777:7777:7777:7777", "48080");
}
TEST(get_network_address_host_and_port, hostname)
{
na_host_and_port_test("localhost", "localhost", "xxxxx");
na_host_and_port_test("bar:29080", "bar", "29080"); // Issue https://github.com/monero-project/monero/issues/8633
na_host_and_port_test("xmrchain.net:18081", "xmrchain.net", "18081");
}
namespace
{
using stream_type = boost::asio::ip::tcp;