Running Relays¶
A relay accepts signed events, stores them in SQLite, and serves queries, subscriptions and synchronization.
What happens to an event¶
- Authentication is required if the policy says so.
- Rate limits apply for the connection.
- Filters check author, kind, tags, words, size, age, time and proof of work.
- Verification checks schema, id and signature.
- Rate limits apply for the author.
- The event is stored with its indexes, replacing or deleting others where the rules say so.
- Subscribers are notified.
Configuration¶
| Variable | Default | Meaning |
|---|---|---|
RELAY_URL |
required | Public address. Authentication events must name it |
RELAY_NAME |
relay |
Name in the information document |
DATA_FILE |
/data/relay.db |
Database |
KEY_FILE |
/data/relay.key |
Key of the relay. Created if missing |
POLICY_FILE |
none | Policy, see below |
WRITERS, READERS, TRUSTED_PEERS |
none | Override the lists of the policy |
AUTH_WRITE, AUTH_READ |
false |
Require authentication |
SYNC_PEERS |
none | Relays to reconcile with |
SYNC_SECONDS |
15 |
Interval |
PUSH_TO |
none | Relays to push every stored event to, in order and with retries |
RETENTION_SECONDS |
0 |
Maximum age of events. 0 keeps all |
RETENTION_EVENTS |
0 |
Maximum number of events. 0 keeps all |
RETENTION_INTERVAL |
60 |
Seconds between retention runs |
HYPER_URL, HYPER_TOKEN |
none | Sidecar of the replicated log |
LISTEN |
:8080 |
Listen address |
Deletion events are kept when retention removes old events, so deleted content does not come back.
Policy¶
{
"min_pow": 0,
"max_tags": 500,
"max_content": 131072,
"max_future_seconds": 900,
"conn_events_per_second": 50,
"conn_burst": 200,
"pubkey_events_per_second": 20,
"pubkey_burst": 200,
"deny_pubkeys": [],
"deny_words": []
}
| Field | Default | Meaning |
|---|---|---|
writers |
all | Authors that may publish |
readers |
all | Keys that may read. Writers and trusted peers may also read |
auth_write, auth_read |
false |
Require authentication |
min_pow |
0 |
Leading zero bits, committed in the nonce tag |
kinds |
all | Accepted kinds |
deny_pubkeys, deny_words |
none | Refused authors and words in content |
max_tags, max_content |
500, 131072 | Size |
max_future_seconds |
900 | Tolerance for clocks that run ahead |
max_age_seconds |
0 |
Maximum age. 0 accepts all |
conn_events_per_second, conn_burst |
50, 200 | Rate of a connection |
pubkey_events_per_second, pubkey_burst |
20, 200 | Rate of an author |
trusted_peers |
none | Authenticated keys that are exempt from age, proof of work and rate limits |
Unknown fields are refused, so a typing error cannot disable a rule.
Synchronization¶
With SYNC_PEERS, a relay reconciles its set of events with a peer using Negentropy, fetches what it is missing and publishes what the peer is missing. Only differences are transferred. Synchronized events pass the author, kind and deny rules of the receiving relay.
Personal relay¶
A personal relay accepts only its owner's events and pushes them to public relays:
environment:
RELAY_NAME: personal
RELAY_URL: "ws://personal:8080"
WRITERS: "<your public key>"
AUTH_WRITE: "true"
PUSH_TO: "ws://relay-0:8080,ws://relay-1:8080"
Monitoring¶
| Endpoint | Content |
|---|---|
GET /healthz |
Liveness |
GET /metrics |
relay_connections, relay_events_accepted_total, relay_events_refused_total, relay_head_seq |
GET / with Accept: application/nostr+json |
Information document |