mirror of
https://github.com/0ceanSlim/grain.git
synced 2024-11-23 17:07:13 +00:00
Compare commits
3 Commits
e8b1380c90
...
0a52bebe14
Author | SHA1 | Date | |
---|---|---|---|
0a52bebe14 | |||
232b1b8d27 | |||
6f15f3f23a |
14
maintainers.yaml
Normal file
14
maintainers.yaml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
identifier: grain
|
||||||
|
maintainers:
|
||||||
|
- npub1zmc6qyqdfnllhnzzxr5wpepfpnzcf8q6m3jdveflmgruqvd3qa9sjv7f60
|
||||||
|
relays:
|
||||||
|
- wss://wheat.happytavern.co/
|
||||||
|
- wss://purplepag.es/
|
||||||
|
- wss://relay.nostr.band/
|
||||||
|
- wss://relay.primal.net/
|
||||||
|
- wss://nos.lol/
|
||||||
|
- wss://offchain.pub/
|
||||||
|
- wss://relay.damus.io/
|
||||||
|
- wss://relay.0xchat.com/
|
||||||
|
- wss://nostr.happytavern.co/
|
||||||
|
- wss://relay.snort.social/
|
@ -44,66 +44,81 @@ func HandleEvent(ws *websocket.Conn, message []interface{}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
eventSize := len(eventBytes) // Calculate event size
|
// Signature check moved here
|
||||||
HandleKind(context.TODO(), evt, ws, eventSize)
|
|
||||||
|
|
||||||
fmt.Println("Event processed:", evt.ID)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func HandleKind(ctx context.Context, evt relay.Event, ws *websocket.Conn, eventSize int) {
|
|
||||||
if !utils.CheckSignature(evt) {
|
if !utils.CheckSignature(evt) {
|
||||||
response.SendOK(ws, evt.ID, false, "invalid: signature verification failed")
|
response.SendOK(ws, evt.ID, false, "invalid: signature verification failed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
collection := db.GetCollection(evt.Kind)
|
eventSize := len(eventBytes) // Calculate event size
|
||||||
rateLimiter := config.GetRateLimiter()
|
|
||||||
sizeLimiter := config.GetSizeLimiter()
|
|
||||||
|
|
||||||
|
if !handleBlacklistAndWhitelist(ws, evt) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !handleRateAndSizeLimits(ws, evt, eventSize) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
storeEvent(context.TODO(), evt, ws)
|
||||||
|
|
||||||
|
fmt.Println("Event processed:", evt.ID)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleBlacklistAndWhitelist(ws *websocket.Conn, evt relay.Event) bool {
|
||||||
if config.GetConfig().DomainWhitelist.Enabled {
|
if config.GetConfig().DomainWhitelist.Enabled {
|
||||||
domains := config.GetConfig().DomainWhitelist.Domains
|
domains := config.GetConfig().DomainWhitelist.Domains
|
||||||
pubkeys, err := utils.FetchPubkeysFromDomains(domains)
|
pubkeys, err := utils.FetchPubkeysFromDomains(domains)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error fetching pubkeys from domains:", err)
|
fmt.Println("Error fetching pubkeys from domains:", err)
|
||||||
response.SendNotice(ws, "", "Error fetching pubkeys from domains")
|
response.SendNotice(ws, "", "Error fetching pubkeys from domains")
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
for _, pubkey := range pubkeys {
|
for _, pubkey := range pubkeys {
|
||||||
config.GetConfig().PubkeyWhitelist.Pubkeys = append(config.GetConfig().PubkeyWhitelist.Pubkeys, pubkey)
|
config.GetConfig().PubkeyWhitelist.Pubkeys = append(config.GetConfig().PubkeyWhitelist.Pubkeys, pubkey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check against manual blacklist
|
|
||||||
if blacklisted, msg := utils.CheckBlacklist(evt.PubKey, evt.Content); blacklisted {
|
if blacklisted, msg := utils.CheckBlacklist(evt.PubKey, evt.Content); blacklisted {
|
||||||
response.SendOK(ws, evt.ID, false, msg)
|
response.SendOK(ws, evt.ID, false, msg)
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the kind is whitelisted
|
|
||||||
if config.GetConfig().KindWhitelist.Enabled && !utils.IsKindWhitelisted(evt.Kind) {
|
if config.GetConfig().KindWhitelist.Enabled && !utils.IsKindWhitelisted(evt.Kind) {
|
||||||
response.SendOK(ws, evt.ID, false, "not allowed: event kind is not whitelisted")
|
response.SendOK(ws, evt.ID, false, "not allowed: event kind is not whitelisted")
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check pubkey/npub whitelist only if the kind is not whitelisted
|
|
||||||
if config.GetConfig().PubkeyWhitelist.Enabled && !utils.IsPubKeyWhitelisted(evt.PubKey) {
|
if config.GetConfig().PubkeyWhitelist.Enabled && !utils.IsPubKeyWhitelisted(evt.PubKey) {
|
||||||
response.SendOK(ws, evt.ID, false, "not allowed: pubkey or npub is not whitelisted")
|
response.SendOK(ws, evt.ID, false, "not allowed: pubkey or npub is not whitelisted")
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleRateAndSizeLimits(ws *websocket.Conn, evt relay.Event, eventSize int) bool {
|
||||||
|
rateLimiter := config.GetRateLimiter()
|
||||||
|
sizeLimiter := config.GetSizeLimiter()
|
||||||
category := determineCategory(evt.Kind)
|
category := determineCategory(evt.Kind)
|
||||||
|
|
||||||
if allowed, msg := rateLimiter.AllowEvent(evt.Kind, category); !allowed {
|
if allowed, msg := rateLimiter.AllowEvent(evt.Kind, category); !allowed {
|
||||||
response.SendOK(ws, evt.ID, false, msg)
|
response.SendOK(ws, evt.ID, false, msg)
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if allowed, msg := sizeLimiter.AllowSize(evt.Kind, eventSize); !allowed {
|
if allowed, msg := sizeLimiter.AllowSize(evt.Kind, eventSize); !allowed {
|
||||||
response.SendOK(ws, evt.ID, false, msg)
|
response.SendOK(ws, evt.ID, false, msg)
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func storeEvent(ctx context.Context, evt relay.Event, ws *websocket.Conn) {
|
||||||
|
collection := db.GetCollection(evt.Kind)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
switch {
|
switch {
|
||||||
case evt.Kind == 0:
|
case evt.Kind == 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user