Skip to content

Commit

Permalink
docs: add strfry guide and update nostream, wot relay, and strfry29 l…
Browse files Browse the repository at this point in the history
…inks (#5)
  • Loading branch information
jchiarulli authored Oct 12, 2024
1 parent 92b4d4d commit 4a5599f
Show file tree
Hide file tree
Showing 30 changed files with 613 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/relay/nostream/build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Build

🚧 Under Construction 🚧
2 changes: 2 additions & 0 deletions docs/relay/nostream/configuration.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Configuration

🚧 Under Construction 🚧
2 changes: 2 additions & 0 deletions docs/relay/nostream/install.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Install

🚧 Under Construction 🚧
3 changes: 3 additions & 0 deletions docs/relay/nostream/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Intro

🚧 Under Construction 🚧
2 changes: 2 additions & 0 deletions docs/relay/nostream/service.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Service

🚧 Under Construction 🚧
2 changes: 2 additions & 0 deletions docs/relay/nostream/test.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Test your Relay

🚧 Under Construction 🚧
3 changes: 3 additions & 0 deletions docs/relay/nostream/websocket-connection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# WebSocket Connection

🚧 Under Construction 🚧
115 changes: 115 additions & 0 deletions docs/relay/strfry/build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Build

We're now going to discuss how to build [strfry](https://github.com/hoytech/strfry "strfry").

## Dependencies

Before building the binary, we need to install the following dependencies

```bash
apt install git g++ make libssl-dev zlib1g-dev liblmdb-dev libflatbuffers-dev libsecp256k1-dev libzstd-dev
```

## Clone the Repository

We'll be downloading the repository to the `$HOME` directory.

Navigate to the `$HOME` directory:

```bash
cd $HOME
```

We're now ready to clone the strfry repository:

```bash
git clone https://github.com/hoytech/strfry.git
```

After cloning the repository, navigate to the `strfry` directory:

```bash
cd strfry
```

You can use the repository to update strfry, so we're going to keep the repository on the relay.

## Build strfry

We're now ready to build strfry.

First, initialize and update the git submodule:

```bash
git submodule update --init
```

Now, we're going to run:

```bash
make setup-golpe
```

Finally, run:

```bash
make -j4
```

The compilation could take a while depending on your server's specs, so be patient while the binary is being built.

When the compilation is finished the binary will be located in the `strfry` directory.

You can list out the contents of that directory to see the binary:

```bash
ls
```

You should see the binary file which should be named `strfry`.

## Version

At the time of writing, the latest version of strfy is `v1.0.1` which is what the rest of the guide is currently based on.

## Run Binary

You can now run the binary:

```bash
./strfry relay
```

strfry should now be listening on `127.0.0.1:7777` and by default only accepts connections from localhost. The relay uses the database in your current directory called `strfry-db` along with a config file called `strfry.conf` which is also located in your current directory.

To stop the relay press `Ctrl+C`.

### Troubleshooting

If you get the following error when running the binary:

```bash
strfry error: Unable to set NOFILES limit to 1000000, exceeds max of 524288
```

Open the strfry config file:

```bash
nano $HOME/strfry/strfry.conf
```

Navigate to the line that says:

```bash
nofiles = 1000000
```

Set the `nofiles` setting to `0` which prevents strfry from attempting to set the value:

```bash
nofiles = 0
```

Save and exit the file.

You should now be able to run the binary.
90 changes: 90 additions & 0 deletions docs/relay/strfry/configuration.md
Original file line number Diff line number Diff line change
@@ -1 +1,91 @@
# Configuration

We're now going to discuss the strfry config file including how to set some of the settings as well as how to move the file to a config directory owned by the `nostr` user we previously created. We're also going to discuss how to create the data directory which will be owned by the `nostr` user.

## Config File

The strfry config file is located in the strfry repository we cloned and is named `strfry.conf`. In our case the file is located in the following directory `$HOME/strfry`.

To view the settings you can open the file:

```bash
nano $HOME/strfry/strfry.conf
```

## Config Directory

We're going to create a config directory for strfry in the `/etc` directory:

```bash
mkdir /etc/strfry
```

We can now copy the config file to the config directory:

```bash
cp $HOME/strfry/strfry.conf /etc/strfry
```

We can change the permissions of the config directory and all of its content, i.e., the files and subdirectories inside of it:

```bash
chmod 0755 -R /etc/strfry
```

We can then change the ownership of the config directory to use the `nostr` user:

```bash
chown -R nostr:nostr /etc/strfry
```

## Data Directory

We're going to create a data directory for strfry in the `/var/lib` directory:

```bash
mkdir -p /var/lib/strfry/db
```

We can change the permissions of the data directory and all of its content, i.e., the files and subdirectories inside of it:

```bash
chmod 0755 -R /var/lib/strfry
```

We can then change the ownership of the data directory to use the `nostr` user:

```bash
chown -R nostr:nostr /var/lib/strfry
```

## Edit Config File

To change the relay settings you can open the file and edit the settings you want to change:

```bash
nano /etc/strfry/strfry.conf
```

Here are some of the settings you may want to change in the config file:

- `db` - The directory where your relay will store the LMDB database. The default value is set to `./strfry-db`. We'll set this to `/var/lib/strfry/db`. Restart required after updating.

- `bind` - The address your relay will listen on. The default value is `127.0.0.1`. To listen on all interfaces set this to `0.0.0.0`. Restart required after updating.

- `port` - The port your relay will use for the WebSocket connection. The default value is `7777`. Restart required after updating.

- `nofiles` - Sets the OS limit on the maximum number of open files/sockets. If set to `0`, strfry won't attempt to set this value. The default value is `1000000`. We'll set this to `0`. Restart required after updating.

- `realIpHeader` - Used to specify the HTTP header that contains the client's real IP before reverse proxying. The default value is `""`, and the input must be lowercase. We'll set this to `x-forwarded-for`.

- `name` - The name of your relay which will be shared with Nostr clients. Must be less than 30 characters. The default value is `strfry default`. We'll set this to `Relay Runner's strfry Relay`.

- `description` - A description of your relay. The default value is `This is a strfry instance.`. We'll set this to `This is a Relay Runner strfry instance`.

- `pubkey` - Your Nostr public key (32-byte hex, not npub) used for administrative requests. The default value is `""`. We'll set this to `3bcbb0f7dea9da9f5b2659ca5da89d5e576215de3885e51bd2474dd1b0c44b16`.

- `contact` - Alternative contact used for administrative requests. Can be an email or website and should be a URI using schemes like `mailto` or `https`. The default value is `""`. We'll set this to `mailto:[email protected]`.

- `icon` - URL to your relay's icon, e.g., `https://example.com/your-relay-icon.png`. It's recommended to be in squared shape.

- `nips` - List of NIPs supported by the relay. The value should be a JSON array, e.g., `[1,2]` or an empty string. The default value is `""`.
34 changes: 34 additions & 0 deletions docs/relay/strfry/install.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
# Install

After building the binary, we're now going to "install" strfry by using the `install` command.

We’re actually not installing strfry though since the `install` command isn’t used to install software packages despite its name.

The `install` command is a way to copy files to a target location similar to the copy command, i.e., `cp`, but it gives us more control by allowing us to use advanced features when copying the files.

Some of these advanced features include the abilities to adjust permission modes like when using the `chmod` command, adjust ownership permissions like when using the `chown` command, to make backups of the files, and to preserve the metadata of the files, e.g., the access and modifications times of the files.

We're going to be "installing" the `strfry` binary to the `/usr/local/bin` directory which allows us to run the binary from any directory. This makes running the binary easier since we don't have to navigate to or specify the path to the `strfry` binary every time we want to run it.

First, navigate to the directory where you installed the binary, e.g.,

```bash
cd $HOME/strfry
```

To "install" strfry we can run:

```bash
install -v -m 0755 -o root -g root -t /usr/local/bin strfry
```

Here’s an explanation of the options we passed to the `install` command:

`-v`: This option specifies that we would like to see the verbose output which means we’ll be displayed with the details of the process.

`-m`: This option specifies the file permissions in octal notation for the files we’re copying, i.e., `0755`.

`-o`: This option allows us to set the owner for the files we’re copying, i.e., `root`.

`-g`: This option allows us to set the group for the files we’re copying, i.e., `root`.

`-t`: This option specifies the target directory that we want to copy the specified files into, i.e., `/usr/local/bin`.
23 changes: 23 additions & 0 deletions docs/relay/strfry/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Intro

[strfry](https://github.com/hoytech/strfry "strfry") is a relay implementation written in C++ that supports multiple NIPs and has numerous features.

## Features

strfry features include:

- Support for most applicable [NIPs](https://github.com/nostr-protocol/nips "NIPs"): 1, 2, 4, 9, 11, 22, 28, 40, 70, 77

- No external database required: All data is stored locally on the filesystem in a Lightning Memory-Mapped Database (LMDB)

- Hot reloading of config file: No server restart needed for many config param changes

- Zero downtime restarts, for upgrading binary without impacting users

- WebSocket compression using `permessage-deflate` with optional sliding window, when supported by clients. Optional on-disk compression using zstd dictionaries.

- Durable writes: The relay never returns an `OK` until an event has been confirmed as committed to the DB

- Built-in support for real-time streaming (up/down/both) events from remote relays, and bulk import/export of events from/to jsonl files

- [negentropy](https://github.com/hoytech/negentropy "negentropy") based set reconciliation for efficient syncing with clients or between relays, accurate counting of events between relays, and more
85 changes: 85 additions & 0 deletions docs/relay/strfry/service.md
Original file line number Diff line number Diff line change
@@ -1 +1,86 @@
# Service

A service is a long-running process that can be started and stopped manually as well as set to automatically start when the system boots. It can be used to run background tasks, handle network requests, and interact with the system.

## Create Unit File

We're going to create a [systemd](https://systemd.io "systemd") service for strfry which will allow us to automatically start the strfry relay on boot.

To do this we're going to create and open the following systemd unit file:

```bash
nano /etc/systemd/system/strfry.service
```

## Edit Unit File

We're now going to add the following lines to the `strfry.service` unit file:

```ini
[Unit]
Description=strfry Service
After=network.target

[Service]
Type=simple
User=nostr
Group=nostr
ExecStart=/usr/local/bin/strfry --config=/etc/strfry/strfry.conf relay
Restart=on-failure
RestartSec=5
ProtectHome=yes
NoNewPrivileges=yes
ProtectSystem=full
LimitCORE=1000000000

[Install]
WantedBy=multi-user.target
```

This service tells systemd to start strfry as the `nostr` user after the network has been properly configured using our specified config file and to attempt to restart the service after waiting 5 seconds if it fails.

## Reload systemd

To apply the newly created strfry service we're going to reload systemd:

```bash
systemctl daemon-reload
```

## Enable Service

We can enable the strfry service to automatically start on boot:

```bash
systemctl enable strfry.service
```

## Start Service

To start the strfry service:

```bash
systemctl start strfry.service
```

## Check Status

The relay service should now be running and set to automatically start on boot.

You can check the status of the service using:

```bash
systemctl status strfry.service
```

If the service is running, you should see the following in the output:

```bash
Active: active (running)
```

If the service is enabled to automatically start on boot, you should see the following in the output:

```bash
Loaded: loaded (/etc/systemd/system/strfry.service; enabled; preset: enabled)
```
Loading

0 comments on commit 4a5599f

Please sign in to comment.