From a35ea6ab5d41642930ef19e8e980b6d078ec22b3 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 12 Aug 2023 15:14:34 -0500 Subject: [PATCH] relay: restrict to local events unless the filter is already narrow --- src/controllers/nostr/relay.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/controllers/nostr/relay.ts b/src/controllers/nostr/relay.ts index eb4a983..c2d77ec 100644 --- a/src/controllers/nostr/relay.ts +++ b/src/controllers/nostr/relay.ts @@ -49,11 +49,14 @@ function connectStream(socket: WebSocket) { } } +/** Enforce the filters with certain criteria. */ function prepareFilters(filters: ClientREQ[2][]): Filter[] { return filters.map((filter) => ({ ...filter, + // Limit the number of events returned per-filter. limit: Math.min(filter.limit || FILTER_LIMIT, FILTER_LIMIT), - local: true, + // Return only local events unless the query is already narrow. + local: !filter.ids?.length && !filter.authors?.length, })); } @@ -65,8 +68,8 @@ const relayController: AppController = (c) => { } const { socket, response } = Deno.upgradeWebSocket(c.req.raw); - connectStream(socket); + return response; };