mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2026-09-08 10:05:25 -05:00
* Address deficiency discussed in #8552, add ability to resolve to IPv6 addresses for hostnames. * If there is no prefer_ipv6 in the config, set it True (per @hoffmang9) and write it back to config.yaml * Pass prefer_ipv6 flag to get_host_addr, which required a little digging for it in a few places that call get_host_addr. * Update a couple things for consistency * Move the load_config into Wallet's __init__ so it doesn't get called so many times as it would in has_full_node. * Pass None into get_host_addr if there's no preference in config, so we have only that one place where the coded default lives. also fix an oversight where we were building a PeerInfo from a PeerInfo in some cases. * Change the default here to match the default coded into util/network.py. It seems that github testers can't handle trying to use IPv6 and this may be easier for average users (sadly) * A test to see if manually creating the server on :: (IP6_ANY) lets tests connect to localhost with IPv6 on * Revert back to IPv4 default and remove the override inserted into TCPSite for testing. * Don't test for ip6-localhost, as it's not on all systems. * Bah. Forced formatting of commented code... * Add a type annotation for the addrset variable * If we don't quote the socket enums, pylint gets upset because it has issues figuring out where/how they're defined. So, quote them here. Co-authored-by: Chris Ross <cross+chia@distal.com> Co-authored-by: Kyle Altendorf <sda@fstab.net>
26 lines
1.1 KiB
Python
26 lines
1.1 KiB
Python
import pytest
|
|
from chia.util.network import get_host_addr
|
|
|
|
|
|
class TestNetwork:
|
|
@pytest.mark.asyncio
|
|
async def test_get_host_addr4(self):
|
|
# Run these tests forcing IPv4 resolution
|
|
prefer_ipv6 = False
|
|
assert get_host_addr("127.0.0.1", prefer_ipv6) == "127.0.0.1"
|
|
assert get_host_addr("10.11.12.13", prefer_ipv6) == "10.11.12.13"
|
|
assert get_host_addr("localhost", prefer_ipv6) == "127.0.0.1"
|
|
assert get_host_addr("example.net", prefer_ipv6) == "93.184.216.34"
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_host_addr6(self):
|
|
# Run these tests forcing IPv6 resolution
|
|
prefer_ipv6 = True
|
|
assert get_host_addr("::1", prefer_ipv6) == "::1"
|
|
assert get_host_addr("2000:1000::1234:abcd", prefer_ipv6) == "2000:1000::1234:abcd"
|
|
# ip6-localhost is not always available, and localhost is IPv4 only
|
|
# on some systems. Just test neither here.
|
|
# assert get_host_addr("ip6-localhost", prefer_ipv6) == "::1"
|
|
# assert get_host_addr("localhost", prefer_ipv6) == "::1"
|
|
assert get_host_addr("example.net", prefer_ipv6) == "2606:2800:220:1:248:1893:25c8:1946"
|