disable reaction archiving, use map to allow posting

This commit is contained in:
Barry Deen 2024-09-22 14:08:09 -04:00
parent 3ceeaf77da
commit 46ec59996e
3 changed files with 49 additions and 24 deletions

View File

@ -21,6 +21,7 @@ MINIMUM_FOLLOWERS=5
# archive all notes from everyone in your WoT from other relays # archive all notes from everyone in your WoT from other relays
ARCHIVAL_SYNC="FALSE" 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 # optional, certain note kinds older than this many days will be deleted
MAX_AGE_DAYS=365 MAX_AGE_DAYS=365

View File

@ -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://satsage.xyz](https://satsage.xyz)
- [wss://wons.calva.dev](https://wons.calva.dev) - [wss://wons.calva.dev](https://wons.calva.dev)
## Prerequisites ## Prerequisites
- **Go**: Ensure you have Go installed on your system. You can download it from [here](https://golang.org/dl/). - **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 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 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) 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 ### 4. Build the project
@ -73,7 +73,7 @@ go build -ldflags "-X main.version=$(git describe --tags --always)"
### 5. Create a Systemd Service (optional) ### 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: 1. Create the file:
@ -89,9 +89,10 @@ Description=WOT Relay Service
After=network.target After=network.target
[Service] [Service]
ExecStart=/home/ubuntu/wot-relay/wot-relay #change this to your path ExecStart=/home/ubuntu/wot-relay/wot-relay
WorkingDirectory=/home/ubuntu/wot-relay #change this to your path WorkingDirectory=/home/ubuntu/wot-relay
Restart=always Restart=always
MemoryLimit=2G
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

35
main.go
View File

@ -36,6 +36,7 @@ type Config struct {
RelayContact string RelayContact string
RelayIcon string RelayIcon string
MaxAgeDays int MaxAgeDays int
ArchiveReactions bool
} }
var pool *nostr.SimplePool var pool *nostr.SimplePool
@ -112,12 +113,10 @@ func main() {
relay.QueryEvents = append(relay.QueryEvents, db.QueryEvents) relay.QueryEvents = append(relay.QueryEvents, db.QueryEvents)
relay.DeleteEvent = append(relay.DeleteEvent, db.DeleteEvent) relay.DeleteEvent = append(relay.DeleteEvent, db.DeleteEvent)
relay.RejectEvent = append(relay.RejectEvent, func(ctx context.Context, event *nostr.Event) (bool, string) { relay.RejectEvent = append(relay.RejectEvent, func(ctx context.Context, event *nostr.Event) (bool, string) {
for _, pk := range trustNetwork { if !trustNetworkMap[event.PubKey] {
if pk == event.PubKey {
return false, ""
}
}
return true, "you are not in the web of trust" return true, "you are not in the web of trust"
}
return false, ""
}) })
seedRelays = []string{ seedRelays = []string{
@ -201,6 +200,10 @@ func LoadConfig() Config {
os.Setenv("MAX_AGE_DAYS", "0") os.Setenv("MAX_AGE_DAYS", "0")
} }
if os.Getenv("ARCHIVE_REACTIONS") == "" {
os.Setenv("ARCHIVE_REACTIONS", "FALSE")
}
minimumFollowers, _ := strconv.Atoi(os.Getenv("MINIMUM_FOLLOWERS")) minimumFollowers, _ := strconv.Atoi(os.Getenv("MINIMUM_FOLLOWERS"))
maxAgeDays, _ := strconv.Atoi(os.Getenv("MAX_AGE_DAYS")) maxAgeDays, _ := strconv.Atoi(os.Getenv("MAX_AGE_DAYS"))
@ -218,6 +221,7 @@ func LoadConfig() Config {
MinimumFollowers: minimumFollowers, MinimumFollowers: minimumFollowers,
ArchivalSync: getEnv("ARCHIVAL_SYNC") == "TRUE", ArchivalSync: getEnv("ARCHIVAL_SYNC") == "TRUE",
MaxAgeDays: maxAgeDays, MaxAgeDays: maxAgeDays,
ArchiveReactions: getEnv("ARCHIVE_REACTIONS") == "TRUE",
} }
return config return config
@ -377,7 +381,10 @@ func archiveTrustedNotes(ctx context.Context, relay *khatru.Relay) {
if config.ArchivalSync { if config.ArchivalSync {
go refreshProfiles(ctx) go refreshProfiles(ctx)
filters := []nostr.Filter{{ var filters []nostr.Filter
if config.ArchiveReactions {
filters = []nostr.Filter{{
Kinds: []int{ Kinds: []int{
nostr.KindArticle, nostr.KindArticle,
nostr.KindDeletion, nostr.KindDeletion,
@ -392,6 +399,22 @@ func archiveTrustedNotes(ctx context.Context, relay *khatru.Relay) {
nostr.KindTextNote, 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...") log.Println("📦 archiving trusted notes...")