Skip to content

Commit

Permalink
Merge pull request #95 from mattn/accept-req
Browse files Browse the repository at this point in the history
add ReqAccepter to handle request filters
  • Loading branch information
mattn authored Oct 7, 2023
2 parents 470d025 + 1db1c6d commit 361f745
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 9 additions & 2 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,15 @@ func (s *Server) doReq(ctx context.Context, ws *WebSocket, request []json.RawMes
); err != nil {
return "failed to decode filter"
}
}

filter := &filters[i]
if accepter, ok := s.relay.(ReqAccepter); ok {
if !accepter.AcceptReq(ctx, id, filters) {
return "REQ fitlers are not accepted"
}
}

for _, filter := range filters {

// prevent kind-4 events from being returned to unauthed users,
// only when authentication is a thing
Expand All @@ -206,7 +213,7 @@ func (s *Server) doReq(ctx context.Context, ws *WebSocket, request []json.RawMes
}
}

events, err := store.QueryEvents(ctx, filter)
events, err := store.QueryEvents(ctx, &filter)
if err != nil {
s.Log.Errorf("store: %v", err)
continue
Expand Down
8 changes: 8 additions & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ type Relay interface {
Storage(context.Context) Storage
}

// ReqAccepter is the main interface for implementing a nostr relay.
type ReqAccepter interface {
// AcceptReq is called for every nostr request filters received by the
// server. If the returned value is true, the filtres is passed on to
// [Storage.QueryEvent].
AcceptReq(context.Context, string, nostr.Filters) bool
}

// Auther is the interface for implementing NIP-42.
// ServiceURL() returns the URL used to verify the "AUTH" event from clients.
type Auther interface {
Expand Down

0 comments on commit 361f745

Please sign in to comment.