Skip to content

Commit

Permalink
Merge pull request #64 from bitvora/dev-disableReactions
Browse files Browse the repository at this point in the history
disable reaction archiving, use map to allow posting
  • Loading branch information
barrydeen authored Sep 22, 2024
2 parents 3ceeaf7 + 46ec599 commit e768390
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 24 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
Expand Down Expand Up @@ -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
Expand All @@ -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:

Expand All @@ -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
Expand Down
63 changes: 43 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Config struct {
RelayContact string
RelayIcon string
MaxAgeDays int
ArchiveReactions bool
}

var pool *nostr.SimplePool
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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"))

Expand All @@ -218,6 +221,7 @@ func LoadConfig() Config {
MinimumFollowers: minimumFollowers,
ArchivalSync: getEnv("ARCHIVAL_SYNC") == "TRUE",
MaxAgeDays: maxAgeDays,
ArchiveReactions: getEnv("ARCHIVE_REACTIONS") == "TRUE",
}

return config
Expand Down Expand Up @@ -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...")

Expand Down

0 comments on commit e768390

Please sign in to comment.