Add runnable node, HTTP API, all-devices revocation and reconnect sync
- cmd/node: init (recovery phrase onboarding), run, recover - api: public reads of canonical signed records, token-protected writes - identity: RevokeAll voids every device certified before a cutoff, so recovery works with only the phrase; store purges by certificate age - p2p: redial bootstrap peers, sync on every new connection (in-flight guard only), validate bootstrap addresses up front - docs: API, recovery semantics, peer-ID change on recovery Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+54
-9
@@ -37,9 +37,19 @@ revoked. There are no accounts.
|
||||
- **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 until `cert_expires_at`. A revoked device's signatures are
|
||||
void: its listings are purged and refused. The owner restores the identity
|
||||
from the phrase on a new machine, revokes the old device, enrolls a new one
|
||||
and republishes (higher `seq`).
|
||||
void: its listings are purged and refused. Two forms:
|
||||
- **one device** (`device` set): voids exactly that device;
|
||||
- **all devices** (`device` empty): voids every device of the author whose
|
||||
certificate was issued *before* `revoked_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.
|
||||
- **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`,
|
||||
@@ -108,11 +118,44 @@ within 30 days.
|
||||
`(author, id)`; higher `seq` wins; equal `seq` -> smaller hash wins;
|
||||
tombstones are stored like any version so old copies cannot resurrect a
|
||||
deleted listing.
|
||||
- **Sync** (`/allmende/1/sync`): on connecting to a peer (at most every
|
||||
5 minutes) a node pulls revocations first, then each subscribed region,
|
||||
paged by a `(created_at, author, id)` keyset cursor. Tombstones are included
|
||||
so deletions propagate. Currently a full pull; a digest-based incremental
|
||||
sync is future work.
|
||||
- **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.
|
||||
|
||||
## 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
|
||||
|
||||
@@ -123,4 +166,6 @@ Proof-of-work per listing and per revocation, plus subscribable blocklists
|
||||
|
||||
Buyer/seller messaging (E2E, store-and-forward), reciprocity rules, anti-
|
||||
discrimination (AGG) content rules, blocklists, peer scoring and rate limits,
|
||||
incremental sync, DHT discovery, HTTP gateway and web UI, image hosting.
|
||||
incremental sync and anti-entropy, DHT discovery, web UI, image hosting,
|
||||
recovering listings onto a fresh machine with an empty database, a helper to
|
||||
turn a place name into a region.
|
||||
|
||||
Reference in New Issue
Block a user