From 2ae219a34c01d80e417f63c9e57f07f25b5dbca5 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Thu, 3 Apr 2025 23:06:57 -0300 Subject: [PATCH] add khatru.IsInternal() for dealing with internal calls specifically in QueryEvents() --- deleting.go | 1 + expiration.go | 1 + utils.go | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/deleting.go b/deleting.go index 9257f49..230eba7 100644 --- a/deleting.go +++ b/deleting.go @@ -39,6 +39,7 @@ func (rl *Relay) handleDeleteRequest(ctx context.Context, evt *nostr.Event) erro continue } + ctx := context.WithValue(ctx, internalCallKey, struct{}{}) for _, query := range rl.QueryEvents { ch, err := query(ctx, f) if err != nil { diff --git a/expiration.go b/expiration.go index 9183e52..4e382d5 100644 --- a/expiration.go +++ b/expiration.go @@ -107,6 +107,7 @@ func (em *expirationManager) checkExpiredEvents(ctx context.Context) { heap.Pop(&em.events) + ctx := context.WithValue(ctx, internalCallKey, struct{}{}) for _, query := range em.relay.QueryEvents { ch, err := query(ctx, nostr.Filter{IDs: []string{next.id}}) if err != nil { diff --git a/utils.go b/utils.go index 4745cd1..131f360 100644 --- a/utils.go +++ b/utils.go @@ -10,6 +10,7 @@ const ( wsKey = iota subscriptionIdKey nip86HeaderAuthKey + internalCallKey ) func RequestAuth(ctx context.Context) { @@ -40,6 +41,12 @@ func GetAuthed(ctx context.Context) string { return "" } +// IsInternalCall returns true when a call to QueryEvents, for example, is being made because of a deletion +// or expiration request. +func IsInternalCall(ctx context.Context) bool { + return ctx.Value(internalCallKey) != nil +} + func GetIP(ctx context.Context) string { conn := GetConnection(ctx) if conn == nil {