remove some seemingly unnecessary TORRENT_TRY and TORRENT_CATCH from is_local(), is_any() and is_teredo(). simplify is_loopback()

This commit is contained in:
arvidn 2020-02-26 10:59:57 +01:00 committed by Arvid Norberg
parent cc792d8638
commit 1dcbeb2e60
1 changed files with 28 additions and 38 deletions

View File

@ -55,7 +55,6 @@ namespace libtorrent {
bool is_local(address const& a)
{
TORRENT_TRY {
if (a.is_v6())
{
// NOTE: site local is deprecated but by
@ -79,39 +78,30 @@ namespace libtorrent {
|| (ip & 0xffff0000) == 0xc0a80000 // 192.168.x.x
|| (ip & 0xffff0000) == 0xa9fe0000 // 169.254.x.x
|| (ip & 0xff000000) == 0x7f000000); // 127.x.x.x
} TORRENT_CATCH(std::exception const&) { return false; }
}
// TODO: this function is pointless
bool is_loopback(address const& addr)
{
TORRENT_TRY {
if (addr.is_v4())
return addr.to_v4() == address_v4::loopback();
else
return addr.to_v6() == address_v6::loopback();
} TORRENT_CATCH(std::exception const&) { return false; }
return addr.is_loopback();
}
bool is_any(address const& addr)
{
TORRENT_TRY {
if (addr.is_v4())
return addr.to_v4() == address_v4::any();
else if (addr.to_v6().is_v4_mapped())
return (addr.to_v6().to_v4() == address_v4::any());
else
return addr.to_v6() == address_v6::any();
} TORRENT_CATCH(std::exception const&) { return false; }
}
bool is_teredo(address const& addr)
{
TORRENT_TRY {
if (!addr.is_v6()) return false;
static const std::uint8_t teredo_prefix[] = {0x20, 0x01, 0, 0};
address_v6::bytes_type b = addr.to_v6().to_bytes();
return std::memcmp(b.data(), teredo_prefix, 4) == 0;
} TORRENT_CATCH(std::exception const&) { return false; }
}
bool supports_ipv6()