The relay of the Veydan network, compatible with Nostr. One program, vrelay,
without state of its own, in two modes:
vrelay serveholds the connections of the clients: sign-in (NIP-42), the read and write policy, the subscriptions. It hands every event to the queue.vrelay writetakes the events from the queue (NATS JetStream), stores them (Apache Cassandra) and hands them to the subscribers.
It stands in place of the relay site of nginx, vguard, strfry, its router and
its timers. On a server of the Veydan Server kit it is the engine vrelay
(see the README of Veydan-Server); this page is for a relay of its own.
Your own relay on one machine: vrelay serve and vrelay write, NATS,
Cassandra, and Caddy for TLS, from published images; nothing is built. You
need Docker with Compose, 8 GB of memory, a domain name whose DNS record
points at the machine, and ports 80 and 443 open to the internet: Caddy gets
and renews the certificate of that name by itself (Let's Encrypt).
cd deploy
cp compose/.env.example .env # set RELAY_HOST, and ADMIN_PUBKEY; read the rest
docker compose up -d --wait # about 90 s the first time, 40 s after
docker compose logs relay-init # the card: the address, the app key, the link for the app
The first start makes the passwords and the keys, turns the default login of
Cassandra off and gives vrelay a role of its own, makes the tables and the
streams, then starts the writer, the relay and Caddy. The card again, at any
time: docker compose run --rm --no-deps relay-init card.
The settings of the stack are in .env, one file with comments
(deploy/compose/.env.example). Every setting of the relay itself is a
variable VRELAY_<SECTION>_<NAME>, listed with its type, default, range and
whether a reload takes it in spec/config.md; the same list,
commented out at the defaults, is deploy/vrelay.env.example. Add one to
environment: of vrelay in deploy/compose.yaml. vrelay config check
checks the settings and names each problem.
- Open to the internet: 80 and 443 (Caddy) alone. Cassandra, NATS and the plain socket of vrelay (7778, for a proxy of your own) listen on 127.0.0.1. No container runs as root but the two one-shots that make the passwords and own the folders; none sees the docker socket.
- A proxy of your own instead of Caddy:
COMPOSE_PROFILES=relayin.env, the proxy to127.0.0.1:7778, and its address inRELAY_TRUSTED_PROXIES. - Team or channel:
ACCESS_MODEin.env(below).
The data are docker volumes of the project veydan-relay: cassandra-data
(the events), nats-data (the queue), secrets (the passwords and the
keys), vrelay-access (members and invites), caddy-data (the
certificate). docker compose down keeps them; docker compose down -v
deletes them all, the keys too.
To back up, stop the stack and save the volumes: docker compose stop, then
for each volume
docker run --rm -v veydan-relay_<volume>:/v:ro -v "$PWD":/b nats:2.15.3-alpine tar -C /v -czf /b/<volume>.tgz .,
and docker compose up -d. The events alone, while it runs:
docker compose run --rm --no-deps -T vrelay-write export > events.jsonl.
Put the new version in RELAY_TAG of .env, then
docker compose pull && docker compose up -d --wait; vrelay-migrate runs
at every start and makes what a new version adds. To pin the image by its
digest as well: RELAY_TAG=<version>@sha256:<digest>
(docker buildx imagetools inspect rookbeam/vrelay:<version>).
Both ways are JSON lines, one event a line, with the env file of
vrelay write (vrelay config check --mode import checks what both read):
# strfry -> vrelay, after `vrelay migrate`
strfry export > events.jsonl
vrelay import events.jsonl # or: strfry export | vrelay import -
# vrelay -> strfry
vrelay export > events.jsonl # --since <unix> / --until <unix>: by created_at
strfry import < events.jsonl
vrelay import checks the id and the signature of each event (--trust:
not), its size and its tags, and skips what the relay would not keep:
ephemeral kinds, the kinds kept in memory only, an event past its
expiration or past the term of its kind. Deletions (kind 5) are applied
after every other event. A second run of the same file stores nothing. At
the end it prints what became of each line; the exit is 1 when any event
failed. vrelay export reads the whole store once; deleted, replaced and
expired events are not written.
A team or a channel server (VRELAY_ACCESS_MODE not open) keeps its
members and invites in the files of VRELAY_ACCESS_MEMBERS_FILE,
VRELAY_ACCESS_INVITES_FILE and VRELAY_ACCESS_SECRET_FILE, in the formats
of vguard: a server moved from vguard keeps them, and its invites stay good.
With the env file of vrelay serve, or in Docker as
docker compose exec vrelay /vrelay access ...:
vrelay access mode # open, team or channel
vrelay access members list # one hex key a line
vrelay access members add <npub|hex>
vrelay access members remove <npub|hex>
vrelay access invite [--uses N] [--days D] [--label L] # the code, one line; 1 use, 7 days
vrelay access invite list
vrelay access invite revoke <id>
A card with an invite: docker compose run --rm --no-deps relay-init card <code>.
The running relay reads the members again within VRELAY_POLICY_REREAD_SECS,
or at once on SIGHUP (systemctl reload vrelay). Exits: 0 done, 1 it did not
work, 2 the settings do not allow it.
make release builds one static Linux binary, dist/vrelay, with its
checksum (the Rust version is the one rust-toolchain.toml names). The
units deploy/vrelay.service and deploy/vrelay-write.service run it under
/opt/vrelay, with the settings in /opt/vrelay/etc/vrelay.env; it needs a
Cassandra 5 and a NATS with JetStream of its own. make test runs the tests.
One server of 8 vCPU and 16 GB holding everything (vrelay, Cassandra, NATS and a proxy in front):
- about 5 000 stored events a second, with every client writing;
- about 25 000 clients online at a normal messaging profile;
- after a restart under 20 000 connected clients, every client back without help.
Two regions sharing one store: no message lost across a 3-minute cut of the link between them.
VRelay is free and open-source software under the GNU Affero General Public
License, version 3 (AGPL-3.0-only), the licence of every part of Veydan:
LICENSE is the text that counts, NOTICE.md holds the
copyright, the additional terms and the commercial licence, and
LICENSE-SUMMARY.md says it in short. The crates it is
built from are listed with their licences in
THIRD-PARTY-LICENSES.md (make third-party).
Developed by Rookbeam Technologies LLC, USA