option to run relay without syncing from other relays

This commit is contained in:
Barry Deen 2024-09-16 21:54:16 -04:00
parent 02fc217510
commit aae474531f

27
main.go
View File

@ -28,6 +28,7 @@ type Config struct {
StaticPath string StaticPath string
RefreshInterval int RefreshInterval int
MinimumFollowers int MinimumFollowers int
ArchivalSync bool
} }
var pool *nostr.SimplePool var pool *nostr.SimplePool
@ -172,6 +173,10 @@ func LoadConfig() Config {
os.Setenv("MINIMUM_FOLLOWERS", "1") os.Setenv("MINIMUM_FOLLOWERS", "1")
} }
if os.Getenv("ARCHIVAL_SYNC") == "" {
os.Setenv("ARCHIVAL_SYNC", "TRUE")
}
minimumFollowers, _ := strconv.Atoi(os.Getenv("MINIMUM_FOLLOWERS")) minimumFollowers, _ := strconv.Atoi(os.Getenv("MINIMUM_FOLLOWERS"))
config := Config{ config := Config{
@ -184,6 +189,7 @@ func LoadConfig() Config {
StaticPath: getEnv("STATIC_PATH"), StaticPath: getEnv("STATIC_PATH"),
RefreshInterval: refreshInterval, RefreshInterval: refreshInterval,
MinimumFollowers: minimumFollowers, MinimumFollowers: minimumFollowers,
ArchivalSync: getEnv("ARCHIVAL_SYNC") == "TRUE",
} }
return config return config
@ -335,6 +341,11 @@ func appendOneHopNetwork(pubkey string) {
func archiveTrustedNotes(ctx context.Context, relay *khatru.Relay) { func archiveTrustedNotes(ctx context.Context, relay *khatru.Relay) {
timeout, cancel := context.WithTimeout(ctx, time.Duration(config.RefreshInterval)*time.Hour) timeout, cancel := context.WithTimeout(ctx, time.Duration(config.RefreshInterval)*time.Hour)
defer cancel() defer cancel()
done := make(chan struct{})
go func() {
if config.ArchivalSync {
go refreshProfiles(ctx) go refreshProfiles(ctx)
filters := []nostr.Filter{{ filters := []nostr.Filter{{
@ -360,6 +371,22 @@ func archiveTrustedNotes(ctx context.Context, relay *khatru.Relay) {
} }
log.Println("📦 archived", trustedNotes, "trusted notes and discarded", untrustedNotes, "untrusted notes") log.Println("📦 archived", trustedNotes, "trusted notes and discarded", untrustedNotes, "untrusted notes")
} else {
log.Println("🔄 web of trust will refresh in", config.RefreshInterval, "hours")
select {
case <-timeout.Done():
}
}
close(done)
}()
select {
case <-timeout.Done():
log.Println("restarting process")
case <-done:
log.Println("📦 archiving process completed")
}
} }
func archiveEvent(ctx context.Context, relay *khatru.Relay, ev nostr.Event) { func archiveEvent(ctx context.Context, relay *khatru.Relay, ev nostr.Event) {