-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathmanagement.go
69 lines (60 loc) · 1.82 KB
/
management.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"context"
"slices"
"github.com/fiatjaf/khatru"
"github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip86"
)
func setupRelayManagement(relay *khatru.Relay) {
relay.ManagementAPI.RejectAPICall = append(relay.ManagementAPI.RejectAPICall,
func(ctx context.Context, mp nip86.MethodParams) (reject bool, msg string) {
if slices.Contains(s.TrustedPubKeys, khatru.GetAuthed(ctx)) {
return false, ""
}
return true, "you are not a trusted pubkey"
},
)
relay.ManagementAPI.BanEvent = func(ctx context.Context, id, reason string) error {
log.Info().Str("id", id).Str("reason", reason).Msg("banning event")
ch, err := sys.Store.QueryEvents(ctx, nostr.Filter{IDs: []string{id}})
if err != nil {
return err
}
for evt := range ch {
sys.Store.DeleteEvent(ctx, evt)
}
if err := internal.banEvent(id, reason); err != nil {
return err
}
return nil
}
relay.ManagementAPI.AllowEvent = func(ctx context.Context, id, reason string) error {
log.Info().Str("id", id).Str("reason", reason).Msg("unbanning event")
if err := internal.unbanEvent(id); err != nil {
return err
}
return nil
}
relay.ManagementAPI.BanPubKey = func(ctx context.Context, pk, reason string) error {
log.Info().Str("pubkey", pk).Str("reason", reason).Msg("banning pubkey")
ch, err := sys.Store.QueryEvents(ctx, nostr.Filter{Authors: []string{pk}, Limit: DB_MAX_LIMIT})
if err != nil {
return err
}
for evt := range ch {
sys.Store.DeleteEvent(ctx, evt)
}
if err := internal.banPubkey(pk, reason); err != nil {
return err
}
return nil
}
relay.ManagementAPI.AllowPubKey = func(ctx context.Context, id, reason string) error {
log.Info().Str("id", id).Str("reason", reason).Msg("unbanning pubkey")
if err := internal.unbanPubkey(id); err != nil {
return err
}
return nil
}
}