Skip to content
eyeoverthinkPublic

About

FMP/1 sovereign UDP/LoRa-profile mesh protocol (CBOR, Ed25519/X25519/ChaCha20-Poly1305, store-and-forward custody, dual-key INTENT gating, SVA-ER/1 receipt export)

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

FMP/1 mesh protocol prototype

A working Python 3 prototype of the FMP/1 UDP mesh protocol in mesh-protocol-spec.md, section 3. It uses only the standard library plus cryptography (Ed25519, X25519, ChaCha20-Poly1305, HKDF). It runs on a Raspberry Pi (Pi 4/5 or Zero 2 W, Python ≥ 3.9).

Status: prototype. Do not use it for life-safety messaging. The community notice channel is unofficial. Every rendering starts with the fixed banner "Community notice from — not an official emergency alert. For emergencies call 911." The code refuses official-alert branding (AMBER/EAS/WEA/IPAWS/Presidential/"official alert") and has no alert tones.

Layout

fmp1/
  packet.py    48-byte header (!BBBB8s8s8sIIBBH8s), Ed25519 / HMAC-128 auth, compact LoRa profile
  cbor.py      minimal RFC 8949 encoder/decoder (bounded depth, strict)
  identity.py  Ed25519 + X25519 keys, node_id = SHA-256(pub)[:8], signed key cards, E2E seal/open
  replay.py    64-entry seq window (IPsec-style), msg_id dedupe (30 min TTL), token buckets
  receipts.py  SHA-256 hash-chained receipt log + verify_log (pinpoints the tampered entry)
  store.py     SQLite (WAL): inbox, outbox states, held notices, custody queue, telemetry, intents
  roster.py    operator-root-signed trust roster (roles: sensor, relay, gateway, notice-publisher, commander, approver)
  notice.py    CAP 1.2 subset validation and rendering, mandatory banner, NWS relay rules
  node.py      asyncio node: HELLO/ETX, DSDV-style ANNOUNCE routing, DATA/ACK/SACK/NACK, RFC 6298 RTO,
               fragmentation, custody store-and-forward, Trickle flooding, DIGEST/REQUEST anti-entropy,
               priority scheduler, INTENT gating, RECEIPT checkpoints, localhost JSON control socket
  sim.py       localhost-only harness: N nodes on 127.0.0.1 with per-link loss, cuts, 10 scenarios
  cli.py       `fmp1` command
tests/         pytest (codec, security, CLI, 2 short simulations)
deploy/        fmp1.service (hardened systemd unit), fmp1.default

Quick start (on one machine, loopback only)

python3 -m venv venv && . venv/bin/activate
pip install -e .[test]          # or: pip install cryptography pytest, then use `python -m fmp1`
pytest -q                       # 46 tests, about 15 s
fmp1 sim                        # 6-node line, 5% loss per link, 10 scenarios
fmp1 sim --nodes 8 --topology ring --loss 0.1

Two real nodes talking over loopback with static peers:

fmp1 --data-dir /tmp/a keygen ; fmp1 --data-dir /tmp/b keygen      # prints node_id
fmp1 --data-dir /tmp/a --control-port 47201 node --port 47110 --peer 127.0.0.1:47111 &
fmp1 --data-dir /tmp/b --control-port 47202 node --port 47111 --peer 127.0.0.1:47110 &
sleep 25   # first HELLOs plus an ANNOUNCE (real timers: 10 s ± 2 s)
fmp1 --data-dir /tmp/a --control-port 47201 send <b_node_id> "hello" --wait
fmp1 --data-dir /tmp/b --control-port 47202 inbox
fmp1 --data-dir /tmp/a --control-port 47201 status
fmp1 verify-log /tmp/a/receipts.jsonl

CLI

command what it does
fmp1 keygen create or show the node identity (identity.key, mode 0600)
fmp1 roster create --root-key K --entry <edpub>:<roles>[:<name>] --out roster.cbor sign a trust roster (keep the root key offline)
fmp1 node [--lan] [--bind A] [--port 47100] [--peer h:p]… [--multicast] [--roster F --root-pub HEX] [--amateur] run a node
fmp1 send DST TEXT [--encrypt] [--wait] / status / telemetry DST SENSOR VALUE / notice FILE.json / inbox / intents talk to the local node over 127.0.0.1:--control-port, authenticated by <data-dir>/control.token (0600)
fmp1 verify-log PATH check a receipt chain
fmp1 export-sva PATH [--clock-trusted] [--out R.json] [--deliverable-out D.txt] export a verified receipts.jsonl chain as an SVA-ER/1 Ed25519 + RFC 6962 Merkle receipt
fmp1 sim [--nodes N] [--loss P] [--topology line|ring|ladder] [--seed S] localhost simulation

Binding is loopback by default. The node binds 127.0.0.1 unless you pass --lan. --lan binds 0.0.0.0 and joins multicast 239.255.71.1; add --no-multicast to use only --peer. A non-loopback --bind and --multicast both require --lan. The control socket is always 127.0.0.1 only. The tests and the simulator use 127.0.0.1 only.

