Skip to content

Commit

Permalink
Remove nostr.band
Browse files Browse the repository at this point in the history
  • Loading branch information
dcadenas committed Apr 30, 2024
1 parent 6b53760 commit 3e4ccc8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
44 changes: 39 additions & 5 deletions service/domain/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package downloader
import (
"context"
"fmt"
"strings"
"sync"
"time"

Expand All @@ -19,6 +20,11 @@ const (
refreshKnownRelaysEvery = 1 * time.Minute
)

var relaySuffixesToSkip = []string{
"relay.nos.social",
"nostr.band",
}

var (
globalEventKindsToDownload = []domain.EventKind{
domain.EventKindMetadata,
Expand Down Expand Up @@ -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()

Expand All @@ -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()).
Expand All @@ -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]()

Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions service/domain/relays/bootstrap_relay_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}

Expand Down

0 comments on commit 3e4ccc8

Please sign in to comment.