Feat: Add comprehensive IPv6 support to transport and network layers #1132
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes:- #1111
Discussion:- #1113
This pull request adds comprehensive IPv6 support to the libp2p network stack, including configuration, address handling, and testing. The changes introduce utility functions for handling both IPv4 and IPv6 multiaddrs, update address validation logic, and expand test coverage to ensure correct behavior with IPv6 addresses and environment variable overrides.
IPv6 Support and Address Handling:
libp2p/utils/multiaddr_utils.pyfor extracting IP addresses (IPv4 or IPv6) fromMultiaddrobjects, determining the IP protocol, and constructing multiaddrs from sockets.libp2p/network/swarm.pyandlibp2p/transport/tcp/tcp.pyto use the newextract_ip_from_multiaddrutility, enabling version-agnostic IP extraction and supporting both IPv4 and IPv6 in connection logic. [1] [2] [3] [4] [5] [6]multiaddr_from_socketutility for consistent handling of both IP versions.Configuration and Validation Enhancements:
LIBP2P_BIND_V6) and validation inlibp2p/tools/constants.py, alongside new defaults and multiaddr construction for IPv6._validate_ipv4_addressand_validate_ipv6_addressfunctions in bothlibp2p/tools/constants.pyandlibp2p/utils/address_validation.pyto ensure secure and correct address defaults for both IP versions. [1] [2]libp2p/utils/address_validation.pyto include IPv6 addresses, always add IPv6 loopback for testing, and prefer non-loopback IPv6 addresses when binding. [1] [2] [3]Testing Improvements:
tests/core/tools/test_bind_address_config.pywith tests for IPv6 default binding, environment variable overrides, and custom IPv6 addresses, ensuring robust configuration behavior for both IP versions. [1] [2] [3] [4] [5]These changes collectively modernize the codebase for dual-stack (IPv4/IPv6) support, improve security defaults, and provide better test coverage for address configuration and validation.