Without a roster (--roster + --root-pub), NOTICE and INTENT are rejected. DATA, TELEMETRY and routing still work between nodes that learn each other's signed key cards from HELLO/ANNOUNCE.

Simulation scenarios (fmp1 sim)

  1. convergence: every node gets a route to every other node.
  2. multihop_reliable_with_loss: 20 ACKed messages across 5 hops with random loss.
  3. fragmented_5KB: a 5 KB message in 6 fragments, SACK/NACK repair, reassembly.
  4. e2e_encrypted: X25519/ChaCha20-Poly1305. The test asserts that the relays' receipt logs never contain the plaintext.
  5. notice_flood_with_banner: Trickle flood from the roster notice-publisher; checks the banner text.
  6. partition_store_and_forward: cut a link, the route is withdrawn, a relay or neighbor takes CUSTODY, heal, delivery, custody released.
  7. offline_catchup_digest: a late node joins and gets the notice through DIGEST (bloom) → REQUEST.
  8. security_rejections: replay, tampered payload, notice from a non-publisher key, "AMBER Alert" notice, stale HELLO, unknown key, and local EAS-branded publish.
  9. intent_gating: an unapproved INTENT is rejected. An approved one is recorded as approved_pending_operator and never executed.
  10. receipt_chain: every node's chain verifies; an edited entry is detected at its exact index.

Raspberry Pi setup

sudo apt update && sudo apt install -y python3-venv chrony      # chrony: Pi has no RTC by default (spec 3.7)
sudo useradd --system --home /var/lib/fmp1 --shell /usr/sbin/nologin fmp1
sudo mkdir -p /opt/fmp1 /var/lib/fmp1 && sudo chown fmp1:fmp1 /var/lib/fmp1 && sudo chmod 700 /var/lib/fmp1
sudo cp -r fmp1 pyproject.toml README.md /opt/fmp1/
sudo python3 -m venv /opt/fmp1/venv && sudo /opt/fmp1/venv/bin/pip install /opt/fmp1
sudo -u fmp1 /opt/fmp1/venv/bin/fmp1 --data-dir /var/lib/fmp1 keygen          # note ed25519_pub
# On an OFFLINE machine that holds the operator root key:
#   fmp1 roster create --root-key root.key --entry <pi_ed25519_pub>:relay,gateway:barn-pi --out roster.cbor
sudo install -o fmp1 -g fmp1 -m 600 roster.cbor /var/lib/fmp1/roster.cbor
sudo cp deploy/fmp1.default /etc/default/fmp1     # set FMP1_ROOT_PUB=<root public key hex>
sudo cp deploy/fmp1.service /etc/systemd/system/ && sudo systemctl daemon-reload
sudo systemctl enable --now fmp1 && journalctl -u fmp1 -f
sudo -u fmp1 /opt/fmp1/venv/bin/fmp1 --data-dir /var/lib/fmp1 status

The unit runs as the dedicated fmp1 user with NoNewPrivileges, ProtectSystem=strict, ReadWritePaths=/var/lib/fmp1, an empty capability set, MemoryMax=128M and RestrictAddressFamilies=AF_INET AF_UNIX. Port 47100 is unprivileged. The unit passes --lan on purpose; remove it to keep the node on loopback. Firewall UDP 47100 to your mesh interfaces only (for example batman-adv/wg0). For ham links add --amateur, which refuses encryption and drops E-flag packets (FCC §97.113(a)(4)).

