diff --git a/cmd/replicatrd/replicatr/adding.go b/cmd/replicatrd/replicatr/adding.go index f6cf096a..65b2b9d4 100644 --- a/cmd/replicatrd/replicatr/adding.go +++ b/cmd/replicatrd/replicatr/adding.go @@ -31,7 +31,7 @@ func (rl *Relay) AddEvent(ctx context.Context, evt *nostr.Event) error { if evt.Kind == 0 || evt.Kind == 3 || (10000 <= evt.Kind && evt.Kind < 20000) { // replaceable event, delete before storing for _, query := range rl.QueryEvents { - ch, err := query(ctx, nostr.Filter{Authors: []string{evt.PubKey}, Kinds: []int{evt.Kind}}) + ch, err := query(ctx, &nostr.Filter{Authors: []string{evt.PubKey}, Kinds: []int{evt.Kind}}) if err != nil { continue } @@ -46,7 +46,7 @@ func (rl *Relay) AddEvent(ctx context.Context, evt *nostr.Event) error { d := evt.Tags.GetFirst([]string{"d", ""}) if d != nil { for _, query := range rl.QueryEvents { - ch, err := query(ctx, nostr.Filter{Authors: []string{evt.PubKey}, Kinds: []int{evt.Kind}, Tags: nostr.TagMap{"d": []string{d.Value()}}}) + ch, err := query(ctx, &nostr.Filter{Authors: []string{evt.PubKey}, Kinds: []int{evt.Kind}, Tags: nostr.TagMap{"d": []string{d.Value()}}}) if err != nil { continue } diff --git a/cmd/replicatrd/replicatr/deleting.go b/cmd/replicatrd/replicatr/deleting.go index 391b44ec..62573063 100644 --- a/cmd/replicatrd/replicatr/deleting.go +++ b/cmd/replicatrd/replicatr/deleting.go @@ -13,7 +13,7 @@ func (rl *Relay) handleDeleteRequest(ctx context.Context, evt *nostr.Event) erro if len(tag) >= 2 && tag[0] == "e" { // first we fetch the event for _, query := range rl.QueryEvents { - ch, err := query(ctx, nostr.Filter{IDs: []string{tag[1]}}) + ch, err := query(ctx, &nostr.Filter{IDs: []string{tag[1]}}) if err != nil { continue } diff --git a/cmd/replicatrd/replicatr/handlers.go b/cmd/replicatrd/replicatr/handlers.go index 22c062a1..89a127c3 100644 --- a/cmd/replicatrd/replicatr/handlers.go +++ b/cmd/replicatrd/replicatr/handlers.go @@ -160,7 +160,7 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) { } var total int64 for _, filter := range env.Filters { - total += rl.handleCountRequest(ctx, ws, filter) + total += rl.handleCountRequest(ctx, ws, &filter) } ws.WriteJSON(nostr.CountEnvelope{SubscriptionID: env.SubscriptionID, Count: &total}) case *nostr.ReqEnvelope: @@ -175,7 +175,7 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) { // handle each filter separately -- dispatching events as they're loaded from databases for _, filter := range env.Filters { - err := rl.handleRequest(reqCtx, env.SubscriptionID, &eose, ws, filter) + err := rl.handleRequest(reqCtx, env.SubscriptionID, &eose, ws, &filter) if err != nil { // fail everything if any filter is rejected reason := err.Error() diff --git a/cmd/replicatrd/replicatr/relay.go b/cmd/replicatrd/replicatr/relay.go index 4c7adfb1..c1588a12 100644 --- a/cmd/replicatrd/replicatr/relay.go +++ b/cmd/replicatrd/replicatr/relay.go @@ -48,8 +48,8 @@ func NewRelay(appName string) *Relay { type Relay struct { ServiceURL string RejectEvent []func(ctx context.Context, event *nostr.Event) (reject bool, msg string) - RejectFilter []func(ctx context.Context, filter nostr.Filter) (reject bool, msg string) - RejectCountFilter []func(ctx context.Context, filter nostr.Filter) (reject bool, msg string) + RejectFilter []func(ctx context.Context, filter *nostr.Filter) (reject bool, msg string) + RejectCountFilter []func(ctx context.Context, filter *nostr.Filter) (reject bool, msg string) OverwriteDeletionOutcome []func(ctx context.Context, target *nostr.Event, deletion *nostr.Event) (acceptDeletion bool, msg string) OverwriteResponseEvent []func(ctx context.Context, event *nostr.Event) OverwriteFilter []func(ctx context.Context, filter *nostr.Filter) @@ -57,8 +57,8 @@ type Relay struct { OverwriteRelayInformation []func(ctx context.Context, r *http.Request, info nip11.RelayInformationDocument) nip11.RelayInformationDocument StoreEvent []func(ctx context.Context, event *nostr.Event) error DeleteEvent []func(ctx context.Context, event *nostr.Event) error - QueryEvents []func(ctx context.Context, filter nostr.Filter) (chan *nostr.Event, error) - CountEvents []func(ctx context.Context, filter nostr.Filter) (int64, error) + QueryEvents []func(ctx context.Context, filter *nostr.Filter) (chan *nostr.Event, error) + CountEvents []func(ctx context.Context, filter *nostr.Filter) (int64, error) OnConnect []func(ctx context.Context) OnDisconnect []func(ctx context.Context) OnEventSaved []func(ctx context.Context, event *nostr.Event) diff --git a/cmd/replicatrd/replicatr/responding.go b/cmd/replicatrd/replicatr/responding.go index 96ad0ab8..32796c45 100644 --- a/cmd/replicatrd/replicatr/responding.go +++ b/cmd/replicatrd/replicatr/responding.go @@ -8,13 +8,13 @@ import ( "github.com/nbd-wtf/go-nostr" ) -func (rl *Relay) handleRequest(ctx context.Context, id string, eose *sync.WaitGroup, ws *WebSocket, filter nostr.Filter) error { +func (rl *Relay) handleRequest(ctx context.Context, id string, eose *sync.WaitGroup, ws *WebSocket, filter *nostr.Filter) error { defer eose.Done() // overwrite the filter (for example, to eliminate some kinds or // that we know we don't support) for _, ovw := range rl.OverwriteFilter { - ovw(ctx, &filter) + ovw(ctx, filter) } if filter.Limit < 0 { @@ -57,10 +57,10 @@ func (rl *Relay) handleRequest(ctx context.Context, id string, eose *sync.WaitGr return nil } -func (rl *Relay) handleCountRequest(ctx context.Context, ws *WebSocket, filter nostr.Filter) int64 { +func (rl *Relay) handleCountRequest(ctx context.Context, ws *WebSocket, filter *nostr.Filter) int64 { // overwrite the filter (for example, to eliminate some kinds or tags that we know we don't support) for _, ovw := range rl.OverwriteCountFilter { - ovw(ctx, &filter) + ovw(ctx, filter) } // then check if we'll reject this filter diff --git a/pkg/eventstore/badger/count.go b/pkg/eventstore/badger/count.go index 3e1d77e4..4f050b7e 100644 --- a/pkg/eventstore/badger/count.go +++ b/pkg/eventstore/badger/count.go @@ -10,7 +10,7 @@ import ( nostr_binary "github.com/nbd-wtf/go-nostr/binary" ) -func (b BadgerBackend) CountEvents(ctx context.Context, filter nostr.Filter) (int64, error) { +func (b BadgerBackend) CountEvents(ctx context.Context, filter *nostr.Filter) (int64, error) { var count int64 = 0 queries, extraFilter, since, err := prepareQueries(filter) diff --git a/pkg/eventstore/badger/query.go b/pkg/eventstore/badger/query.go index c1ffaa98..a22f9835 100644 --- a/pkg/eventstore/badger/query.go +++ b/pkg/eventstore/badger/query.go @@ -26,7 +26,7 @@ type queryEvent struct { query int } -func (b BadgerBackend) QueryEvents(ctx context.Context, filter nostr.Filter) (chan *nostr.Event, error) { +func (b BadgerBackend) QueryEvents(ctx context.Context, filter *nostr.Filter) (chan *nostr.Event, error) { ch := make(chan *nostr.Event) queries, extraFilter, since, err := prepareQueries(filter) @@ -192,7 +192,7 @@ func (pq *priorityQueue) Pop() any { return item } -func prepareQueries(filter nostr.Filter) ( +func prepareQueries(filter *nostr.Filter) ( queries []query, extraFilter *nostr.Filter, since uint32, diff --git a/pkg/eventstore/relay_interface.go b/pkg/eventstore/relay_interface.go index ac4a925c..0df9e816 100644 --- a/pkg/eventstore/relay_interface.go +++ b/pkg/eventstore/relay_interface.go @@ -9,8 +9,8 @@ import ( // RelayInterface is a wrapper thing that unifies Store and nostr.Relay under a common API. type RelayInterface interface { - Publish(ctx context.Context, event nostr.Event) error - QuerySync(ctx context.Context, filter nostr.Filter, opts ...nostr.SubscriptionOption) ([]*nostr.Event, error) + Publish(ctx context.Context, event *nostr.Event) error + QuerySync(ctx context.Context, filter *nostr.Filter, opts ...nostr.SubscriptionOption) ([]*nostr.Event, error) } type RelayWrapper struct { @@ -19,17 +19,17 @@ type RelayWrapper struct { var _ RelayInterface = (*RelayWrapper)(nil) -func (w RelayWrapper) Publish(ctx context.Context, evt nostr.Event) error { +func (w RelayWrapper) Publish(ctx context.Context, evt *nostr.Event) error { if 20000 <= evt.Kind && evt.Kind < 30000 { // do not store ephemeral events return nil } else if evt.Kind == 0 || evt.Kind == 3 || (10000 <= evt.Kind && evt.Kind < 20000) { // replaceable event, delete before storing - ch, err := w.Store.QueryEvents(ctx, nostr.Filter{Authors: []string{evt.PubKey}, Kinds: []int{evt.Kind}}) + ch, err := w.Store.QueryEvents(ctx, &nostr.Filter{Authors: []string{evt.PubKey}, Kinds: []int{evt.Kind}}) if err != nil { return fmt.Errorf("failed to query before replacing: %w", err) } - if previous := <-ch; previous != nil && isOlder(previous, &evt) { + if previous := <-ch; previous != nil && isOlder(previous, evt) { if err := w.Store.DeleteEvent(ctx, previous); err != nil { return fmt.Errorf("failed to delete event for replacing: %w", err) } @@ -38,11 +38,11 @@ func (w RelayWrapper) Publish(ctx context.Context, evt nostr.Event) error { // parameterized replaceable event, delete before storing d := evt.Tags.GetFirst([]string{"d", ""}) if d != nil { - ch, err := w.Store.QueryEvents(ctx, nostr.Filter{Authors: []string{evt.PubKey}, Kinds: []int{evt.Kind}, Tags: nostr.TagMap{"d": []string{d.Value()}}}) + ch, err := w.Store.QueryEvents(ctx, &nostr.Filter{Authors: []string{evt.PubKey}, Kinds: []int{evt.Kind}, Tags: nostr.TagMap{"d": []string{d.Value()}}}) if err != nil { return fmt.Errorf("failed to query before parameterized replacing: %w", err) } - if previous := <-ch; previous != nil && isOlder(previous, &evt) { + if previous := <-ch; previous != nil && isOlder(previous, evt) { if err := w.Store.DeleteEvent(ctx, previous); err != nil { return fmt.Errorf("failed to delete event for parameterized replacing: %w", err) } @@ -50,14 +50,14 @@ func (w RelayWrapper) Publish(ctx context.Context, evt nostr.Event) error { } } - if err := w.SaveEvent(ctx, &evt); err != nil && err != ErrDupEvent { + if err := w.SaveEvent(ctx, evt); err != nil && err != ErrDupEvent { return fmt.Errorf("failed to save: %w", err) } return nil } -func (w RelayWrapper) QuerySync(ctx context.Context, filter nostr.Filter, opts ...nostr.SubscriptionOption) ([]*nostr.Event, error) { +func (w RelayWrapper) QuerySync(ctx context.Context, filter *nostr.Filter, opts ...nostr.SubscriptionOption) ([]*nostr.Event, error) { ch, err := w.Store.QueryEvents(ctx, filter) if err != nil { return nil, fmt.Errorf("failed to query: %w", err) diff --git a/pkg/eventstore/store.go b/pkg/eventstore/store.go index b61ef557..8183cceb 100644 --- a/pkg/eventstore/store.go +++ b/pkg/eventstore/store.go @@ -18,7 +18,7 @@ type Store interface { // QueryEvents is invoked upon a client's REQ as described in NIP-01. // it should return a channel with the events as they're recovered from a database. // the channel should be closed after the events are all delivered. - QueryEvents(context.Context, nostr.Filter) (chan *nostr.Event, error) + QueryEvents(context.Context, *nostr.Filter) (chan *nostr.Event, error) // DeleteEvent is used to handle deletion events, as per NIP-09. DeleteEvent(context.Context, *nostr.Event) error // SaveEvent is called once Relay.AcceptEvent reports true.