sdk: track query attempts automatically and other small tweaks to replaceable fetching and stuff.

This commit is contained in:
fiatjaf
2024-12-24 00:15:10 -03:00
parent 3b3d5cce7b
commit 95ddacb9f3
4 changed files with 74 additions and 15 deletions

View File

@@ -2,6 +2,7 @@ package sdk
import (
"context"
"math/rand/v2"
"github.com/fiatjaf/eventstore"
"github.com/fiatjaf/eventstore/nullstore"
@@ -10,7 +11,7 @@ import (
"github.com/nbd-wtf/go-nostr/sdk/cache"
cache_memory "github.com/nbd-wtf/go-nostr/sdk/cache/memory"
"github.com/nbd-wtf/go-nostr/sdk/hints"
memory_hints "github.com/nbd-wtf/go-nostr/sdk/hints/memory"
"github.com/nbd-wtf/go-nostr/sdk/hints/memoryh"
)
type System struct {
@@ -43,7 +44,7 @@ type RelayStream struct {
}
func NewRelayStream(urls ...string) *RelayStream {
return &RelayStream{URLs: urls, serial: -1}
return &RelayStream{URLs: urls, serial: rand.Int()}
}
func (rs *RelayStream) Next() string {
@@ -82,12 +83,13 @@ func NewSystem(mods ...SystemModifier) *System {
"wss://relay.nostr.band",
"wss://search.nos.today",
),
Hints: memory_hints.NewHintDB(),
Hints: memoryh.NewHintDB(),
outboxShortTermCache: cache_memory.New32[[]string](1000),
}
sys.Pool = nostr.NewSimplePool(context.Background(),
nostr.WithQueryMiddleware(sys.TrackQueryAttempts),
nostr.WithEventMiddleware(sys.TrackEventHints),
nostr.WithPenaltyBox(),
)