What is Nostr?
boatymcboatface / Boatface
npub1tf6…v4pu
2024-10-24 04:57:34

boatymcboatface on Nostr: Saving. nostr:note1tgdwaj4ny3rkchgd9fr9le36y6u8szml7hvtkkeuyppj4uua6sfq8ct2su

Saving.
### Tldr

- Nostr relays help users post and read notes on the network
- Relay operators have launched a variety of relays for you to use
- You too can launch your own relay for any reason you like
- Launching your own relay gives you a lot of power in how you use Nostr
- Many relay softwares exist for you to use
- I launched a personal relay using HAVEN relay software on my VPS
- I am now more in control of saving notes, cutting spam, and protecting my privacy
- My personal relay is now hosted at relay.rodbishop.nz

### What are Nostr Relays Anyway?

When you're a user of a social network, you post and read notes from other users on the network. In a centralised network like Twitter or Instagram the company's servers receive all user's notes and relay them to other users. On Nostr, there is no single company's servers to relay messages, so instead the task is taken up by relay operators.

Anyone can be a relay operator and they can run a relay for any purpose. When you start using Nostr you will usually be connected to any one of a number of "public" relays, and be able to post and receive notes from users on the network via these.

Configuring these relays can tailor your experience somewhat–for example the client Nostrudel allows you to select from Western or Japanese relay set.

It is also possible to set up your own relay to use for your own purposes. All kinds of people have launched relays for all kinds of purposes. For example, to:

- Power your own client
- Support your community
- Run a for-profit relay business
- Relay a certain a type of content you need
- Back up your own notes, decrease spam, or increase privacy
- Curate your own social feed with your own algorithm

#### Relay instances available to connect with

Today is an interesting time in relay-ops. The evolution of the technology has inspired users to experiment with diverse types of relays tailored to various needs. As a result there are very many relay instances in operation and available to connect with.

