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:
+29
-6
@@ -23,7 +23,11 @@ let
|
||||
cfg.httpAddress
|
||||
"--listen"
|
||||
"/ip4/0.0.0.0/tcp/${toString cfg.p2pPort}"
|
||||
"--listen"
|
||||
"/ip4/0.0.0.0/udp/${toString cfg.p2pPort}/quic-v1"
|
||||
]
|
||||
++ lib.optional cfg.public "--public"
|
||||
++ lib.optional (!cfg.defaultBootstrap) "--no-default-bootstrap"
|
||||
++ lib.concatMap (r: [
|
||||
"--region"
|
||||
r
|
||||
@@ -47,10 +51,12 @@ in
|
||||
|
||||
regions = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
example = [ "u1j" ];
|
||||
description = ''
|
||||
Regions to replicate: 3-character geohashes, each about 150 km wide.
|
||||
`u1j` is Bonn, `u1h` Cologne, `u1x` Hamburg.
|
||||
`u1j` is Bonn, `u1h` Cologne, `u1x` Hamburg. May be empty only for a
|
||||
bootstrap node ({option}`public`).
|
||||
'';
|
||||
};
|
||||
|
||||
@@ -58,7 +64,23 @@ in
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
example = [ "/ip4/203.0.113.5/tcp/4001/p2p/12D3KooW..." ];
|
||||
description = "Known peers to connect to, as multiaddrs ending in /p2p/<peer id>.";
|
||||
description = "Extra peers to connect to: /p2p/<peer id> multiaddrs or /dnsaddr/<name>.";
|
||||
};
|
||||
|
||||
defaultBootstrap = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = "Also use the built-in bootstrap name (allmende.stinnesbeck.com).";
|
||||
};
|
||||
|
||||
public = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
This machine is reachable from the internet: serve the DHT and relay for
|
||||
nodes behind a NAT. Turn it on for a bootstrap node, and publish the TXT
|
||||
records the node prints (see `journalctl -u allmende`) in DNS.
|
||||
'';
|
||||
};
|
||||
|
||||
httpAddress = lib.mkOption {
|
||||
@@ -74,13 +96,13 @@ in
|
||||
p2pPort = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
default = 4001;
|
||||
description = "TCP port other nodes connect to.";
|
||||
description = "Port other nodes connect to, over TCP and over UDP (QUIC).";
|
||||
};
|
||||
|
||||
openFirewall = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = "Open the peer-to-peer port ({option}`p2pPort`) in the firewall.";
|
||||
description = "Open the peer-to-peer port ({option}`p2pPort`, TCP and UDP) in the firewall.";
|
||||
};
|
||||
|
||||
dataDir = lib.mkOption {
|
||||
@@ -100,8 +122,8 @@ in
|
||||
config = lib.mkIf cfg.enable {
|
||||
assertions = [
|
||||
{
|
||||
assertion = cfg.regions != [ ];
|
||||
message = "services.allmende.regions needs at least one region, for example [ \"u1j\" ].";
|
||||
assertion = cfg.regions != [ ] || cfg.public;
|
||||
message = "services.allmende.regions needs at least one region, for example [ \"u1j\" ] (only a public bootstrap node may have none).";
|
||||
}
|
||||
];
|
||||
|
||||
@@ -154,6 +176,7 @@ in
|
||||
};
|
||||
|
||||
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.p2pPort ];
|
||||
networking.firewall.allowedUDPPorts = lib.mkIf cfg.openFirewall [ cfg.p2pPort ]; # QUIC
|
||||
|
||||
environment.systemPackages = [ admin ];
|
||||
};
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ buildGoModule {
|
||||
|
||||
# Changes whenever go.mod or go.sum do: set it to lib.fakeHash, build, and
|
||||
# copy the hash from the error.
|
||||
vendorHash = "sha256-vUBmsqyS+/qXo3UDYzZmZQYik7rMhOrX7csy56UJbLU=";
|
||||
vendorHash = "sha256-cls1bwmv+BbBwGx5mfNcihENUuojR5Pog5tfVzBKPU8=";
|
||||
|
||||
subPackages = [ "cmd/allmende" ];
|
||||
env.CGO_ENABLED = "0";
|
||||
|
||||
+4
-2
@@ -46,8 +46,10 @@ pkgs.testers.runNixOSTest {
|
||||
machine.succeed("ss -ltn | grep -q '127.0.0.1:8080'")
|
||||
machine.fail("ss -ltn | grep -q '0.0.0.0:8080'")
|
||||
|
||||
with subtest("it survives a restart"):
|
||||
machine.succeed("systemctl restart allmende")
|
||||
with subtest("it stops promptly even though the VM has no DNS, and restarts"):
|
||||
# The built-in bootstrap name cannot be resolved here; stopping must not wait for it.
|
||||
machine.succeed("timeout 3 systemctl stop allmende")
|
||||
machine.succeed("systemctl start allmende")
|
||||
machine.wait_for_open_port(8080)
|
||||
'';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user