Deviations from the spec (deliberate or forced)

  1. Signature coverage: the auth covers the header with hop_limit zeroed, so relays can decrement it without re-signing. As written, the spec's "bytes 0..48+N-1" would break at the first hop.
  2. Compact header is 19 bytes, not 20: the fields the spec lists add up to 19.
  3. Timestamp checks: storable/store-and-forward types (DATA, NOTICE, RECEIPT, CUSTODY) get an expiry/future check instead of the ±300 s skew, because otherwise custody delivery after a partition would always fail. DATA with an "old" seq (outside the 64-window) is accepted if its msg_id was never seen.
  4. NOTICE replay uses persistent msg_id dedupe until expiry (seq windows don't fit flooded traffic).
  5. Receipt hash = SHA-256(prev ‖ bytes ‖ "i|t|kind|verdict"). The verdict string includes the index and time.
  6. Routing (ANNOUNCE) is a per-neighbor DSDV-style distance vector with signed key cards. Origin seqs are even and time-based. A link break advertises seq+1 (odd) at infinity, which prevents count-to-infinity (verified in the sim). Selection prefers the freshest seq, then the lowest ETX cost. It uses poison reverse, sends triggered updates and keeps every neighbor's offer (not just "best two").
  7. ACK format: {s, k:[up to 15 recent seqs], m, all?} replaces "cumulative + 32-bit SACK + echo ts". Seqs are shared by every packet type on a (src, dst) flow, so a cumulative ACK isn't meaningful. RTT uses Karn's rule. all=true acks a whole completed message and is sent twice. Seqs survive restarts via reserved blocks of 1000.
  8. Custody: an origin with no route offers custody to its best neighbor right away, and a relay with no route takes custody of A-flag DATA. The spec only says "after retries are exhausted". The source shows IN_CUSTODY (the spec's STORED). Custodians release on a "delivered" note or on seeing the ACK, and drop as unconfirmed after 20 attempts.
  9. Retries count attempts without progress. A multi-fragment message whose fragments are being ACKed doesn't fail at 5 total attempts.
  10. Fragments carry 900-byte payloads, so a fragment fits inside a CUSTODY offer within the 1200-byte MTU.
  11. Encryption: static X25519 → HKDF → ChaCha20-Poly1305 with AAD = src‖dst‖msg_id‖(idx,cnt). There is no forward secrecy.
  12. IPv4 only: no ff02::1 IPv6 multicast. One interface per process. No interface weights. No group dst ids.
  13. Scheduler: strict priority for classes 0/1, weighted 3:2:1 round-robin for classes 2–4. The 20% notice reservation and 10% control cap are not enforced. BULK is refused on links ≤1 Mb/s (--link-rate).
  14. Roster is distributed and checkpoints are gossiped as flooded RECEIPT packets (op: roster|ckpt).
  15. INTENT is reliable (A flag, 5 retries), needs a commander key plus a countersignature from an approver key, and expires after 300 s. It is only recorded, never executed. NOTICE_ACK is defined but never sent. TELEMETRY is unreliable and latest-wins (an HMAC cluster key is allowed only for TELEMETRY).
  16. Notice rules beyond the spec: the sender must equal the publisher's roster name, a forbidden-terms filter applies, NWS relays need an https://api.weather.gov/ source_url, and lifetime is at most 7 days.
  17. Own CBOR codec instead of cbor2 (stdlib-only constraint); cryptography instead of PyNaCl.
  18. Forwarder dedupe is time-gated (0.5 × rto_min) so an origin's retransmits are forwarded again.
  19. Origin outstanding messages are not resumed after a restart. Custody items are persisted and resumed.

Not implemented / limits

  • No LoRa/Reticulum/Meshtastic bridge (the compact codec exists but nothing carries it), no live NWS fetch, no Fly mirroring of checkpoints, no batman-adv setup, no LoRa RTO profile.
  • Untrusted clocks are only partly handled. The clock_trusted flag exists; checks fall back to seq/dedupe for storable types only.
  • Under heavy loss, end-to-end reliability is bounded by the spec's 5 retries. At 10% loss per link per direction over 5 hops, one round trip succeeds about 35% of the time, so a single message occasionally ends FAILED. The default sim uses 5%; see the results below.
  • Python-level throughput only (hundreds of packets/s). No congestion control beyond RTO backoff and per-source token buckets.
  • Not security-audited. Key cards are trust-on-first-use unless a roster is loaded.

Test & simulation results (2026-10-30, box: Python 3 + cryptography 50.0.2)

  • pytest -q: 46 passed (~15 s), all sockets bound to 127.0.0.1.
  • fmp1 sim (default: 6-node line, 5% loss): all 10 scenarios PASS, ~10-14 s. 5-hop reliable: 20/20 delivered with ~10 retransmits; 5 KB message in 6 fragments delivered; partition → custody at node 1 → delivered after heal; receipt-chain tamper detected.
  • Extra topologies at 5% loss: ring-8 PASS, ladder-7 PASS, ladder-8 PASS; line-6 seeds 1,2,3,7,31-33 PASS.
  • Stress at 10% loss, line-6, seeds 21-25: 5/5 PASS (11-22 s). Earlier, before the progress-aware retry fix, a 10% run lost a single message after 5 retries across 5 hops. At this loss rate that can still happen, because retries are capped (see Limits).

Exporting SVA-ER/1 Receipts (Interoperable with @eyeoverthink/ai-receipt)

Because Raspberry Pi and off-grid mesh nodes frequently run without a battery-backed RTC, fmp1 export-sva defaults to clock.status = "unattested" (pass --clock-trusted when chrony/NTP is verified). The exported receipt can be verified offline in Node.js, Browser WebCrypto, or Java:

fmp1 --data-dir /var/lib/fmp1 export-sva /var/lib/fmp1/receipts.jsonl --out mesh-receipt.json --deliverable-out mesh-checkpoint.json
npx @eyeoverthink/ai-receipt verify mesh-receipt.json mesh-checkpoint.json

License

Apache-2.0 — see LICENSE.

About

FMP/1 sovereign UDP/LoRa-profile mesh protocol (CBOR, Ed25519/X25519/ChaCha20-Poly1305, store-and-forward custody, dual-key INTENT gating, SVA-ER/1 receipt export)

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages