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

@@ -38,7 +38,7 @@ namespace net
{
void get_network_address_host_and_port(const std::string& address, std::string& host, std::string& port)
{
// require ipv6 address format "[addr:addr:addr:...:addr]:port"
// If IPv6 address format with port "[addr:addr:addr:...:addr]:port"
if (address.find(']') != std::string::npos)
{
host = address.substr(1, address.rfind(']') - 1);
@@ -47,6 +47,12 @@ namespace net
port = address.substr(address.rfind(':') + 1);
}
}
// Else if IPv6 address format without port e.g. "addr:addr:addr:...:addr"
else if (std::count(address.begin(), address.end(), ':') >= 2)
{
host = address;
}
// Else IPv4, Tor, I2P address or hostname
else
{
host = address.substr(0, address.rfind(':'));