Documentation / Build / Run your own relay
Run your own relay
This page shows how to run the relay program of protocol0 on a computer that others can reach.
What a relay does
A relay passes entries between the computers of a group. It holds no key, so it cannot read a sealed entry or make a valid one. It can change the bytes it passes, but every copy checks each entry by itself and refuses an entry that a relay changed.
It has 2 ways to run: the normal way (for a test or a small run on your own network) and production mode (for the internet).
The normal way
Set it up
- Install Node 20 or later from nodejs.org on any computer that others can reach.
- Copy this project folder to that computer.
- In the folder, run
corepack enableonce, thenpnpm install. - Start the relay:
pnpm relay --port 8080. - To keep entries after a restart, add a folder:
pnpm relay --port 8080 --dir ./relay-data. - Open port 8080 in the firewall of that computer.
- Check it from another computer: open
http://ADDRESS:8080/healthin a browser. - In Pubstad, propose a change of the constitution that adds
http://ADDRESS:8080to the relays. - When more than half of the members have signed, every copy uses your relay too.
- Stop it with Ctrl+C. The group goes on through the other relays on its list.
In the normal way the relay has no size limit and no rate limit.
Production mode
Production mode is for a relay that strangers can reach on the internet. It adds size limits, rate limits and a log that holds no content.
Turn it on with --production on the command line, or with RELAY_MODE=production in the environment.
pnpm relay --production --dir ./relay-data
PORT=9000 RELAY_MODE=production RELAY_DIR=./relay-data pnpm relayWhere the settings come from
| Setting | Environment value | Command line | Default |
|---|---|---|---|
| Mode | RELAY_MODE=production |
--production |
normal |
| Port | PORT |
--port |
8080 |
| Host | HOST |
--host |
0.0.0.0 |
| Data folder | RELAY_DIR |
--dir |
none (memory only) |
The environment value wins over the command line. If the port is not a number, the relay stops with a clear message.
The limits and their defaults
The defaults are sized for a pilot of 5 to 10 people, with groups up to 300 members and 10,000 entries. Set an environment value to change a limit. Each value is a whole number above 0.
| Limit | Environment value | Default | Answer when passed |
|---|---|---|---|
| Size of 1 item | RELAY_MAX_ITEM_BYTES |
262144 (256 KB) | 413 |
| Items in 1 box | RELAY_MAX_BOX_ITEMS |
20000 | 413 |
| Bytes in 1 box | RELAY_MAX_BOX_BYTES |
52428800 (50 MB) | 413 |
| Boxes on the relay | RELAY_MAX_BOXES |
500 | 413 |
| Bytes on the whole relay | RELAY_MAX_TOTAL_BYTES |
314572800 (300 MB) | 413 |
| Size of 1 request | RELAY_MAX_BODY_BYTES |
8388608 (8 MB) | 413 |
| Writes per minute from 1 address | RELAY_WRITES_PER_MINUTE_ADDRESS |
120 | 429 |
| Writes per minute to 1 box | RELAY_WRITES_PER_MINUTE_BOX |
600 | 429 |
- 413 means "too big". The relay stores nothing of that request. A box that is full stays readable.
- 429 means "too many". The answer holds a
Retry-Afterheader with the seconds to wait. A minute later it works again. - A write is a POST request. Reading is not limited.
/healthis never limited. - A repeated item does not count against a box.
- The items of 10,000 entries need well under 50 MB. A client sends 500 items at most in 1 request.
The real address behind a proxy
Behind a proxy (such as Fly.io) every request seems to come from the proxy. To count each sender on its own, set RELAY_TRUST_PROXY_HEADER to the name of the header where the proxy puts the real address. On Fly.io it is fly-client-ip (already set in fly.toml). Set it only when a proxy you trust sits in front, because anyone can write this header otherwise. When it is not set, the relay uses the address of the connection.
The health address
GET /health answers 200 with a small text such as {"ok":true,"relay":"protocol0 relay","boxes":3}. It shows the number of boxes and nothing else: no box name, no content.
What the relay logs
- At start: the port, the mode, the data folder and the limits.
- For each request, in production mode: the method, the status and the size of the answer, for example
POST 200 12. - Never the bytes of an item. Never a box name. Never an address.
Check it on your computer
pnpm relay:checkThis starts the relay as its own program in production mode on a free port, with small limits. It checks /health, a push and a read, the 413 for a big item, the 413 for a full box, the 429 for rapid writes, and that nothing it prints holds the content of an item or a box name. It prints 1 line per check and exits with 0 only when all pass.
For the internet
- The steps in
docs/relay/DEPLOY.mdput it on Fly.io. - The steps in
docs/relay/RUN-YOUR-OWN.mdrun a second relay. - The files
Dockerfileandfly.tomlin this folder are for that. The Dockerfile was written without running Docker here.
The tests
pnpm --filter relay test runs the unit tests of the limits, the settings and the health address.
Adding a relay is a change of the constitution so it needs the number that the constitution sets for its own changes and that number may be above half of the members.
Something wrong on this page