libp2p / libp2p/py-libp2p

Enhancement: Kademlia example: bind all interfaces and show public IP

Open
#805 6 comments 0 reactions 2 assignees View on GitHub

@sumanjeet0012 is already working on this.

Since Aug 12, 2025.

Dominant language
Python
Stars
624
Forks
256
Avg merge
1d 34m
Merged PRs (30d)
47

Description

### Description

There are two connectivity issues in the Kademlia DHT example at:
- examples/kademlia/kademlia.py: https://github.com/libp2p/py-libp2p/blob/main/examples/kademlia/kademlia.py

1) The example binds to 127.0.0.1, which prevents external peers from connecting (e.g., on AWS EC2). Binding to 0.0.0.0 resolves this by listening on all interfaces.

2) The example logs/advertises the node’s address using 127.0.0.1, which is incorrect for remote peers. It should display a routable/public IP so that the printed bootstrap command is usable.

Example of incorrect log output in docs:
- https://github.com/libp2p/py-libp2p/blob/main/docs/examples.kademlia.rst

### Motivation

- On cloud hosts and remote deployments, binding to localhost (127.0.0.1) prevents other nodes from connecting to the example node.
- Logging a bootstrap multiaddr with 127.0.0.1 misleads users and results in failed connection attempts from remote peers.
- Fixing both issues improves the out-of-the-box experience and mirrors real-world usage patterns.

### Current Implementation

- The example sets:
- listen address: `/ip4/127.0.0.1/tcp/{port}`
- advertised/logged address: `/ip4/127.0.0.1/tcp/{port}/p2p/{peer_id}`

- Result:
- Other nodes cannot connect when the example runs on a remote host.
- Documentation/logs show a non-routable address for bootstrapping.

### Are you planning to do it yourself in a pull request ?

Maybe

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.