Peer Network (P2P Mesh)
General Bots can join an opt-in peer mesh in which every desktop install is a potential node and joining is explicit and reversible.
What the network is β and is not
One binary plays every role; the role is configuration, not a different build.
| Role | Ships today | What it is |
|---|---|---|
| Peer (desktop) | core/peer_network.rs |
A desktop install that may join; off by default, with a Settings switch to stop all traffic |
| Always-on node (VPS) | Same binary, configured from Vault | A node that never sleeps; peer.generalbots.org is deployed this way |
| Volunteer node / relay | Planned | A peer that forwards ciphertext for others; the payload layer exists in core/peer_payloads.rs but there is no volunteer mode yet |
The network is not a central store: payloads are end-to-end encrypted, a
relay holds only an expiring encrypted copy, and registrations live in an
in-memory table keyed by node id that expires after heartbeat-ttl-secs
(default 90 s). It carries no telemetry, and with the mesh off every request
stays on 127.0.0.1.
What actually travels
Registration and heartbeat are the only plaintext messages; each carries the
fields of RegisterRequest / HeartbeatRequest (core/peer_network_types.rs).
| Message | Fields | Retained by a helper |
|---|---|---|
| register | node_id, name, optional address, capabilities |
The row, until the TTL expires, in memory |
| heartbeat | node_id, optional address, optional capabilities |
Refreshes last_heartbeat |
Every other operation is a PeerPayload envelope (core/peer_payloads.rs):
personal-mesh, shared-folder, drop-box, ask-my-bot, peer-backup,
calls and peer-cache. The body is opaque to the relay and only the recipient
can decrypt it.
| Operation | What a relay sees | What it can retain |
|---|---|---|
| Chat between directly reachable peers | Nothing β no relay hop | Nothing |
| Any relayed payload | Recipient id, ciphertext, timing and size | The encrypted envelope until expires_at |
| Home-site signature check | The signed site and its key id | The site, as any web server would |
| Registration / heartbeat | Node id, name, address, capabilities | The row, until the TTL expires |
The relay never receives message text, file contents, contact lists or the node's signing key.
Privacy model
- Opt-in only. The first-run wizard asks once for
OfflineorP2P; the default isOffline. The answer is written to the stack.envasGB_NETWORK_MODEand honoured at boot. - Reversible. Settings β Network can flip it;
POST /api/peer/disablestops every peer surface immediately and rewrites the same key, so the choice survives a restart. Offline also removes Settings β Shared Links. - No retention. Peer nodes do not retain user content; payloads are end-to-end encrypted.
- No telemetry. No analytics, usage reports or crash beacons travel through the mesh (
PRIVACY.md). - Loopback by default. With P2P disabled, all networking stays on
127.0.0.1.
Reachability tiers
| Tier | Address | Requirement |
|---|---|---|
| LAN | hostname.local:<port> |
Reachable only on the local network |
| Own domain | A configured PUBLIC_BASE_URL / public_base_url |
DNS pointing at the host |
| Free General Bots address | <name>.generalbots.org |
Opt-in hosted relay, available only after joining P2P |
Node identity
A desktop generates a local peer identity on first run: a stable node id in
node.json under data-dir, plus a signing key in the local Vault
(secret/gbo/peer, signing-key). Registration and heartbeat announce only the
node id and display name; the signing key is never transmitted. Heartbeats are
sent only while P2P is enabled and only to the configured relay.
Configuration (Vault)
Precedence, highest first:
- Process environment (
GB_PEER_*) β dev, test and one-off overrides - Vault
secret/gbo/peerβ the canonical source for a deployed node - The legacy
~/.prodfile, only forGB_PEER_TOKEN - Built-in defaults, plus
mode.jsonfor the on/off flag
| Key | Env override | Meaning |
|---|---|---|
enabled |
GB_PEER_NETWORK |
1 / true / yes / on joins the mesh |
node-id |
GB_PEER_NODE_ID |
Stable UUID; generated and persisted when empty |
node-name |
GB_PEER_NODE_NAME |
Display name; general-bots-<id8> when empty |
advertise-addr |
GB_PEER_ADVERTISE_ADDR |
Address relayed to peers; defaults to peer.generalbots.org |
data-dir |
GB_PEER_DATA_DIR |
Where node.json and mode.json live |
heartbeat-ttl-secs |
GB_PEER_HEARTBEAT_TTL_SECS |
Peer expiry, default 90 |
token |
GB_PEER_TOKEN |
Shared node token; required β with no token every /api/peer/* route answers 503 |
signing-key |
GB_PEER_SIGNING_KEY |
Home-site signing key; empty falls back to the node id |
GET /api/peer/status returns config_sources, the origin of each key
(env, vault, prod-file, mode-file, default). It is not anonymous: call
it with the shared token (X-Peer-Token) or an admin session. Token and signing
key are never printed β the boot log reports them as configured or absent.
Desktop client (#1969)
The desktop client never discovers a relay. GET /api/product publishes a
peer object with relay, relay_url, enabled and node_id; the suite
resolves peers and home sites through that host (window.GB_PEER_RELAY).
Settings β Network and Settings β Shared Links read the value from there rather
than hardcoding it. The object never carries the token, the signing key or the
node's advertise address. advertise-addr is separate: it is the address this
node tells peers to reach.
Enabling the public node (peer.generalbots.org)
vault kv put secret/gbo/peer \
enabled=1 \
node-name=peer \
advertise-addr=peer.generalbots.org \
token="$(openssl rand -hex 32)" \
signing-key="$(openssl rand -hex 32)"
sudo systemctl restart botserver
curl -s -H "X-Peer-Token: $GB_PEER_TOKEN" \
http://127.0.0.1:8080/api/peer/status | jq .config_sources
# { "enabled": "vault", "node-name": "vault", "token": "vault", ... }
Nothing peer-specific belongs in the systemd unit: only VAULT_ADDR,
VAULT_TOKEN and the CA path live there.
Authentication (required, #2141)
| Route | Credential |
|---|---|
POST /api/peer/register, POST /api/peer/heartbeat |
Shared token |
POST /api/peer/payloads, GET /api/peer/payloads |
Shared token |
GET /api/peer/home-site, GET /api/peer/status |
Shared token or an admin session |
POST /api/peer/enable, POST /api/peer/disable |
Admin session only |
- The token is compared in constant time and accepted as
X-Peer-Token: <token>orAuthorization: Bearer <token>. - With no token configured, routes fail closed with
503 peer_network_unconfigured; they never fall back to "local calls are allowed". enableanddisableare ordinary admin endpoints, so a token-less request cannot stop the network.
Token rotation
vault kv put secret/gbo/peer token="$(openssl rand -hex 32)"
sudo systemctl restart botserver # configuration is resolved once, at boot
Rotate signing-key the same way; home sites regenerated after the restart
carry the new signature. The token is checked only on peer endpoints, so a
restart is the whole rollout. A peer still holding the old value gets 401
unauthorized until it is updated.
Status
The foundation (identity, heartbeat, status endpoint) ships in
botserver/src/core/peer_network.rs and
botserver/src/main_module/routes/peer_network.rs. Payloads ship in
botserver/src/core/peer_payloads.rs, and the signed home-site generator ships
in botserver/src/core/home_site.rs.
Related
- Consent System β how an agent action is gated locally.
- General Bots OS (laptop appliance) β the image the mesh runs on.