add khatru.IsInternal() for dealing with internal calls specifically in QueryEvents()

This commit is contained in:
fiatjaf
2025-04-03 23:06:57 -03:00
parent 8c9394993b
commit 2ae219a34c
3 changed files with 9 additions and 0 deletions

View File

@@ -39,6 +39,7 @@ func (rl *Relay) handleDeleteRequest(ctx context.Context, evt *nostr.Event) erro
continue continue
} }
ctx := context.WithValue(ctx, internalCallKey, struct{}{})
for _, query := range rl.QueryEvents { for _, query := range rl.QueryEvents {
ch, err := query(ctx, f) ch, err := query(ctx, f)
if err != nil { if err != nil {

View File

@@ -107,6 +107,7 @@ func (em *expirationManager) checkExpiredEvents(ctx context.Context) {
heap.Pop(&em.events) heap.Pop(&em.events)
ctx := context.WithValue(ctx, internalCallKey, struct{}{})
for _, query := range em.relay.QueryEvents { for _, query := range em.relay.QueryEvents {
ch, err := query(ctx, nostr.Filter{IDs: []string{next.id}}) ch, err := query(ctx, nostr.Filter{IDs: []string{next.id}})
if err != nil { if err != nil {

View File

@@ -10,6 +10,7 @@ const (
wsKey = iota wsKey = iota
subscriptionIdKey subscriptionIdKey
nip86HeaderAuthKey nip86HeaderAuthKey
internalCallKey
) )
func RequestAuth(ctx context.Context) { func RequestAuth(ctx context.Context) {
@@ -40,6 +41,12 @@ func GetAuthed(ctx context.Context) string {
return "" 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 { func GetIP(ctx context.Context) string {
conn := GetConnection(ctx) conn := GetConnection(ctx)
if conn == nil { if conn == nil {