A few sites try to collate which relays are in operation, like [nostr.info](https://nostr.info/relays/) and [xport.top](https://relays.xport.top/) and [sesseor's relay list](https://github.com/sesseor/nostr-relays-list/blob/main/relays.txt) . These lists are long (Sessor's list counted 2,500+ relays) and it's not clear to me whether it's even possible to be comprehensive as relays may join or leave the network all the time.

Broadly speaking, relays might be available for different users to use in different ways:

- A relay where anyone can post, like [relay.damus.io](http://relay.damus.io)
- A paid relay where anyone can post after payment, to cut spam, like [nostr.wine](http://nostr.wine)
- A "web of trust" relay where anyone can post if they are related to the owner's social graph, to cut spam, like [nostrelites.org](http://nostrelites.org)
- A speciality relay where a particular community can post, like [nostr.com.au](http://nostr.com.au) for #austriches (Australians)
- A relay where anyone can post just specific content, like [purplepag.es](http://purplepag.es) for user profiles only
- A team relay for your company or organisation only
- A personal relay for your own personal use

[Nostr.Band](https://stats.nostr.band/) shows which of these available relays are most popular, such as [relay.damus.io](http://relay.damus.io) and [nos.lol](nos.lol) and [eden.nostr.land](http://eden.nostr.land)

#### Relay softwares for you to launch your own

You may decide to launch you own relays, and if you do there are many different relay softwares to choose from:

- Simple, like [Bucket](https://github.com/coracle-social/bucket) (<100 lines of code)
- Widely used, like [Nostream](https://github.com/Cameri/nostream) (top ranked on Github)
- Customisable, like [Khatru](https://khatru.nostr.technology/) (a framework for customised relays)
- Specialised, like [HAVEN](https://github.com/bitvora/haven) or [Team Relay](https://github.com/bitvora/team-relay) (for personal or teams relays, based on Khartu)

You can run these on your own server, or local machine, or [phone](https://github.com/greenart7c3/Citrine) or with a third-party host.

[Aljaz](aljaz (npub1alj…g9jp)) provides a [great resource](https://github.com/aljazceru/awesome-nostr?tab=readme-ov-file#relays) with 45+ relay softwares to choose from.

In summary, at a high level,

- Anyone can connect to any of the relay instances that are available for them to use
- Anyone who wants to launch their own can select the relay software that best suit their needs, launch an instance, and have it used by whichever users they like

### Reasons to Run Your Own Relay

As a normal user of a Nostr client there's no obligation to run a relay. But having your own relay does give you more power.

For my own journey down the #nostr rabbit hole, I was looking for a relay to:

- back up my notes
- decrease spam
- increase my privacy
- learn skills I could later use for running a community or team or paid relay

Backing up notes – When you post notes to a public relay there's no guarantee that the relay is going to keep them long-term. It's job is relaying your notes to other clients, not storing them. Running your own relay allows you to keep your notes online.

Decrease spam – To first spam we can use a "Web of Trust" model–in which users endorse other users as trustworthy. A "Web of Trust" relay will reject notes from parties too far removed from your network. Running your own relay makes you more difficult to spam.

Increasing privacy – When you connect to a public relay, they can determine personal information about you, such as your IP address. Running your own relay keeps things more private.

For communities and teams and paid relays – Many opportunities exist to tailor relays to certain users needs, be they businesses or communities or as a for-profit business. For me, I am hoping that running my own relay helps me learn skills I can use in these kinds of further ventures.

To start I decided to focus on a personal relay. However, when I really got under the hood, it turned out I would need multiple relays not just one.

#### The outbox model

[Mike Dilger](mikedilger (npub1acg…p35c)) proposed [the outbox model](https://mikedilger.com/gossip-model/) (originally called the gossip model) as a way for users to engage with the wider Nostr network. It's a great model that is helpful to understand, as it suggests to establish different relays for different purposes.

Many clients and relay softwares have now adopted and continued to elaborate on this model. An example is to run specialised relays for Outbox, Inbox, Chat and Private needs.

**Outbox Relay (also called Home Relay)**

- This relay is for notes you have written, so that everyone knows where to find your notes
- In a set up where you are running your own, this relay is restricted so that only you can post to it, and you should set up your clients to post your notes to it
- An advanced version may take any notes received to this relay and "blast" them to other public relays so that your notes get wider reach

**Inbox Relay (also called Public Relay)**

- This relay is for public notes that other users want you to see, so that you always find notes that are relevant to you, including all replies, comments, likes, and zap payments
- In a set up where you are running your own, this relay is where you should look for notes relevant to you, and you should set up your clients to read from it
- An advanced version may search other public relays for notes that tag you, and import them into this relay so that you never miss a relevant note

**Chat Relay (also called Direct Message Relay)**

- This relay is for private direct message notes from other users, so that you always find your direct messages and so that they stay private
- In a set up where you are running your own, this relay is restricted so that only you can read from it, and you should set up your clients to read from it
- An advanced version may cut spam by only accepting direct messages from other users within your Web of Trust

**Private Relay**

- This relay is for your private use only, so that you can store private drafts or thoughts
- Only you can write to it and only you can read from it (and so, it is a bit mis-named as it does not actually relay anything to anywhere at all)
- In a set up where you are running your own, it gives you true privacy for these notes

**In summary as a user**

- I post my notes to my outbox relay. Network users can read them there, and if the relay is advanced it will also blast the notes out to other relays on the network
- I read from my inbox relay. Network users know to reach me there, and if the relay is advanced it will also bring me notes from the wider network
- I can have private direct message conversations with others in my chat relay.
- I can save private notes in my private relay

For me, this model has a lot of appeal and I went looking for a personal relay which adopted this model and contained all of these features.

#### HAVEN as a personal relay

I decided to go with HAVEN relay software.

HAVEN is all four of the above relays in one–outbox, inbox, chat and private. It contains advanced features like blasting your notes from outbox to other relays, importing notes from other relays to your inbox, and preventing spam with Web of Trust.

[HAVEN](https://github.com/bitvora/haven) is written by [Utxo the Webmaster](👨‍💻 utxo 👨‍💻 (npub1utx…50e8)) . It is based upon the [Khatru](https://khatru.nostr.technology/) relay framework by [Fiatjaf](fiatjaf (npub180c…h6w6))

### Setting up HAVEN as a Personal Relay

I am mostly non-technical, but on my #Nostr journey I have been having success with technology set ups that use Docker.

- I have a cheap VPS which currently runs [Albyhub and Phoneixd with Docker](naddr1qq…fyfn),
- My objective was to set up HAVEN to run alongside it, in a separate Docker on the same server. HAVEN does not include Docker by default, but [Sebastix](sebastix (npub1qe3…zefe)) published a [fork with Docker support](https://github.com/nostrver-se/haven/tree/docker_compose_support).

To get HAVEN up and running in Docker on your VPS:

1. Clone and configure HAVEN with the right variables
2. Launch it in Docker on your VPS
3. Check the URLs and logs to see your HAVEN running
4. Configure a subdomain to point to the VPS
5. Configure the VPS to reverse proxy to the Docker port
6. Configure the relays in your favourite Nostr client
7. Post a note to your outbox and see if it blasts!

#### Running HAVEN

I cloned Sebastix fork to start.

```
git clone -b docker_compose_support https://github.com/nostrver-se/haven.git
cd haven
```

The software sets up all environment variables in the `.env` file, and comes with an `.env.example` file. Duplicate and rename the file to `.env`. Within the `.env` file you need to set up the environment variables. The file is long but it contains lots of repetition and for the most part defaults can be retained–only a few changes are required:

- Replace all instances of the default user npub with your own (for me, `npub1r0d8...`)
- Change the default relay URL to your own (for me, `relay.rodbishop.nz`)
- Replace all instances of the default name in the relay names (for me, "Rod's ...")
- Replace all instances of the default profile image with your own

To enable automatic blasting from your outbox, and importing to your inbox, the software comes with an example list of relays to blast and import from. See `relays_blastr.example.json` and `relays_import.example.json`. To use these features simply duplicate and rename these files to `relays_blastr.json` and `relays_import.json` respectively. Within these files you can specify the public relays of your choice. I simply used the default list.

There are other features available, such as backups and initial imports, but I decided to handle these later. To start with I wanted to launch the relay and test it.

To launch the relay run Docker Compose.

```
docker-compose up -d
docker logs haven-relay
```

Then you should explore the logs in the command line and the ports in your browser to see if it launched successfully. The logs should show your web of trust has been built successfully and the browser should show simple landing pages.

The logs should show that the relay has queried the network and built a web of trust from your followers. Mine looked as follows.

```
2024/10/14 12:02:08 🌐 building web of trust graph
2024/10/14 12:02:16 🫂 total network size: 13296
2024/10/14 12:02:16 🔗 relays discovered: 335
2024/10/14 12:02:17 🌐 pubkeys with minimum followers: 9394 keys
```

Your browser should show you have four relays in operation, for example as follows.

- `your_IP_address:3355` (your outbox or home relay)
- `your_IP_address:3355/private` (your private relay)
- `your_IP_address:3355/chat` (your direct message relay)
- `your_IP_address:3355/inbox` (your inbox relay)

That's it. Your relay is online.

#### Connecting HAVEN

Now all that remains is the plumbing to connect your domain, relay, and Nostr clients together.

**Configure DNS**

First, configure your domain. At a high level –

1. Get your domain (buy one if you need to)
2. Get the IP address of your VPS
3. In your domain's DNS settings add those records as an A record to the subdomain of your choice, e.g. `relay` as in `relay.your_domain_name.com`, or in my case `relay.rodbishop.nz`

Your subdomain now points to your server.

**Configure reverse proxy**

Next, you need to redirect traffic from your subdomain to your relay at port `3355`.

On my VPS I use Caddy as a reverse proxy for a few projects, I have it sitting in a separate Docker network. To use it for my HAVEN Relay required two steps. I am sure that the way I do this is not very elegant, but it worked. If you prefer a different method, the HAVEN readme also comes with instructions on how to perform a similar setup using nginx.

For my method, my steps were as follows:

1. Add configuration to Caddy's `Caddyfile` to tell it what to do with requests for the `relay.rodbishop.nz` subdomain
2. Add the Caddy Docker network to the HAVEN `docker-compose.yml` to make it be part of the Caddy network

For the addition to the `Caddyfile`, I used as follows:

```
relay.rodbishop.nz {
reverse_proxy haven-relay:3355 {
header_up X-Forwarded-For {remote}
header_up X-Forwarded-Proto {scheme}
header_up X-Forwarded-Port {server_port}
}
}
```

For the addition to the `docker-compose.yml`, I used as follows:

```
networks:
- caddy # Added this line to services to connect to the Caddy network

networks:
caddy:
external: true # Added this to section specify the Caddy network
```

Once your DNS configuration and reverse proxy setup are completed, you should now be able to access your Nostr client at `relay.your_domain_name.com`. For my set up, this was `relay.rodbishop.nz`.

**Connecting your Nostr client**

Most Nostr clients allow you to specify any relay you choose. My go-to client at the moment is Amethyst on Android. Amethyst allows you to specify discrete relays for each role in the outbox model which ties up very neatly with HAVEN.

- In the sidebar, select Relays
- For "Public Outbox/Home Relays" enter `relay.your_domain_name.com`
- For "Public Inbox Relays" enter `relay.your_domain_name.com/inbox`
- For "DM Inbox Relays" enter `relay.your_domain_name.com/chat`
- For "Private Home Relays" enter `relay.your_domain_name.com/private`
- Click Save to broadcast your new relays to the Nostr network.

Your new relay configuration is now live.

**Testing your relay**

Lastly, it's time to test. Amethyst provides a simple method to test this as it allows you to configure the relays used on each post.

- Create a test note, and then before you post it, edit your relays using the icon at the top
- Turn off all relays except your own outbox relay, and post the note
- Access your HAVEN docker logs with `docker logs haven-relay` and see if there is a log to indicate if the note was received and blasted to other public relays
- Copy the `nevent` of the note, and attempt to find it in another client

If you're in luck, you may see something like this (the blasted note, and then users on the network responding to the note in turn).

```
2024/10/22 00:12:23 🔫 blasted 95c477af7e6b612bf5d1d94309d2d57377a0a67d2181cfbb42a2e3fbc0feeaaf to 26 relays
2024/10/22 00:13:50 🤙 new reaction in your inbox
2024/10/22 00:14:42 🫂 new reaction in your inbox
2024/10/22 00:14:45 ✅ new reaction in your inbox
2024/10/22 00:15:12 💜 new reaction in your inbox
2024/10/22 00:17:03 ✅ new reaction in your inbox
2024/10/22 00:17:03 🫂 new reaction in your inbox
2024/10/22 00:17:55 🫂 new reaction in your inbox
2024/10/22 00:19:02 📰 new note in your inbox
```

That's it. If you followed this successfully your personal relay is up and running.

#### What I did wrong so you don't have to

**My first relay was too public**

This blog comes after much trial and error. The first error I made was I set up a relay to use as a personal relay, but without any restrictions on use. I very quickly found other people discovered and started using my relay to save their own notes! This was unintended and I had to take it down.

**Unfamiliar with Go language**

I am mostly non-technical, and completely unfamiliar with Go. I got the project up and running with Go on my localhost–with a lot of help from my AI–but I then completely failed in migrating this to my VPS. Moving to Docker made the difference for me here.

**I failed a few times due to a messy folder**

After messing with Go, I moved to the Docker setup, but I started my work from a messy folder which contained remnants of the Go build, which caused various failures. Deleting the folder and cloning again from scratch solved the issue.

**Trouble with Nostr.wine**

I subscribe to the Nostr.wine paid relay, and I initially added it to the list of relays in my blaster. However, it didn't work, and the logs showed an error as follows

```
CLOSED from wss://nostr.wine: 'auth-required: this relay only serves private notes to authenticated users'
```

It seems my npub's subscription to Nostr.wine is not enough for it to permit my relay to blast notes to it. In the end, I removed Nostr.wine from my relay config, and kept Nostr.wine as a separate entry in my Client's outbox settings.

**Failed to create web of trust graph**

When I first launched the relay on my VPS, HAVEN failed to complete the Web of Trust graph, with a log that looked as follows (note the zeroes). As a result, no one would have been able to send me DM's to my Chat relay (it would flag every message as spam).

```
2024/10/14 12:02:08 🌐 building web of trust graph
2024/10/14 12:02:16 🫂 total network size: 0
2024/10/14 12:02:16 🔗 relays discovered: 0
2024/10/14 12:02:17 🌐 pubkeys with minimum followers: 0 keys
```

I never got to the bottom of why this was. In the process of trying to fix it I rebuild the container, and on the rebuild it spontaneously worked. Accordingly my lesson learned is "if in doubt, turn if off and on again".

**Failed to run --import function**

HAVEN comes with a function to import all your old notes from other public relays to your own outbox relay. When I run it I get an error as follows:

```
panic: Cannot acquire directory lock on "db/private". Another process is using this Badger database. error: resource temporarily unavailable
```

I have yet to work out the solution for this, and will update this note when I do so!

### What's Next?

Over the past four blogs I have

- [Mined a Nostr pubkey and backed up the mnemonic](naddr1qq…2ekw)
- [Set up Nostr payments with a Lightning wallet plus all the bells and whistles](naddr1qq…l6je)
- [Set up NIP-05 and Lighting Address at my own domain](naddr1qq…4nh0)
- Set up a Personal Relay at my own domain

This feels like a very comprehensive personal set up now. Also, I have uncovered some new rabbit holes and feel like I have some projects to tackle. Perhaps one of these?

- Set up a personal homepage with my Nostr feed to round-out my rodbishop.nz domain
- Experiment with different signers like Amber and Nsec.app and NFC cards
- Set up a paid relay for #austriches (Australians and Kiwis on Nostr)
- Set up a team relay to experiment with Nostr for business or community projects
- Or something else ... ?

Please be sure to let me know if you think there's another Nostr topic you'd like to see me tackle.

Pura vida Nostr.
Author Public Key
npub1tf6pddzrnr5c6gz9ufg4gfu0thkgn7d7j7x3vx52940nkzat8mashvv4pu