From 3e4ccc8d04c0654c4a338ef885fb26c10a714a8a Mon Sep 17 00:00:00 2001 From: Daniel Cadenas Date: Tue, 30 Apr 2024 11:21:12 -0300 Subject: [PATCH] Remove nostr.band --- service/domain/downloader/downloader.go | 44 ++++++++++++++++--- .../domain/relays/bootstrap_relay_source.go | 4 +- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/service/domain/downloader/downloader.go b/service/domain/downloader/downloader.go index 4783964..b6126f0 100644 --- a/service/domain/downloader/downloader.go +++ b/service/domain/downloader/downloader.go @@ -3,6 +3,7 @@ package downloader import ( "context" "fmt" + "strings" "sync" "time" @@ -19,6 +20,11 @@ const ( refreshKnownRelaysEvery = 1 * time.Minute ) +var relaySuffixesToSkip = []string{ + "relay.nos.social", + "nostr.band", +} + var ( globalEventKindsToDownload = []domain.EventKind{ domain.EventKindMetadata, @@ -178,9 +184,6 @@ func (d *Downloader) updateDownloaders(ctx context.Context) error { return errors.Wrap(err, "error getting relays") } - // Test if removing the relay for reads solves the timeout issue - relays.Delete(domain.MustNewRelayAddress("wss://relay.nos.social")) - d.relayDownloadersLock.Lock() defer d.relayDownloadersLock.Unlock() @@ -198,6 +201,7 @@ func (d *Downloader) updateDownloaders(ctx context.Context) error { for _, relayAddress := range relays.List() { if _, ok := d.relayDownloaders[relayAddress]; !ok { + d.logger. Trace(). WithField("address", relayAddress.String()). @@ -224,7 +228,8 @@ func (d *Downloader) updateDownloaders(ctx context.Context) error { return nil } -// Get the bootstrap relays and those already in the database. +// Get the bootstrap relays and those already in the database skipping those in +// relaySuffixesToSkip. func (d *Downloader) getRelays(ctx context.Context) (*internal.Set[domain.RelayAddress], error) { result := internal.NewEmptySet[domain.RelayAddress]() @@ -238,11 +243,40 @@ func (d *Downloader) getRelays(ctx context.Context) (*internal.Set[domain.RelayA if err != nil { return nil, errors.Wrap(err, "error getting relays") } - result.PutMany(databaseRelays) + + filteredDatabaseRelays := filter(databaseRelays, func(s domain.RelayAddress) bool { + return endsWithAny(s.HostWithoutPort(), relaySuffixesToSkip) + }) + + result.PutMany(filteredDatabaseRelays) return result, nil } +// filter applies a predicate function to each element in the input slice and +// returns a new slice containing only elements that do not satisfy the +// predicate. +func filter[T any](slice []T, predicate func(T) bool) []T { + var result []T + for _, item := range slice { + if !predicate(item) { + result = append(result, item) + } + } + return result +} + +// endsWithAny checks if the given string ends with any of the strings in the +// list. +func endsWithAny(s string, list []string) bool { + for _, suffix := range list { + if strings.HasSuffix(s, suffix) { + return true + } + } + return false +} + type runningRelayDownloader struct { Context context.Context CancelFunc context.CancelFunc diff --git a/service/domain/relays/bootstrap_relay_source.go b/service/domain/relays/bootstrap_relay_source.go index ac81832..0adc120 100644 --- a/service/domain/relays/bootstrap_relay_source.go +++ b/service/domain/relays/bootstrap_relay_source.go @@ -8,14 +8,12 @@ import ( ) var bootstrapRelayAddresses = []domain.RelayAddress{ - domain.MustNewRelayAddress("wss://relay.nostr.band"), domain.MustNewRelayAddress("wss://relay.damus.io"), domain.MustNewRelayAddress("wss://nos.lol"), domain.MustNewRelayAddress("wss://e.nos.lol"), domain.MustNewRelayAddress("wss://purplepag.es"), domain.MustNewRelayAddress("wss://relay.current.fyi"), - domain.MustNewRelayAddress("wss://relay.nos.social"), - domain.MustNewRelayAddress("wss://relayable.org"), + domain.MustNewRelayAddress("wss://brb.io"), domain.MustNewRelayAddress("wss://relay.snort.social"), }