mirror of
https://github.com/aljazceru/khatru.git
synced 2025-12-17 21:44:22 +01:00
add khatru.IsInternal() for dealing with internal calls specifically in QueryEvents()
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
7
utils.go
7
utils.go
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user