Every node now serves a search and listing-detail UI at GET /. It is vanilla TypeScript, bundled unminified into web/dist (committed) and embedded with go:embed, so `go build` is enough to run a node. The browser verifies each listing itself (certificate, binding, validity, signature, proof-of-work) with pure-JS ed25519, so a gateway can withhold listings but not forge them. Unverifiable results are hidden and their content is never shown. Listing text is only inserted via textContent and the UI is served with a strict CSP. Canonical JSON is reimplemented in TypeScript and tested against a golden fixture signed by the Go code. /api/v1/status now reports difficulty. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
10 KiB
Protocol (draft v1)
A distributed, free marketplace for buying/selling and renting. Listing requires running a node; searching is browser-only through any node's HTTP gateway.
Architecture
- Nodes (Go, single binary): libp2p between nodes, HTTP gateway + web UI + search API on every node.
- Browsers never join the P2P network. They fetch from any gateway and verify signatures themselves, so a gateway cannot forge listings.
- Sharding: a listing carries a precision-6
geohash(~1 km) and is gossiped on the topic of its precision-3 region (~150 km cell),/allmende/1/listings/<region>. Nodes subscribe to the regions they care about, replicate them, and index them locally. Fine-grained filtering (precision, kind, category, price) happens in local search. - Discovery: configured bootstrap peers plus mDNS on the local network; gossipsub peer exchange spreads the mesh. A Kademlia DHT can be added later without protocol changes.
- License: AGPL-3.0, so modified nodes and gateways must publish their source.
- Launch scope: one German state or metro area.
Identity and keys
Designed so non-technical people can use it and a compromised node can be revoked. There are no accounts.
- Identity key (ed25519): derived from a 12-word recovery phrase shown
once at first run. Its public key is the
author. It signs certificates and revocations only, and is deleted from the machine right after enrolling the first device. - Device key (ed25519): generated per node, stored on that node. It signs
listings and is also the node's libp2p identity, so the node's peer ID derives
from the
devicefield. There is no separateendpointfield. - Certificate:
{v, author, device, issued_at, expires_at (<= 1 year), sig}signed by the identity key. Travels inside every listing. - Revocation:
{v, author, device, revoked_at, cert_expires_at, pow, sig}signed by the identity key, gossiped on/allmende/1/revocations(all nodes subscribe), kept untilcert_expires_at. A revoked device's signatures are void: its listings are purged and refused. Two forms:- one device (
deviceset): voids exactly that device; - all devices (
deviceempty): voids every device of the author whose certificate was issued beforerevoked_at. This is what recovery uses, because on a new machine the owner has only the phrase and does not know the old device's key. The replacement device is enrolled at the same instant (issued_at == revoked_at), which stays valid.
- one device (
- Recovery (
node recover): phrase in, all-devices revocation out, fresh device enrolled, the node's own listings re-signed (seq + 1) from the new device. The same command renews the yearly certificate. - Peer IDs change on recovery because the device key is the libp2p identity. Anyone who listed the old peer ID as a bootstrap address has a stale entry; the recovered node dials out to its own bootstrap peers.
- Lost phrase and lost device: start a new identity. Cheap, because listings expire within 30 days anyway.
- Signed payloads are domain-separated (
allmende-cert-v1\n,allmende-revocation-v1\n,allmende-listing-v1\nprefixes).
Listing record
Canonical JSON (RFC 8785), integers only. See internal/listing.
| field | notes |
|---|---|
v |
format version, currently 1 |
id |
32 hex, stable across versions |
author |
identity public key (hex) |
device |
signing device's public key (hex) |
cert |
certificate binding device to author |
seq |
higher replaces lower for the same author + id (any device of the author may supersede) |
created_at, expires_at |
unix seconds; lifetime <= 30 days, owner re-signs to renew |
tombstone |
deletion marker: higher seq, no content, only routing geohash |
kind |
rent or sale |
category |
apartment, house, room, commercial |
geohash |
precision 6 |
price |
`{amount_cents, currency: "EUR", period: month |
area_m2, rooms_x2 |
rooms * 2 (2.5 rooms = 5) |
features, title, description |
bounded text |
images |
{hash, thumb_hash}, content-addressed, no location |
delegate |
optional always-on host's peer ID, chosen by the owner |
pow |
nonce; sha256 of the unsigned canonical bytes has N leading zero bits |
sig |
device signature over the unsigned canonical bytes (with context prefix) |
There is no address, name, phone or email in the record.
Personal data (GDPR)
Only non-personal data is replicated. Exact address and contact details are released by the owner's node on request over an encrypted channel. Deletion = signed tombstone, honored by honest nodes, plus the owner's node ceasing to serve details.
Images (illegal-content risk, e.g. CSAM)
- Images are origin-hosted: only the owner's node (or a host the owner explicitly delegates to) stores them. Third parties never replicate or persistently cache them. Gateways stream without storing.
- Uploads are re-encoded, metadata stripped, size-capped, and checked against hash lists where access is available.
- Signed abuse reports feed subscribable blocklists.
- Get a German lawyer's review before any public launch (§184b StGB).
Availability
Metadata (~2 KB) replicates regionally, so listings remain searchable while the owner is offline. Images and contact details need the owner's node or its delegate. UI shows an "owner offline" badge; listings expire if not re-signed within 30 days.
Replication
- Gossip: every message is checked by a topic validator before it is relayed: canonical encoding, size, signature chain, proof-of-work, region match, not revoked. Invalid messages are rejected (the relaying peer loses score); clock-related failures (expired, future) are ignored without penalty. Publishers flood to all subscribed peers so a listing published right after connecting is not lost before the mesh forms.
- Conflict rules (identical on every node, so replicas converge): keyed by
(author, id); higherseqwins; equalseq-> smaller hash wins; tombstones are stored like any version so old copies cannot resurrect a deleted listing. - Sync (
/allmende/1/sync): on every new connection to a peer a node pulls revocations first, then each subscribed region, paged by a(created_at, author, id)keyset cursor. Tombstones are included so deletions propagate. Simultaneous connections to the same peer (e.g. TCP and QUIC) share one running sync. Currently a full pull; a digest-based incremental sync is future work. Gossip lost while connected is only repaired by the next reconnect; periodic anti-entropy is future work. - Reconnection: bootstrap peers are redialed every 20 s when disconnected.
- Re-announce: a running node re-gossips its own live listings and revocations every 30 minutes, so newcomers hear about them without waiting for a sync.
HTTP API (internal/api)
Public reads serve the signed records in their canonical encoding, so a
browser verifies signatures itself and need not trust the gateway. Writes act
as the node's owner and need Authorization: Bearer <admin token> (a random
token written to admin.token at init, mode 0600).
| method and path | auth | |
|---|---|---|
GET /api/v1/status |
no | peer ID, addresses, identity, regions, peer and listing counts |
GET /api/v1/listings |
no | filters: geohash (comma-separated prefixes), kind, category, min_price, max_price, min_area, min_rooms, limit (max 200), offset |
GET /api/v1/listings/{author}/{id} |
no | one listing |
POST /api/v1/listings |
token | publish a draft; the node adds identity, time, PoW and signature |
PUT /api/v1/listings/{id} |
token | replace own listing (seq + 1); the region cannot change |
DELETE /api/v1/listings/{id} |
token | publish a tombstone |
Reads send Access-Control-Allow-Origin: * (the data is public). Writes are
not cross-origin. Images are not supported yet. status also reports the
node's PoW difficulty, which the browser uses as its minimum.
Web UI (web/)
Every node serves a search UI at GET /. It is vanilla TypeScript, bundled by
esbuild into web/dist (unminified, so it can be read) and committed, then
embedded with go:embed: go build is enough to run a node, Node.js is only
needed to change the UI (cd web && npm ci && npm run build).
- Verification in the browser. Every listing is checked locally with pure-JS ed25519/SHA-256 (works over plain http): format, device certificate, certificate/listing binding, validity windows, signature, proof-of-work. Failing results are hidden (with a count) and their content is never shown. A gateway can therefore withhold listings but not forge them. What a browser cannot know is whether a device was revoked since; the UI says so.
- Canonical JSON is reimplemented in TypeScript and tested against a
fixture signed by the Go code (
internal/listing/testdata/fixture.json, refresh withUPDATE_FIXTURES=1 go test ./internal/listing -run Golden). - Untrusted text. Listing text is only ever inserted with
textContent. The CSP isdefault-src 'none'; script-src 'self'; style-src 'self'; ...(no inline script or style), plusnosniffandno-referrer. - Publishing is not in the UI yet; it stays on the token-protected API.
Running a node (cmd/node)
node init # create identity, show the 12-word phrase (once)
node run --region u1x [--bootstrap <addr>] # replicate a region, serve the API on 127.0.0.1:8080
node recover # restore from the phrase; also yearly cert renewal
Spam
Proof-of-work per listing and per revocation, plus subscribable blocklists (not built yet). The format leaves room for vouching signatures later.
Open
Buyer/seller messaging (E2E, store-and-forward), reciprocity rules, anti- discrimination (AGG) content rules, blocklists, peer scoring and rate limits, incremental sync and anti-entropy, DHT discovery, UI publishing, image hosting, recovering listings onto a fresh machine with an empty database, a helper to turn a place name into a region.