Add bootstrap nodes, DNS-based discovery, a DHT per region and NAT traversal

- Bootstrap: built-in /dnsaddr/allmende.stinnesbeck.com (TXT records at
  _dnsaddr.<name>), resolved at every redial with the last good answer kept;
  --bootstrap takes /p2p/ or /dnsaddr/ entries, --no-default-bootstrap drops
  the built-in one. Stopping never waits for a stuck resolver.
- Remembered peers in peers.json (saved every 5 min and on shutdown, redialled
  at the next start)
- Private Kademlia DHT (/allmende prefix), advertised and looked up per region
  with quick first attempts and a backoff; --no-dht turns it off
- NAT traversal: port mapping, hole punching, AutoRelay through bootstrap nodes
- --public: DHT server and relay for a bootstrap node; prints the TXT records
- Docker, NixOS module (public, defaultBootstrap, QUIC/UDP) and docs updated
- e2e: bootstrap node scenario, seed cache restart, and polling that really polls

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 22:14:34 +01:00
co-authored by Claude Sonnet 5.5
parent a81595e9ee
commit e7bec4fb63
18 changed files with 1281 additions and 69 deletions
+18 -3
View File
@@ -28,8 +28,23 @@ Owners publish from the same screen: "New listing" takes a title, price and
pasted coordinates (only a ~1 km area is published, never the address), and
listings can be edited, renewed (30 days, manually) or deleted there.
A second node on the same network finds this one automatically (mDNS); across
networks, pass `--bootstrap /ip4/<addr>/tcp/<port>/p2p/<peer id>`.
Nodes find each other through a bootstrap list in DNS (`allmende.stinnesbeck.com`),
the peers they met last time, a DHT per region, and mDNS on the local network.
Add your own bootstrap peers with `--bootstrap /ip4/<addr>/tcp/<port>/p2p/<peer id>`
(or `/dnsaddr/<name>`), or turn the built-in one off with `--no-default-bootstrap`.
**Running a bootstrap node** helps everyone else connect, and nodes behind a home
router use it as a relay. It needs a public address:
```
allmende run --public --listen /ip4/0.0.0.0/tcp/4001 --listen /ip4/0.0.0.0/udp/4001/quic-v1
```
It prints the DNS TXT records to publish at `_dnsaddr.allmende.stinnesbeck.com`
(`dnsaddr=/ip4/<ip>/tcp/4001/p2p/<peer id>`, one per address). With a few such
nodes on different networks, the network no longer depends on any one of them.
In Docker replace the command (see the end of the `Dockerfile`) and add `--public`;
the NixOS module has `services.allmende.public = true`.
## Running a node for real
@@ -42,7 +57,7 @@ targets: `make build run test check e2e docker` (`make help` lists them).
docker build -t allmende . # or: make docker
docker run --rm -it -v allmende-data:/data allmende init # once; write down the phrase
docker run -d --name allmende -v allmende-data:/data \
-p 127.0.0.1:8080:8080 -p 4001:4001 allmende # Bonn (u1j) by default
-p 127.0.0.1:8080:8080 -p 4001:4001 -p 4001:4001/udp allmende # Bonn (u1j) by default
docker logs allmende | grep -A1 'Owner login' # the sign-in link
```