mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Refactor: update examples to utilize new address paradigm with wildcard support
- Introduced `get_wildcard_address` function for explicit wildcard binding. - Updated examples to use `get_available_interfaces` and `get_optimal_binding_address` for address selection. - Ensured consistent usage of the new address paradigm across all example files. - Added tests to verify the implementation of the new address paradigm and wildcard feature.
This commit is contained in:
@ -14,6 +14,7 @@ try:
|
||||
expand_wildcard_address,
|
||||
get_available_interfaces,
|
||||
get_optimal_binding_address,
|
||||
get_wildcard_address,
|
||||
)
|
||||
except ImportError:
|
||||
# Fallbacks if utilities are missing
|
||||
@ -29,6 +30,9 @@ except ImportError:
|
||||
def get_optimal_binding_address(port: int, protocol: str = "tcp"):
|
||||
return Multiaddr(f"/ip4/127.0.0.1/{protocol}/{port}")
|
||||
|
||||
def get_wildcard_address(port: int, protocol: str = "tcp"):
|
||||
return Multiaddr(f"/ip4/0.0.0.0/{protocol}/{port}")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
port = 8080
|
||||
@ -37,7 +41,10 @@ def main() -> None:
|
||||
for a in interfaces:
|
||||
print(f" - {a}")
|
||||
|
||||
wildcard_v4 = Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
|
||||
# Demonstrate wildcard address as a feature
|
||||
wildcard_v4 = get_wildcard_address(port)
|
||||
print(f"\nWildcard address (feature): {wildcard_v4}")
|
||||
|
||||
expanded_v4 = expand_wildcard_address(wildcard_v4)
|
||||
print("\nExpanded IPv4 wildcard:")
|
||||
for a in expanded_v4:
|
||||
|
||||
Reference in New Issue
Block a user