Replace two-node-udp with Docker network test harness, fix dead code warnings

Replace examples/two-node-udp/ (netns-based) with examples/docker-network/
(Docker compose, 5 nodes, mesh + chain topologies). The new harness uses
auto-detecting build script and includes SVG topology diagrams.

Remove unused get_session_mut, remote_addr(), remote_pubkey() methods.
Gate test-only accessors with #[cfg(test)]. Zero warnings in release build.
This commit is contained in:
Johnathan Corgan
2026-02-14 18:38:26 +00:00
parent 801a5ab222
commit 5236fd02bf
23 changed files with 983 additions and 395 deletions
+1
View File
@@ -0,0 +1 @@
fips
+11
View File
@@ -0,0 +1,11 @@
FROM debian:bookworm-slim
RUN apt-get update && \
apt-get install -y --no-install-recommends \
iproute2 iputils-ping dnsutils && \
rm -rf /var/lib/apt/lists/*
COPY fips /usr/local/bin/
RUN chmod +x /usr/local/bin/fips
ENTRYPOINT ["fips", "--config", "/etc/fips/fips.yaml"]
+134
View File
@@ -0,0 +1,134 @@
# Docker Network Test Harness
Multi-node integration test for FIPS using Docker containers. Two topologies
are provided: a sparse mesh (5 nodes, 6 links) and a linear chain (5 nodes,
4 links). Both exercise the full FIPS stack including TUN devices, DNS
resolution, peer link encryption, spanning tree construction, and
discovery-driven multi-hop routing.
## Prerequisites
- Docker with the compose plugin
- Rust toolchain (for building the FIPS binary)
## Quick Start
Build the binary and copy it to the docker context:
```bash
./scripts/build.sh
```
### Mesh Topology
```bash
docker compose --profile mesh build
docker compose --profile mesh up -d
./scripts/ping-test.sh mesh # 20/20 expected
docker compose --profile mesh down
```
### Chain Topology
```bash
docker compose --profile chain build
docker compose --profile chain up -d
./scripts/ping-test.sh chain # 6/6 expected
docker compose --profile chain down
```
## Mesh Topology
![Mesh Topology](docker-mesh-topology.svg)
Five nodes with 6 bidirectional UDP links forming a sparse, fully connected
graph. Not all nodes are direct peers — non-adjacent pairs require
discovery-driven multi-hop routing to establish end-to-end sessions.
The spanning tree is rooted at node A, which has the lexicographically
smallest `NodeAddr` (the first 16 bytes of `SHA-256(pubkey)`). Tree edges
are highlighted in blue in the diagram above.
The ping test exercises all 20 directed pairs (5 nodes x 4 targets each),
covering both direct-peer and multi-hop paths.
| Link | Type |
|------|------|
| A — D | tree edge (D's parent is A) |
| A — E | tree edge (E's parent is A) |
| C — D | tree edge (C's parent is D) |
| B — C | tree edge (B's parent is C) |
| D — E | non-tree link |
| C — E | non-tree link |
## Chain Topology
![Chain Topology](docker-chain-topology.svg)
Five nodes in a linear chain: A — B — C — D — E. Each node peers only with
its immediate neighbors. Multi-hop communication (e.g., A to E) requires the
discovery protocol to find routes through intermediate nodes.
The ping test covers:
- Adjacent hops: A→B, B→C (1 hop each)
- Multi-hop: A→C (2 hops), A→D (3 hops), A→E (4 hops)
- Reverse: E→A (4 hops)
## Node Identities
All nodes use deterministic test keys (not for production use).
| Node | npub | FIPS IPv6 Address | Docker IP |
|------|------|-------------------|-----------|
| A | `npub1sjlh2c3...` | `fd69:e08d:65cc:3a6b:...` | 172.20.0.10 |
| B | `npub1tdwa4vj...` | `fd8e:302c:287e:b48d:...` | 172.20.0.11 |
| C | `npub1cld9yay...` | `fdac:a221:4069:5044:...` | 172.20.0.12 |
| D | `npub1n9lpnv0...` | `fdb6:8411:a191:6d48:...` | 172.20.0.13 |
| E | `npub1wf8akf8...` | `fded:7dee:d386:a546:...` | 172.20.0.14 |
## Container Configuration
- **Base image**: debian:bookworm-slim
- **Capabilities**: `CAP_NET_ADMIN` (for TUN device creation)
- **Devices**: `/dev/net/tun` mapped into each container
- **DNS**: FIPS built-in resolver on `127.0.0.1:53`
- **Transport**: UDP on port 4000, MTU 1280
- **TUN**: `fips0` interface, MTU 1280
Each node resolves `<npub>.fips` DNS names to FIPS IPv6 addresses via its
local DNS responder, which primes the identity cache for session establishment.
## Troubleshooting
**Stale images after code changes**: Docker compose may cache old layers.
Force a clean rebuild:
```bash
docker compose --profile mesh build --no-cache
```
**Check node logs**:
```bash
docker logs fips-node-a
docker logs -f fips-node-c # follow
```
**Verify DNS resolution inside a container**:
```bash
docker exec fips-node-a dig AAAA npub1tdwa4vjrjl33pcjdpf2t4p027nl86xrx24g4d3avg4vwvayr3g8qhd84le.fips @127.0.0.1
```
**Verify binary is up to date**: Compare hashes between the local build and
the binary inside the container:
```bash
md5sum examples/docker-network/fips
docker exec fips-node-a md5sum /usr/local/bin/fips
```
**Increase convergence time**: If tests fail intermittently, the 5-second
convergence wait in `ping-test.sh` may be insufficient. Edit the `sleep`
value at the top of the script.
@@ -0,0 +1,31 @@
# FIPS Node A configuration (chain topology: A-B-C-D-E)
#
# Identity: npub1sjlh2c3x9w7kjsqg2ay080n2lff2uvt325vpan33ke34rn8l5jcqawh57m
# FIPS address: fd69:e08d:65cc:3a6b:9c2c:2ac4:bd40:5e4b
node:
identity:
nsec: "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"
tun:
enabled: true
name: fips0
mtu: 1280
dns:
enabled: true
bind_addr: "127.0.0.1"
port: 53
transports:
udp:
bind_addr: "0.0.0.0:4000"
mtu: 1280
peers:
- npub: "npub1tdwa4vjrjl33pcjdpf2t4p027nl86xrx24g4d3avg4vwvayr3g8qhd84le"
alias: "node-b"
addresses:
- transport: udp
addr: "172.20.0.11:4000"
connect_policy: auto_connect
@@ -0,0 +1,37 @@
# FIPS Node B configuration (chain topology: A-B-C-D-E)
#
# Identity: npub1tdwa4vjrjl33pcjdpf2t4p027nl86xrx24g4d3avg4vwvayr3g8qhd84le
# FIPS address: fd8e:302c:287e:b48d:6268:122f:da76:b77
node:
identity:
nsec: "b102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fb0"
tun:
enabled: true
name: fips0
mtu: 1280
dns:
enabled: true
bind_addr: "127.0.0.1"
port: 53
transports:
udp:
bind_addr: "0.0.0.0:4000"
mtu: 1280
peers:
- npub: "npub1sjlh2c3x9w7kjsqg2ay080n2lff2uvt325vpan33ke34rn8l5jcqawh57m"
alias: "node-a"
addresses:
- transport: udp
addr: "172.20.0.10:4000"
connect_policy: auto_connect
- npub: "npub1cld9yay0u24davpu6c35l4vldrhzvaq66pcqtg9a0j2cnjrn9rtsxx2pe6"
alias: "node-c"
addresses:
- transport: udp
addr: "172.20.0.12:4000"
connect_policy: auto_connect
@@ -0,0 +1,37 @@
# FIPS Node C configuration (chain topology: A-B-C-D-E)
#
# Identity: npub1cld9yay0u24davpu6c35l4vldrhzvaq66pcqtg9a0j2cnjrn9rtsxx2pe6
# FIPS address: fdac:a221:4069:5044:c41:d550:280e:d15a
node:
identity:
nsec: "c102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fc0"
tun:
enabled: true
name: fips0
mtu: 1280
dns:
enabled: true
bind_addr: "127.0.0.1"
port: 53
transports:
udp:
bind_addr: "0.0.0.0:4000"
mtu: 1280
peers:
- npub: "npub1tdwa4vjrjl33pcjdpf2t4p027nl86xrx24g4d3avg4vwvayr3g8qhd84le"
alias: "node-b"
addresses:
- transport: udp
addr: "172.20.0.11:4000"
connect_policy: auto_connect
- npub: "npub1n9lpnv0592cc2ps6nm0ca3qls642vx7yjsv35rkxqzj2vgds52sqgpverl"
alias: "node-d"
addresses:
- transport: udp
addr: "172.20.0.13:4000"
connect_policy: auto_connect
@@ -0,0 +1,37 @@
# FIPS Node D configuration (chain topology: A-B-C-D-E)
#
# Identity: npub1n9lpnv0592cc2ps6nm0ca3qls642vx7yjsv35rkxqzj2vgds52sqgpverl
# FIPS address: fdb6:8411:a191:6d48:efc6:b8bd:63bb:1cd7
node:
identity:
nsec: "d102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fd0"
tun:
enabled: true
name: fips0
mtu: 1280
dns:
enabled: true
bind_addr: "127.0.0.1"
port: 53
transports:
udp:
bind_addr: "0.0.0.0:4000"
mtu: 1280
peers:
- npub: "npub1cld9yay0u24davpu6c35l4vldrhzvaq66pcqtg9a0j2cnjrn9rtsxx2pe6"
alias: "node-c"
addresses:
- transport: udp
addr: "172.20.0.12:4000"
connect_policy: auto_connect
- npub: "npub1wf8akf8lu2zdkjkmwhl75pqvven654mpv4sz2x2tprl5265mgrzq8nhak4"
alias: "node-e"
addresses:
- transport: udp
addr: "172.20.0.14:4000"
connect_policy: auto_connect
@@ -0,0 +1,31 @@
# FIPS Node E configuration (chain topology: A-B-C-D-E)
#
# Identity: npub1wf8akf8lu2zdkjkmwhl75pqvven654mpv4sz2x2tprl5265mgrzq8nhak4
# FIPS address: fded:7dee:d386:a546:2a43:5103:16d8:4f3c
node:
identity:
nsec: "e102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fe0"
tun:
enabled: true
name: fips0
mtu: 1280
dns:
enabled: true
bind_addr: "127.0.0.1"
port: 53
transports:
udp:
bind_addr: "0.0.0.0:4000"
mtu: 1280
peers:
- npub: "npub1n9lpnv0592cc2ps6nm0ca3qls642vx7yjsv35rkxqzj2vgds52sqgpverl"
alias: "node-d"
addresses:
- transport: udp
addr: "172.20.0.13:4000"
connect_policy: auto_connect
@@ -0,0 +1,37 @@
# FIPS Node A configuration (mesh topology)
#
# Identity: npub1sjlh2c3x9w7kjsqg2ay080n2lff2uvt325vpan33ke34rn8l5jcqawh57m
# FIPS address: fd69:e08d:65cc:3a6b:9c2c:2ac4:bd40:5e4b
node:
identity:
nsec: "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"
tun:
enabled: true
name: fips0
mtu: 1280
dns:
enabled: true
bind_addr: "127.0.0.1"
port: 53
transports:
udp:
bind_addr: "0.0.0.0:4000"
mtu: 1280
peers:
- npub: "npub1n9lpnv0592cc2ps6nm0ca3qls642vx7yjsv35rkxqzj2vgds52sqgpverl"
alias: "node-d"
addresses:
- transport: udp
addr: "172.20.0.13:4000"
connect_policy: auto_connect
- npub: "npub1wf8akf8lu2zdkjkmwhl75pqvven654mpv4sz2x2tprl5265mgrzq8nhak4"
alias: "node-e"
addresses:
- transport: udp
addr: "172.20.0.14:4000"
connect_policy: auto_connect
@@ -0,0 +1,31 @@
# FIPS Node B configuration (mesh topology)
#
# Identity: npub1tdwa4vjrjl33pcjdpf2t4p027nl86xrx24g4d3avg4vwvayr3g8qhd84le
# FIPS address: fd8e:302c:287e:b48d:6268:122f:da76:b77
node:
identity:
nsec: "b102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fb0"
tun:
enabled: true
name: fips0
mtu: 1280
dns:
enabled: true
bind_addr: "127.0.0.1"
port: 53
transports:
udp:
bind_addr: "0.0.0.0:4000"
mtu: 1280
peers:
- npub: "npub1cld9yay0u24davpu6c35l4vldrhzvaq66pcqtg9a0j2cnjrn9rtsxx2pe6"
alias: "node-c"
addresses:
- transport: udp
addr: "172.20.0.12:4000"
connect_policy: auto_connect
@@ -0,0 +1,43 @@
# FIPS Node C configuration (mesh topology)
#
# Identity: npub1cld9yay0u24davpu6c35l4vldrhzvaq66pcqtg9a0j2cnjrn9rtsxx2pe6
# FIPS address: fdac:a221:4069:5044:c41:d550:280e:d15a
node:
identity:
nsec: "c102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fc0"
tun:
enabled: true
name: fips0
mtu: 1280
dns:
enabled: true
bind_addr: "127.0.0.1"
port: 53
transports:
udp:
bind_addr: "0.0.0.0:4000"
mtu: 1280
peers:
- npub: "npub1tdwa4vjrjl33pcjdpf2t4p027nl86xrx24g4d3avg4vwvayr3g8qhd84le"
alias: "node-b"
addresses:
- transport: udp
addr: "172.20.0.11:4000"
connect_policy: auto_connect
- npub: "npub1n9lpnv0592cc2ps6nm0ca3qls642vx7yjsv35rkxqzj2vgds52sqgpverl"
alias: "node-d"
addresses:
- transport: udp
addr: "172.20.0.13:4000"
connect_policy: auto_connect
- npub: "npub1wf8akf8lu2zdkjkmwhl75pqvven654mpv4sz2x2tprl5265mgrzq8nhak4"
alias: "node-e"
addresses:
- transport: udp
addr: "172.20.0.14:4000"
connect_policy: auto_connect
@@ -0,0 +1,43 @@
# FIPS Node D configuration (mesh topology)
#
# Identity: npub1n9lpnv0592cc2ps6nm0ca3qls642vx7yjsv35rkxqzj2vgds52sqgpverl
# FIPS address: fdb6:8411:a191:6d48:efc6:b8bd:63bb:1cd7
node:
identity:
nsec: "d102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fd0"
tun:
enabled: true
name: fips0
mtu: 1280
dns:
enabled: true
bind_addr: "127.0.0.1"
port: 53
transports:
udp:
bind_addr: "0.0.0.0:4000"
mtu: 1280
peers:
- npub: "npub1sjlh2c3x9w7kjsqg2ay080n2lff2uvt325vpan33ke34rn8l5jcqawh57m"
alias: "node-a"
addresses:
- transport: udp
addr: "172.20.0.10:4000"
connect_policy: auto_connect
- npub: "npub1cld9yay0u24davpu6c35l4vldrhzvaq66pcqtg9a0j2cnjrn9rtsxx2pe6"
alias: "node-c"
addresses:
- transport: udp
addr: "172.20.0.12:4000"
connect_policy: auto_connect
- npub: "npub1wf8akf8lu2zdkjkmwhl75pqvven654mpv4sz2x2tprl5265mgrzq8nhak4"
alias: "node-e"
addresses:
- transport: udp
addr: "172.20.0.14:4000"
connect_policy: auto_connect
@@ -0,0 +1,43 @@
# FIPS Node E configuration (mesh topology)
#
# Identity: npub1wf8akf8lu2zdkjkmwhl75pqvven654mpv4sz2x2tprl5265mgrzq8nhak4
# FIPS address: fded:7dee:d386:a546:2a43:5103:16d8:4f3c
node:
identity:
nsec: "e102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fe0"
tun:
enabled: true
name: fips0
mtu: 1280
dns:
enabled: true
bind_addr: "127.0.0.1"
port: 53
transports:
udp:
bind_addr: "0.0.0.0:4000"
mtu: 1280
peers:
- npub: "npub1sjlh2c3x9w7kjsqg2ay080n2lff2uvt325vpan33ke34rn8l5jcqawh57m"
alias: "node-a"
addresses:
- transport: udp
addr: "172.20.0.10:4000"
connect_policy: auto_connect
- npub: "npub1cld9yay0u24davpu6c35l4vldrhzvaq66pcqtg9a0j2cnjrn9rtsxx2pe6"
alias: "node-c"
addresses:
- transport: udp
addr: "172.20.0.12:4000"
connect_policy: auto_connect
- npub: "npub1n9lpnv0592cc2ps6nm0ca3qls642vx7yjsv35rkxqzj2vgds52sqgpverl"
alias: "node-d"
addresses:
- transport: udp
addr: "172.20.0.13:4000"
connect_policy: auto_connect
@@ -0,0 +1,113 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 700 400" font-family="monospace" font-size="13">
<style>
circle.node { fill: #1a1a2e; stroke: #e0e0e0; stroke-width: 2; }
text { fill: #e0e0e0; }
text.name { font-size: 14px; font-weight: bold; }
text.ip { font-size: 10px; fill: #808890; }
text.fips-addr { font-size: 9px; fill: #607090; }
text.title { font-size: 16px; font-weight: bold; }
text.subtitle { font-size: 11px; fill: #909090; }
text.legend { font-size: 11px; }
text.net-label { font-size: 10px; fill: #606880; }
text.hop-label { font-size: 10px; fill: #909090; }
line.link { stroke: #506090; stroke-width: 2; }
line.path { stroke: #d0a040; stroke-width: 1.2; stroke-dasharray: 5 3; }
rect.legend-box { fill: #151520; stroke: #404060; stroke-width: 1; rx: 4; }
rect.net-box { fill: none; stroke: #303050; stroke-width: 1; stroke-dasharray: 6 3; rx: 8; }
marker { fill: #d0a040; }
</style>
<defs>
<marker id="arrow" viewBox="0 0 10 6" refX="10" refY="3"
markerWidth="8" markerHeight="5" orient="auto-start-reverse">
<path d="M 0 0 L 10 3 L 0 6 z"/>
</marker>
</defs>
<!-- Background -->
<rect width="700" height="400" fill="#0d1117" rx="8"/>
<!-- Title -->
<text x="350" y="30" text-anchor="middle" class="title">Docker Chain Topology</text>
<text x="350" y="48" text-anchor="middle" class="subtitle">Linear chain — ABCDE, multi-hop routing via discovery</text>
<!-- Docker network boundary -->
<rect x="30" y="65" width="640" height="175" class="net-box"/>
<text x="40" y="82" class="net-label">172.20.0.0/24 (docker: fips-net)</text>
<!--
Horizontal chain layout:
A (110, 170) B (230, 170) C (350, 170) D (470, 170) E (590, 170)
-->
<!-- === Links === -->
<!-- A—B -->
<line x1="138" y1="170" x2="202" y2="170" class="link"/>
<text x="170" y="160" text-anchor="middle" class="hop-label">UDP</text>
<!-- B—C -->
<line x1="258" y1="170" x2="322" y2="170" class="link"/>
<text x="290" y="160" text-anchor="middle" class="hop-label">UDP</text>
<!-- C—D -->
<line x1="378" y1="170" x2="442" y2="170" class="link"/>
<text x="410" y="160" text-anchor="middle" class="hop-label">UDP</text>
<!-- D—E -->
<line x1="498" y1="170" x2="562" y2="170" class="link"/>
<text x="530" y="160" text-anchor="middle" class="hop-label">UDP</text>
<!-- === Multi-hop path illustration (A→E, 4 hops) === -->
<line x1="110" y1="210" x2="590" y2="210" class="path"
marker-end="url(#arrow)"/>
<text x="350" y="228" text-anchor="middle" class="hop-label">
A → E (4 hops, discovery-routed)
</text>
<!-- === Nodes === -->
<!-- Node A -->
<circle cx="110" cy="170" r="28" class="node"/>
<text x="110" y="166" text-anchor="middle" class="name">A</text>
<text x="110" y="179" text-anchor="middle" class="ip">.10</text>
<text x="110" y="130" text-anchor="middle" class="fips-addr">fd69:e08d:...</text>
<!-- Node B -->
<circle cx="230" cy="170" r="28" class="node"/>
<text x="230" y="166" text-anchor="middle" class="name">B</text>
<text x="230" y="179" text-anchor="middle" class="ip">.11</text>
<text x="230" y="130" text-anchor="middle" class="fips-addr">fd8e:302c:...</text>
<!-- Node C -->
<circle cx="350" cy="170" r="28" class="node"/>
<text x="350" y="166" text-anchor="middle" class="name">C</text>
<text x="350" y="179" text-anchor="middle" class="ip">.12</text>
<text x="350" y="130" text-anchor="middle" class="fips-addr">fdac:a221:...</text>
<!-- Node D -->
<circle cx="470" cy="170" r="28" class="node"/>
<text x="470" y="166" text-anchor="middle" class="name">D</text>
<text x="470" y="179" text-anchor="middle" class="ip">.13</text>
<text x="470" y="130" text-anchor="middle" class="fips-addr">fdb6:8411:...</text>
<!-- Node E -->
<circle cx="590" cy="170" r="28" class="node"/>
<text x="590" y="166" text-anchor="middle" class="name">E</text>
<text x="590" y="179" text-anchor="middle" class="ip">.14</text>
<text x="590" y="130" text-anchor="middle" class="fips-addr">fded:7dee:...</text>
<!-- === Legend === -->
<rect x="30" y="260" width="640" height="120" class="legend-box"/>
<line x1="50" y1="282" x2="90" y2="282" stroke="#506090" stroke-width="2"/>
<text x="100" y="286" class="legend">Direct UDP peer link (port 4000, auto_connect)</text>
<line x1="50" y1="304" x2="90" y2="304" stroke="#d0a040" stroke-width="1.2"
stroke-dasharray="5 3" marker-end="url(#arrow)"/>
<text x="100" y="308" class="legend">Multi-hop path (discovery + session establishment)</text>
<text x="50" y="332" class="legend" fill="#808890">Routing flow: TUN packet → identity cache → initiate_session()</text>
<text x="50" y="347" class="legend" fill="#808890"> → find_next_hop() fails → discovery flood → route_cache populated</text>
<text x="50" y="362" class="legend" fill="#808890"> → session retry → Noise IK handshake → encrypted data delivery</text>
</svg>

After

Width:  |  Height:  |  Size: 4.9 KiB

+142
View File
@@ -0,0 +1,142 @@
networks:
fips-net:
driver: bridge
ipam:
config:
- subnet: 172.20.0.0/24
x-fips-common: &fips-common
build:
context: .
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun:/dev/net/tun
sysctls:
- net.ipv6.conf.all.disable_ipv6=0
restart: "no"
environment:
- RUST_LOG=info
services:
# ── Mesh topology ──────────────────────────────────────────────
node-a:
<<: *fips-common
profiles: ["mesh"]
container_name: fips-node-a
hostname: node-a
volumes:
- ./resolv.conf:/etc/resolv.conf:ro
- ./configs/mesh/node-a.yaml:/etc/fips/fips.yaml:ro
networks:
fips-net:
ipv4_address: 172.20.0.10
node-b:
<<: *fips-common
profiles: ["mesh"]
container_name: fips-node-b
hostname: node-b
volumes:
- ./resolv.conf:/etc/resolv.conf:ro
- ./configs/mesh/node-b.yaml:/etc/fips/fips.yaml:ro
networks:
fips-net:
ipv4_address: 172.20.0.11
node-c:
<<: *fips-common
profiles: ["mesh"]
container_name: fips-node-c
hostname: node-c
volumes:
- ./resolv.conf:/etc/resolv.conf:ro
- ./configs/mesh/node-c.yaml:/etc/fips/fips.yaml:ro
networks:
fips-net:
ipv4_address: 172.20.0.12
node-d:
<<: *fips-common
profiles: ["mesh"]
container_name: fips-node-d
hostname: node-d
volumes:
- ./resolv.conf:/etc/resolv.conf:ro
- ./configs/mesh/node-d.yaml:/etc/fips/fips.yaml:ro
networks:
fips-net:
ipv4_address: 172.20.0.13
node-e:
<<: *fips-common
profiles: ["mesh"]
container_name: fips-node-e
hostname: node-e
volumes:
- ./resolv.conf:/etc/resolv.conf:ro
- ./configs/mesh/node-e.yaml:/etc/fips/fips.yaml:ro
networks:
fips-net:
ipv4_address: 172.20.0.14
# ── Chain topology (A-B-C-D-E) ────────────────────────────────
chain-a:
<<: *fips-common
profiles: ["chain"]
container_name: fips-node-a
hostname: node-a
volumes:
- ./resolv.conf:/etc/resolv.conf:ro
- ./configs/chain/node-a.yaml:/etc/fips/fips.yaml:ro
networks:
fips-net:
ipv4_address: 172.20.0.10
chain-b:
<<: *fips-common
profiles: ["chain"]
container_name: fips-node-b
hostname: node-b
volumes:
- ./resolv.conf:/etc/resolv.conf:ro
- ./configs/chain/node-b.yaml:/etc/fips/fips.yaml:ro
networks:
fips-net:
ipv4_address: 172.20.0.11
chain-c:
<<: *fips-common
profiles: ["chain"]
container_name: fips-node-c
hostname: node-c
volumes:
- ./resolv.conf:/etc/resolv.conf:ro
- ./configs/chain/node-c.yaml:/etc/fips/fips.yaml:ro
networks:
fips-net:
ipv4_address: 172.20.0.12
chain-d:
<<: *fips-common
profiles: ["chain"]
container_name: fips-node-d
hostname: node-d
volumes:
- ./resolv.conf:/etc/resolv.conf:ro
- ./configs/chain/node-d.yaml:/etc/fips/fips.yaml:ro
networks:
fips-net:
ipv4_address: 172.20.0.13
chain-e:
<<: *fips-common
profiles: ["chain"]
container_name: fips-node-e
hostname: node-e
volumes:
- ./resolv.conf:/etc/resolv.conf:ro
- ./configs/chain/node-e.yaml:/etc/fips/fips.yaml:ro
networks:
fips-net:
ipv4_address: 172.20.0.14
@@ -0,0 +1,130 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 700 560" font-family="monospace" font-size="13">
<style>
circle.node { fill: #1a1a2e; stroke: #e0e0e0; stroke-width: 2; }
circle.root { fill: #1a1a2e; stroke: #60a0e0; stroke-width: 2.5; }
text { fill: #e0e0e0; }
text.name { font-size: 14px; font-weight: bold; }
text.root-label { font-size: 9px; fill: #60a0e0; }
text.npub { font-size: 9px; fill: #808890; }
text.title { font-size: 16px; font-weight: bold; }
text.subtitle { font-size: 11px; fill: #909090; }
text.legend { font-size: 11px; }
text.net-label { font-size: 10px; fill: #606880; }
text.test-label { font-size: 10px; fill: #909090; }
line.link { stroke: #404860; stroke-width: 1.5; }
line.link-tree { stroke: #60a0e0; stroke-width: 2; }
rect.legend-box { fill: #151520; stroke: #404060; stroke-width: 1; rx: 4; }
rect.net-box { fill: none; stroke: #303050; stroke-width: 1;
stroke-dasharray: 6 3; rx: 8; }
</style>
<defs>
<marker id="tree-arrow" viewBox="0 0 10 6" refX="38" refY="3"
markerWidth="10" markerHeight="7" orient="auto-start-reverse"
markerUnits="userSpaceOnUse">
<path d="M 0 0 L 10 3 L 0 6 z" fill="#60a0e0"/>
</marker>
</defs>
<!-- Background -->
<rect width="700" height="560" fill="#0d1117" rx="8"/>
<!-- Title -->
<text x="350" y="30" text-anchor="middle" class="title">Docker Mesh Topology</text>
<text x="350" y="48" text-anchor="middle" class="subtitle">Sparse mesh — 5 nodes, 6 bidirectional UDP links</text>
<!-- Docker network boundary -->
<rect x="40" y="62" width="620" height="310" class="net-box"/>
<text x="52" y="78" class="net-label">172.20.0.0/24 (docker: fips-net)</text>
<!--
Pentagon layout (centered at 350,225):
A = top (350, 110)
B = upper-right (550, 195)
C = lower-right (480, 335)
D = lower-left (220, 335)
E = upper-left (150, 195)
Links: B-C, C-D, D-E, E-A, A-D, C-E
Spanning tree (root=A, lowest NodeAddr):
A → D, A → E
D → C
C → B
Tree edges highlighted; non-tree edges dim.
-->
<!-- === Peer links (6 edges) === -->
<!-- Non-tree edges (dim) -->
<!-- D — E -->
<line x1="220" y1="335" x2="150" y2="195" class="link"/>
<!-- C — E -->
<line x1="480" y1="335" x2="150" y2="195" class="link"/>
<!-- Tree edges (highlighted, arrow toward parent/root) -->
<!-- B → C (parent) -->
<line x1="550" y1="195" x2="480" y2="335" class="link-tree"
marker-end="url(#tree-arrow)"/>
<!-- C → D (parent) -->
<line x1="480" y1="335" x2="220" y2="335" class="link-tree"
marker-end="url(#tree-arrow)"/>
<!-- E → A (parent) -->
<line x1="150" y1="195" x2="350" y2="110" class="link-tree"
marker-end="url(#tree-arrow)"/>
<!-- D → A (parent) -->
<line x1="220" y1="335" x2="350" y2="110" class="link-tree"
marker-end="url(#tree-arrow)"/>
<!-- === Nodes (on top of links) === -->
<!-- Node A — root (2 peers: D, E) -->
<circle cx="350" cy="110" r="26" class="root"/>
<text x="350" y="108" text-anchor="middle" class="name">A</text>
<text x="350" y="121" text-anchor="middle" class="npub">.10</text>
<text x="350" y="75" text-anchor="middle" class="npub">npub1sjlh2c3...</text>
<text x="350" y="148" text-anchor="middle" class="root-label">root</text>
<!-- Node B (1 peer: C) -->
<circle cx="550" cy="195" r="26" class="node"/>
<text x="550" y="193" text-anchor="middle" class="name">B</text>
<text x="550" y="206" text-anchor="middle" class="npub">.11</text>
<text x="550" y="162" text-anchor="middle" class="npub">npub1tdwa4vj...</text>
<!-- Node C (3 peers: B, D, E) -->
<circle cx="480" cy="335" r="26" class="node"/>
<text x="480" y="333" text-anchor="middle" class="name">C</text>
<text x="480" y="346" text-anchor="middle" class="npub">.12</text>
<text x="516" y="357" text-anchor="start" class="npub">npub1cld9yay...</text>
<!-- Node D (3 peers: A, C, E) -->
<circle cx="220" cy="335" r="26" class="node"/>
<text x="220" y="333" text-anchor="middle" class="name">D</text>
<text x="220" y="346" text-anchor="middle" class="npub">.13</text>
<text x="112" y="357" text-anchor="start" class="npub">npub1n9lpnv0...</text>
<!-- Node E (3 peers: A, C, D) -->
<circle cx="150" cy="195" r="26" class="node"/>
<text x="150" y="193" text-anchor="middle" class="name">E</text>
<text x="150" y="206" text-anchor="middle" class="npub">.14</text>
<text x="150" y="162" text-anchor="middle" class="npub">npub1wf8akf8...</text>
<!-- Test info -->
<text x="350" y="390" text-anchor="middle" class="test-label">
All-pairs ping test: 20 directed paths (direct + multi-hop via discovery)
</text>
<!-- === Legend === -->
<rect x="40" y="410" width="620" height="130" class="legend-box"/>
<line x1="60" y1="435" x2="100" y2="435" stroke="#404860" stroke-width="1.5"/>
<text x="110" y="439" class="legend">UDP peer link (port 4000, auto_connect)</text>
<line x1="55" y1="457" x2="100" y2="457" stroke="#60a0e0" stroke-width="2"/>
<path d="M 90 454 L 100 457 L 90 460 z" fill="#60a0e0"/>
<text x="110" y="461" class="legend">Spanning tree edge (arrow toward parent/root)</text>
<circle cx="72" cy="479" r="8" fill="#1a1a2e" stroke="#60a0e0" stroke-width="2"/>
<text x="110" y="483" class="legend">Tree root (lowest NodeAddr = SHA-256(pubkey)[:16])</text>
<text x="60" y="525" class="legend" fill="#808890">Each container: CAP_NET_ADMIN, /dev/net/tun, DNS on 127.0.0.1:53</text>
</svg>

After

Width:  |  Height:  |  Size: 5.5 KiB

+1
View File
@@ -0,0 +1 @@
nameserver 127.0.0.1
+24
View File
@@ -0,0 +1,24 @@
#!/bin/bash
# Build the FIPS binary and copy it to the docker build context.
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
DOCKER_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
# Find project root (directory containing Cargo.toml)
PROJECT_ROOT="$(cd "$DOCKER_DIR/../.." && pwd)"
if [ ! -f "$PROJECT_ROOT/Cargo.toml" ]; then
echo "Error: Cannot find Cargo.toml at $PROJECT_ROOT" >&2
echo "Expected layout: <project-root>/examples/docker-network/scripts/build.sh" >&2
exit 1
fi
echo "Building FIPS (release)..."
cargo build --release --manifest-path="$PROJECT_ROOT/Cargo.toml"
echo "Copying binary to docker context..."
cp "$PROJECT_ROOT/target/release/fips" "$DOCKER_DIR/fips"
echo "Done. Binary at $DOCKER_DIR/fips"
echo ""
echo "Next: cd $DOCKER_DIR && docker compose --profile mesh build"
+102
View File
@@ -0,0 +1,102 @@
#!/bin/bash
# End-to-end ping test between FIPS nodes via DNS resolution.
# Usage: ./ping-test.sh [mesh|chain]
#
# Requires containers to be running:
# docker compose --profile mesh up -d
# ./scripts/ping-test.sh mesh
set -e
PROFILE="${1:-mesh}"
COUNT=3
TIMEOUT=10
PASSED=0
FAILED=0
# Node identities
NPUB_A="npub1sjlh2c3x9w7kjsqg2ay080n2lff2uvt325vpan33ke34rn8l5jcqawh57m"
NPUB_B="npub1tdwa4vjrjl33pcjdpf2t4p027nl86xrx24g4d3avg4vwvayr3g8qhd84le"
NPUB_C="npub1cld9yay0u24davpu6c35l4vldrhzvaq66pcqtg9a0j2cnjrn9rtsxx2pe6"
NPUB_D="npub1n9lpnv0592cc2ps6nm0ca3qls642vx7yjsv35rkxqzj2vgds52sqgpverl"
NPUB_E="npub1wf8akf8lu2zdkjkmwhl75pqvven654mpv4sz2x2tprl5265mgrzq8nhak4"
ping_test() {
local from="$1"
local to_npub="$2"
local label="$3"
echo -n " $label ... "
if docker exec "fips-$from" ping6 -c "$COUNT" -W "$TIMEOUT" "${to_npub}.fips" > /dev/null 2>&1; then
echo "OK"
PASSED=$((PASSED + 1))
else
echo "FAIL"
FAILED=$((FAILED + 1))
fi
}
echo "=== FIPS Ping Test ($PROFILE topology) ==="
echo ""
# Wait for nodes to converge
echo "Waiting 5s for mesh convergence..."
sleep 5
if [ "$PROFILE" = "mesh" ]; then
# Sparse mesh topology: A-B, B-C, C-D, D-E, E-A, A-D
# Test all 20 directed pairs (5 nodes × 4 targets each)
echo ""
echo "From node-a:"
ping_test node-a "$NPUB_B" "A → B"
ping_test node-a "$NPUB_C" "A → C"
ping_test node-a "$NPUB_D" "A → D"
ping_test node-a "$NPUB_E" "A → E"
echo ""
echo "From node-b:"
ping_test node-b "$NPUB_A" "B → A"
ping_test node-b "$NPUB_C" "B → C"
ping_test node-b "$NPUB_D" "B → D"
ping_test node-b "$NPUB_E" "B → E"
echo ""
echo "From node-c:"
ping_test node-c "$NPUB_A" "C → A"
ping_test node-c "$NPUB_B" "C → B"
ping_test node-c "$NPUB_D" "C → D"
ping_test node-c "$NPUB_E" "C → E"
echo ""
echo "From node-d:"
ping_test node-d "$NPUB_A" "D → A"
ping_test node-d "$NPUB_B" "D → B"
ping_test node-d "$NPUB_C" "D → C"
ping_test node-d "$NPUB_E" "D → E"
echo ""
echo "From node-e:"
ping_test node-e "$NPUB_A" "E → A"
ping_test node-e "$NPUB_B" "E → B"
ping_test node-e "$NPUB_C" "E → C"
ping_test node-e "$NPUB_D" "E → D"
elif [ "$PROFILE" = "chain" ]; then
echo ""
echo "Adjacent peer tests:"
ping_test node-a "$NPUB_B" "A → B (1 hop)"
ping_test node-b "$NPUB_C" "B → C (1 hop)"
echo ""
echo "Multi-hop tests:"
ping_test node-a "$NPUB_C" "A → C (2 hops)"
ping_test node-a "$NPUB_D" "A → D (3 hops)"
ping_test node-a "$NPUB_E" "A → E (4 hops)"
echo ""
echo "Reverse multi-hop:"
ping_test node-e "$NPUB_A" "E → A (4 hops)"
fi
echo ""
echo "=== Results: $PASSED passed, $FAILED failed ==="
[ "$FAILED" -eq 0 ] && exit 0 || exit 1