Skip to content

Conversation

@yashksaini-coder
Copy link
Contributor

@yashksaini-coder yashksaini-coder commented Jan 13, 2026

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:

  • Added new utility functions in libp2p/utils/multiaddr_utils.py for extracting IP addresses (IPv4 or IPv6) from Multiaddr objects, determining the IP protocol, and constructing multiaddrs from sockets.
  • Updated libp2p/network/swarm.py and libp2p/transport/tcp/tcp.py to use the new extract_ip_from_multiaddr utility, enabling version-agnostic IP extraction and supporting both IPv4 and IPv6 in connection logic. [1] [2] [3] [4] [5] [6]
  • Replaced direct socket-to-multiaddr conversion logic with the new multiaddr_from_socket utility for consistent handling of both IP versions.

Configuration and Validation Enhancements:

  • Introduced IPv6-specific environment variable support (LIBP2P_BIND_V6) and validation in libp2p/tools/constants.py, alongside new defaults and multiaddr construction for IPv6.
  • Refactored and added _validate_ipv4_address and _validate_ipv6_address functions in both libp2p/tools/constants.py and libp2p/utils/address_validation.py to ensure secure and correct address defaults for both IP versions. [1] [2]
  • Updated address selection and expansion logic in libp2p/utils/address_validation.py to include IPv6 addresses, always add IPv6 loopback for testing, and prefer non-loopback IPv6 addresses when binding. [1] [2] [3]

Testing Improvements:

  • Enhanced tests/core/tools/test_bind_address_config.py with 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]
  • Updated core network and swarm tests to use the new utilities and verify listener behavior for both IPv4 and IPv6 addresses. [1] [2] [3]

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.

@yashksaini-coder yashksaini-coder marked this pull request as ready for review January 13, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant