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:
@ -53,7 +53,11 @@ BOOTSTRAP_PEERS = [
|
||||
|
||||
async def run(port: int, bootstrap_addrs: list[str]) -> None:
|
||||
"""Run the bootstrap discovery example."""
|
||||
from libp2p.utils.address_validation import find_free_port, get_available_interfaces
|
||||
from libp2p.utils.address_validation import (
|
||||
find_free_port,
|
||||
get_available_interfaces,
|
||||
get_optimal_binding_address,
|
||||
)
|
||||
|
||||
if port <= 0:
|
||||
port = find_free_port()
|
||||
@ -93,6 +97,12 @@ async def run(port: int, bootstrap_addrs: list[str]) -> None:
|
||||
logger.info(f"{addr}")
|
||||
print(f"{addr}")
|
||||
|
||||
# Display optimal address for reference
|
||||
optimal_addr = get_optimal_binding_address(port)
|
||||
optimal_addr_with_peer = f"{optimal_addr}/p2p/{host.get_id().to_string()}"
|
||||
logger.info(f"Optimal address: {optimal_addr_with_peer}")
|
||||
print(f"Optimal address: {optimal_addr_with_peer}")
|
||||
|
||||
# Keep running and log peer discovery events
|
||||
await trio.sleep_forever()
|
||||
except KeyboardInterrupt:
|
||||
|
||||
Reference in New Issue
Block a user