Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/examples.circuit_relay.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Create a file named ``relay_node.py`` with the following content:
logger = logging.getLogger("relay_node")
async def run_relay():
listen_addr = multiaddr.Multiaddr("/ip4/0.0.0.0/tcp/9000")
listen_addr = multiaddr.Multiaddr("/ip4/127.0.0.1/tcp/9000")
host = new_host()
config = RelayConfig(
Expand Down Expand Up @@ -139,7 +139,7 @@ Create a file named ``destination_node.py`` with the following content:
Run a simple destination node that accepts connections.
This is a simplified version that doesn't use the relay functionality.
"""
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/9001")
listen_addr = multiaddr.Multiaddr(f"/ip4/127.0.0.1/tcp/9001")
host = new_host()
# Configure as a relay receiver (stop)
Expand Down Expand Up @@ -259,7 +259,7 @@ Create a file named ``source_node.py`` with the following content:
async def run_source(relay_peer_id=None, destination_peer_id=None):
# Create a libp2p host
listen_addr = multiaddr.Multiaddr("/ip4/0.0.0.0/tcp/9002")
listen_addr = multiaddr.Multiaddr("/ip4/127.0.0.1/tcp/9002")
host = new_host()
# Configure as a relay client
Expand Down Expand Up @@ -428,7 +428,7 @@ Running the Example
Relay node multiaddr: /ip4/127.0.0.1/tcp/9000/p2p/QmaUigQJ9nJERa6GaZuyfaiX91QjYwoQJ46JS3k7ys7SLx
==================================================
Listening on: [<Multiaddr /ip4/0.0.0.0/tcp/9000/p2p/QmaUigQJ9nJERa6GaZuyfaiX91QjYwoQJ46JS3k7ys7SLx>]
Listening on: [<Multiaddr /ip4/127.0.0.1/tcp/9000/p2p/QmaUigQJ9nJERa6GaZuyfaiX91QjYwoQJ46JS3k7ys7SLx>]
Protocol service started
Relay service started successfully
Relay limits: RelayLimits(duration=3600, data=10485760, max_circuit_conns=8, max_reservations=4)
Expand All @@ -447,7 +447,7 @@ Running the Example
Use this ID in the source node: QmPBr38KeQG2ibyL4fxq6yJWpfoVNCqJMHBdNyn1Qe4h5s
==================================================
Listening on: [<Multiaddr /ip4/0.0.0.0/tcp/9001/p2p/QmPBr38KeQG2ibyL4fxq6yJWpfoVNCqJMHBdNyn1Qe4h5s>]
Listening on: [<Multiaddr /ip4/127.0.0.1/tcp/9001/p2p/QmPBr38KeQG2ibyL4fxq6yJWpfoVNCqJMHBdNyn1Qe4h5s>]
Registered echo protocol handler
Protocol service started
Transport created
Expand All @@ -469,7 +469,7 @@ Running the Example
$ python source_node.py
Source node started with ID: QmPyM56cgmFoHTgvMgGfDWRdVRQznmxCDDDg2dJ8ygVXj3
Listening on: [<Multiaddr /ip4/0.0.0.0/tcp/9002/p2p/QmPyM56cgmFoHTgvMgGfDWRdVRQznmxCDDDg2dJ8ygVXj3>]
Listening on: [<Multiaddr /ip4/127.0.0.1/tcp/9002/p2p/QmPyM56cgmFoHTgvMgGfDWRdVRQznmxCDDDg2dJ8ygVXj3>]
Protocol service started
No relay peer ID provided. Please enter the relay\'s peer ID:
Enter relay peer ID: QmaUigQJ9nJERa6GaZuyfaiX91QjYwoQJ46JS3k7ys7SLx
Expand Down
8 changes: 4 additions & 4 deletions docs/examples.identify.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This example demonstrates how to use the libp2p ``identify`` protocol.
$ identify-demo
First host listening. Run this from another console:
identify-demo -p 8889 -d /ip4/0.0.0.0/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM
identify-demo -p 8889 -d /ip4/127.0.0.1/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM
Waiting for incoming identify request...
Expand All @@ -21,13 +21,13 @@ folder and paste it in:

.. code-block:: console
$ identify-demo -p 8889 -d /ip4/0.0.0.0/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM
dialer (host_b) listening on /ip4/0.0.0.0/tcp/8889
$ identify-demo -p 8889 -d /ip4/127.0.0.1/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM
dialer (host_b) listening on /ip4/127.0.0.1/tcp/8889
Second host connecting to peer: QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM
Starting identify protocol...
Identify response:
Public Key (Base64): CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDC6c/oNPP9X13NDQ3Xrlp3zOj+ErXIWb/A4JGwWchiDBwMhMslEX3ct8CqI0BqUYKuwdFjowqqopOJ3cS2MlqtGaiP6Dg9bvGqSDoD37BpNaRVNcebRxtB0nam9SQy3PYLbHAmz0vR4ToSiL9OLRORnGOxCtHBuR8ZZ5vS0JEni8eQMpNa7IuXwyStnuty/QjugOZudBNgYSr8+9gH722KTjput5IRL7BrpIdd4HNXGVRm4b9BjNowvHu404x3a/ifeNblpy/FbYyFJEW0looygKF7hpRHhRbRKIDZt2BqOfT1sFkbqsHE85oY859+VMzP61YELgvGwai2r7KcjkW/AgMBAAE=
Listen Addresses: ['/ip4/0.0.0.0/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM']
Listen Addresses: ['/ip4/127.0.0.1/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM']
Protocols: ['/ipfs/id/1.0.0', '/ipfs/ping/1.0.0']
Observed Address: ['/ip4/127.0.0.1/tcp/38082']
Protocol Version: ipfs/0.1.0
Expand Down
8 changes: 4 additions & 4 deletions docs/examples.identify_push.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ There is also a more interactive version of the example which runs as separate l
==== Starting Identify-Push Listener on port 8888 ====
Listener host ready!
Listening on: /ip4/0.0.0.0/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM
Listening on: /ip4/127.0.0.1/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM
Peer ID: QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM
Run dialer with command:
identify-push-listener-dialer-demo -d /ip4/0.0.0.0/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM
identify-push-listener-dialer-demo -d /ip4/127.0.0.1/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM
Waiting for incoming connections... (Ctrl+C to exit)
Expand All @@ -47,12 +47,12 @@ folder and paste it in:

.. code-block:: console
$ identify-push-listener-dialer-demo -d /ip4/0.0.0.0/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM
$ identify-push-listener-dialer-demo -d /ip4/127.0.0.1/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM
==== Starting Identify-Push Dialer on port 8889 ====
Dialer host ready!
Listening on: /ip4/0.0.0.0/tcp/8889/p2p/QmZyXwVuTaBcDeRsSkJpOpWrSt
Listening on: /ip4/127.0.0.1/tcp/8889/p2p/QmZyXwVuTaBcDeRsSkJpOpWrSt
Connecting to peer: QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM
Successfully connected to listener!
Expand Down
4 changes: 2 additions & 2 deletions docs/examples.pubsub.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This example demonstrates how to create a chat application using libp2p's PubSub
2025-04-06 23:59:17,471 - pubsub-demo - INFO - Your selected topic is: pubsub-chat
2025-04-06 23:59:17,472 - pubsub-demo - INFO - Using random available port: 33269
2025-04-06 23:59:17,490 - pubsub-demo - INFO - Node started with peer ID: QmcJnocH1d1tz3Zp4MotVDjNfNFawXHw2dpB9tMYGTXJp7
2025-04-06 23:59:17,490 - pubsub-demo - INFO - Listening on: /ip4/0.0.0.0/tcp/33269
2025-04-06 23:59:17,490 - pubsub-demo - INFO - Listening on: /ip4/127.0.0.1/tcp/33269
2025-04-06 23:59:17,490 - pubsub-demo - INFO - Initializing PubSub and GossipSub...
2025-04-06 23:59:17,491 - pubsub-demo - INFO - Pubsub and GossipSub services started.
2025-04-06 23:59:17,491 - pubsub-demo - INFO - Pubsub ready.
Expand All @@ -35,7 +35,7 @@ Copy the line that starts with ``pubsub-demo -d``, open a new terminal and paste
2025-04-07 00:00:59,846 - pubsub-demo - INFO - Your selected topic is: pubsub-chat
2025-04-07 00:00:59,846 - pubsub-demo - INFO - Using random available port: 51977
2025-04-07 00:00:59,864 - pubsub-demo - INFO - Node started with peer ID: QmYQKCm95Ut1aXsjHmWVYqdaVbno1eKTYC8KbEVjqUaKaQ
2025-04-07 00:00:59,864 - pubsub-demo - INFO - Listening on: /ip4/0.0.0.0/tcp/51977
2025-04-07 00:00:59,864 - pubsub-demo - INFO - Listening on: /ip4/127.0.0.1/tcp/51977
2025-04-07 00:00:59,864 - pubsub-demo - INFO - Initializing PubSub and GossipSub...
2025-04-07 00:00:59,864 - pubsub-demo - INFO - Pubsub and GossipSub services started.
2025-04-07 00:00:59,865 - pubsub-demo - INFO - Pubsub ready.
Expand Down
2 changes: 1 addition & 1 deletion docs/examples.random_walk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The Random Walk implementation performs the following key operations:
2025-08-12 19:51:25,424 - random-walk-example - INFO - Mode: server, Port: 0 Demo interval: 30s
2025-08-12 19:51:25,426 - random-walk-example - INFO - Starting server node on port 45123
2025-08-12 19:51:25,426 - random-walk-example - INFO - Node peer ID: 16Uiu2HAm7EsNv5vvjPAehGAVfChjYjD63ZHyWogQRdzntSbAg9ef
2025-08-12 19:51:25,426 - random-walk-example - INFO - Node address: /ip4/0.0.0.0/tcp/45123/p2p/16Uiu2HAm7EsNv5vvjPAehGAVfChjYjD63ZHyWogQRdzntSbAg9ef
2025-08-12 19:51:25,426 - random-walk-example - INFO - Node address: /ip4/127.0.0.1/tcp/45123/p2p/16Uiu2HAm7EsNv5vvjPAehGAVfChjYjD63ZHyWogQRdzntSbAg9ef
2025-08-12 19:51:25,427 - random-walk-example - INFO - Initial routing table size: 0
2025-08-12 19:51:25,427 - random-walk-example - INFO - DHT service started in SERVER mode
2025-08-12 19:51:25,430 - libp2p.discovery.random_walk.rt_refresh_manager - INFO - RT Refresh Manager started
Expand Down
4 changes: 2 additions & 2 deletions examples/advanced/network_discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
except ImportError:
# Fallbacks if utilities are missing
def get_available_interfaces(port: int, protocol: str = "tcp"):
return [Multiaddr(f"/ip4/0.0.0.0/{protocol}/{port}")]
return [Multiaddr(f"/ip4/127.0.0.1/{protocol}/{port}")]

def expand_wildcard_address(addr: Multiaddr, port: int | None = None):
if port is None:
Expand All @@ -27,7 +27,7 @@ def expand_wildcard_address(addr: Multiaddr, port: int | None = None):
return [Multiaddr(addr_str + f"/{port}")]

def get_optimal_binding_address(port: int, protocol: str = "tcp"):
return Multiaddr(f"/ip4/0.0.0.0/{protocol}/{port}")
return Multiaddr(f"/ip4/127.0.0.1/{protocol}/{port}")


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion examples/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def run(port: int, bootstrap_addrs: list[str]) -> None:
key_pair = create_new_key_pair(secret)

# Create listen address
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
listen_addr = multiaddr.Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")

# Register peer discovery handler
peerDiscovery.register_peer_discovered_handler(on_peer_discovery)
Expand Down
2 changes: 1 addition & 1 deletion examples/chat/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def write_data(stream: INetStream) -> None:


async def run(port: int, destination: str) -> None:
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
listen_addr = multiaddr.Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")
host = new_host()
async with host.run(listen_addrs=[listen_addr]), trio.open_nursery() as nursery:
# Start the peer-store cleanup task
Expand Down
2 changes: 1 addition & 1 deletion examples/doc-examples/example_encryption_insecure.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def main():

# Configure the listening address
port = 8000
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
listen_addr = multiaddr.Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")

# Start the host
async with host.run(listen_addrs=[listen_addr]):
Expand Down
2 changes: 1 addition & 1 deletion examples/doc-examples/example_encryption_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def main():

# Configure the listening address
port = 8000
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
listen_addr = multiaddr.Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")

# Start the host
async with host.run(listen_addrs=[listen_addr]):
Expand Down
2 changes: 1 addition & 1 deletion examples/doc-examples/example_encryption_secio.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def main():

# Configure the listening address
port = 8000
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
listen_addr = multiaddr.Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")

# Start the host
async with host.run(listen_addrs=[listen_addr]):
Expand Down
2 changes: 1 addition & 1 deletion examples/doc-examples/example_multiplexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def main():

# Configure the listening address
port = 8000
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
listen_addr = multiaddr.Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")

# Start the host
async with host.run(listen_addrs=[listen_addr]):
Expand Down
2 changes: 1 addition & 1 deletion examples/doc-examples/example_net_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ async def run_enhanced_demo(
"""
Run enhanced echo demo with NetStream state management.
"""
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
listen_addr = multiaddr.Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")

# Generate or use provided key
if seed:
Expand Down
2 changes: 1 addition & 1 deletion examples/doc-examples/example_peer_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def main():

# Configure the listening address
port = 8000
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
listen_addr = multiaddr.Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")

# Start the host
async with host.run(listen_addrs=[listen_addr]):
Expand Down
2 changes: 1 addition & 1 deletion examples/doc-examples/example_running.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def main():

# Configure the listening address
port = 8000
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
listen_addr = multiaddr.Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")

# Start the host
async with host.run(listen_addrs=[listen_addr]):
Expand Down
2 changes: 1 addition & 1 deletion examples/doc-examples/example_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async def main():

# Configure the listening address
port = 8000
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
listen_addr = multiaddr.Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")

# Start the host
async with host.run(listen_addrs=[listen_addr]):
Expand Down
7 changes: 3 additions & 4 deletions examples/identify/identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def print_identify_response(identify_response: Identify):


async def run(port: int, destination: str, use_varint_format: bool = True) -> None:
localhost_ip = "0.0.0.0"
localhost_ip = "127.0.0.1"

if not destination:
# Create first host (listener)
Expand All @@ -79,10 +79,9 @@ async def run(port: int, destination: str, use_varint_format: bool = True) -> No
# Start the peer-store cleanup task
nursery.start_soon(host_a.get_peerstore().start_cleanup_task, 60)

# Get the actual address and replace 0.0.0.0 with 127.0.0.1 for client
# connections
# Get the actual address
server_addr = str(host_a.get_addrs()[0])
client_addr = server_addr.replace("/ip4/0.0.0.0/", "/ip4/127.0.0.1/")
client_addr = server_addr

format_name = "length-prefixed" if use_varint_format else "raw protobuf"
format_flag = "--raw-format" if not use_varint_format else ""
Expand Down
4 changes: 2 additions & 2 deletions examples/identify_push/identify_push_listener_dialer.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ async def run_listener(
)

# Start listening
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
listen_addr = multiaddr.Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")

try:
async with host.run([listen_addr]):
Expand Down Expand Up @@ -275,7 +275,7 @@ async def run_dialer(
)

# Start listening on a different port
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
listen_addr = multiaddr.Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")

async with host.run([listen_addr]):
logger.info("Dialer host ready!")
Expand Down
2 changes: 1 addition & 1 deletion examples/mDNS/mDNS.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def onPeerDiscovery(peerinfo: PeerInfo):
async def run(port: int) -> None:
secret = secrets.token_bytes(32)
key_pair = create_new_key_pair(secret)
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
listen_addr = multiaddr.Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")

peerDiscovery.register_peer_discovered_handler(onPeerDiscovery)

Expand Down
2 changes: 1 addition & 1 deletion examples/ping/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def send_ping(stream: INetStream) -> None:


async def run(port: int, destination: str) -> None:
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
listen_addr = multiaddr.Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")
host = new_host(listen_addrs=[listen_addr])

async with host.run(listen_addrs=[listen_addr]), trio.open_nursery() as nursery:
Expand Down
2 changes: 1 addition & 1 deletion examples/pubsub/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async def run(topic: str, destination: str | None, port: int | None) -> None:
port = find_free_port()
logger.info(f"Using random available port: {port}")

listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
listen_addr = multiaddr.Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")

# Create a new libp2p host
host = new_host(
Expand Down
4 changes: 2 additions & 2 deletions examples/random_walk/random_walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async def run_node(port: int, mode: str, demo_interval: int = 30) -> None:
# Create host and DHT
key_pair = create_new_key_pair(secrets.token_bytes(32))
host = new_host(key_pair=key_pair, bootstrap=DEFAULT_BOOTSTRAP_NODES)
listen_addr = Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
listen_addr = Multiaddr(f"/ip4/127.0.0.1/tcp/{port}")

async with host.run(listen_addrs=[listen_addr]), trio.open_nursery() as nursery:
# Start maintenance tasks
Expand All @@ -139,7 +139,7 @@ async def run_node(port: int, mode: str, demo_interval: int = 30) -> None:

peer_id = host.get_id().pretty()
logger.info(f"Node peer ID: {peer_id}")
logger.info(f"Node address: /ip4/0.0.0.0/tcp/{port}/p2p/{peer_id}")
logger.info(f"Node address: /ip4/127.0.0.1/tcp/{port}/p2p/{peer_id}")

# Create and start DHT with Random Walk enabled
dht = KadDHT(host, dht_mode, enable_random_walk=True)
Expand Down
6 changes: 3 additions & 3 deletions libp2p/utils/address_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def get_available_interfaces(port: int, protocol: str = "tcp") -> list[Multiaddr

# Fallback if nothing discovered
if not addrs:
addrs.append(Multiaddr(f"/ip4/0.0.0.0/{protocol}/{port}"))
addrs.append(Multiaddr(f"/ip4/127.0.0.1/{protocol}/{port}"))

return addrs

Expand Down Expand Up @@ -148,8 +148,8 @@ def is_non_loopback(ma: Multiaddr) -> bool:
if "/ip4/127." in str(c) or "/ip6/::1" in str(c):
return c

# As a final fallback, produce a wildcard
return Multiaddr(f"/ip4/0.0.0.0/{protocol}/{port}")
# As a final fallback, produce a loopback address
return Multiaddr(f"/ip4/127.0.0.1/{protocol}/{port}")


__all__ = [
Expand Down
2 changes: 2 additions & 0 deletions newsfragments/885.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Enhanced security by defaulting to loopback address (127.0.0.1) instead of wildcard binding.
All examples and core modules now use secure default addresses to prevent unintended public exposure.
Loading
Loading