diff --git a/.env.example b/.env.example index 42554d8..5473baf 100644 --- a/.env.example +++ b/.env.example @@ -21,6 +21,7 @@ MINIMUM_FOLLOWERS=5 # archive all notes from everyone in your WoT from other relays ARCHIVAL_SYNC="FALSE" +ARCHIVE_REACTIONS="FALSE" # optional, reactions take up a lot of space and compute # optional, certain note kinds older than this many days will be deleted MAX_AGE_DAYS=365 \ No newline at end of file diff --git a/README.md b/README.md index 41835b0..e65e23e 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@ Don't want to run the relay, just want to connect to some? Here are some availab - [wss://satsage.xyz](https://satsage.xyz) - [wss://wons.calva.dev](https://wons.calva.dev) - ## Prerequisites - **Go**: Ensure you have Go installed on your system. You can download it from [here](https://golang.org/dl/). @@ -61,6 +60,7 @@ STATIC_PATH="/home/ubuntu/wot-relay/templates/static" # path to the static folde REFRESH_INTERVAL_HOURS=24 # interval in hours to refresh the web of trust MINIMUM_FOLLOWERS=3 #how many followers before they're allowed in the WoT ARCHIVAL_SYNC="FALSE" # set to TRUE to archive every note from every person in the WoT (not recommended) +ARCHIVE_REACTIONS="FALSE" # set to TRUE to archive every reaction from every person in the WoT (not recommended) ``` ### 4. Build the project @@ -73,7 +73,7 @@ go build -ldflags "-X main.version=$(git describe --tags --always)" ### 5. Create a Systemd Service (optional) -To have the relay run as a service, create a systemd unit file. Here's an example: +To have the relay run as a service, create a systemd unit file. Make sure to limit the memory usage to less than your system's total memory to prevent the relay from crashing the system. 1. Create the file: @@ -89,9 +89,10 @@ Description=WOT Relay Service After=network.target [Service] -ExecStart=/home/ubuntu/wot-relay/wot-relay #change this to your path -WorkingDirectory=/home/ubuntu/wot-relay #change this to your path +ExecStart=/home/ubuntu/wot-relay/wot-relay +WorkingDirectory=/home/ubuntu/wot-relay Restart=always +MemoryLimit=2G [Install] WantedBy=multi-user.target diff --git a/main.go b/main.go index 8be5019..954c7ad 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,7 @@ type Config struct { RelayContact string RelayIcon string MaxAgeDays int + ArchiveReactions bool } var pool *nostr.SimplePool @@ -112,12 +113,10 @@ func main() { relay.QueryEvents = append(relay.QueryEvents, db.QueryEvents) relay.DeleteEvent = append(relay.DeleteEvent, db.DeleteEvent) relay.RejectEvent = append(relay.RejectEvent, func(ctx context.Context, event *nostr.Event) (bool, string) { - for _, pk := range trustNetwork { - if pk == event.PubKey { - return false, "" - } + if !trustNetworkMap[event.PubKey] { + return true, "you are not in the web of trust" } - return true, "you are not in the web of trust" + return false, "" }) seedRelays = []string{ @@ -201,6 +200,10 @@ func LoadConfig() Config { os.Setenv("MAX_AGE_DAYS", "0") } + if os.Getenv("ARCHIVE_REACTIONS") == "" { + os.Setenv("ARCHIVE_REACTIONS", "FALSE") + } + minimumFollowers, _ := strconv.Atoi(os.Getenv("MINIMUM_FOLLOWERS")) maxAgeDays, _ := strconv.Atoi(os.Getenv("MAX_AGE_DAYS")) @@ -218,6 +221,7 @@ func LoadConfig() Config { MinimumFollowers: minimumFollowers, ArchivalSync: getEnv("ARCHIVAL_SYNC") == "TRUE", MaxAgeDays: maxAgeDays, + ArchiveReactions: getEnv("ARCHIVE_REACTIONS") == "TRUE", } return config @@ -377,21 +381,40 @@ func archiveTrustedNotes(ctx context.Context, relay *khatru.Relay) { if config.ArchivalSync { go refreshProfiles(ctx) - filters := []nostr.Filter{{ - Kinds: []int{ - nostr.KindArticle, - nostr.KindDeletion, - nostr.KindContactList, - nostr.KindEncryptedDirectMessage, - nostr.KindMuteList, - nostr.KindReaction, - nostr.KindRelayListMetadata, - nostr.KindRepost, - nostr.KindZapRequest, - nostr.KindZap, - nostr.KindTextNote, - }, - }} + var filters []nostr.Filter + if config.ArchiveReactions { + + filters = []nostr.Filter{{ + Kinds: []int{ + nostr.KindArticle, + nostr.KindDeletion, + nostr.KindContactList, + nostr.KindEncryptedDirectMessage, + nostr.KindMuteList, + nostr.KindReaction, + nostr.KindRelayListMetadata, + nostr.KindRepost, + nostr.KindZapRequest, + nostr.KindZap, + nostr.KindTextNote, + }, + }} + } else { + filters = []nostr.Filter{{ + Kinds: []int{ + nostr.KindArticle, + nostr.KindDeletion, + nostr.KindContactList, + nostr.KindEncryptedDirectMessage, + nostr.KindMuteList, + nostr.KindRelayListMetadata, + nostr.KindRepost, + nostr.KindZapRequest, + nostr.KindZap, + nostr.KindTextNote, + }, + }} + } log.Println("📦 archiving trusted notes...")