mirror of
https://github.com/0ceanSlim/grain.git
synced 2024-11-22 00:27:14 +00:00
undo limited routine for event handler
This commit is contained in:
parent
462fa0a4b1
commit
3526d2937e
@ -16,55 +16,55 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func HandleEvent(ws *websocket.Conn, message []interface{}) {
|
func HandleEvent(ws *websocket.Conn, message []interface{}) {
|
||||||
config.LimitedGoRoutine(func() {
|
|
||||||
if len(message) != 2 {
|
|
||||||
fmt.Println("Invalid EVENT message format")
|
|
||||||
response.SendNotice(ws, "", "Invalid EVENT message format")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
eventData, ok := message[1].(map[string]interface{})
|
if len(message) != 2 {
|
||||||
if !ok {
|
fmt.Println("Invalid EVENT message format")
|
||||||
fmt.Println("Invalid event data format")
|
response.SendNotice(ws, "", "Invalid EVENT message format")
|
||||||
response.SendNotice(ws, "", "Invalid event data format")
|
return
|
||||||
return
|
}
|
||||||
}
|
|
||||||
eventBytes, err := json.Marshal(eventData)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error marshaling event data:", err)
|
|
||||||
response.SendNotice(ws, "", "Error marshaling event data")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var evt nostr.Event
|
eventData, ok := message[1].(map[string]interface{})
|
||||||
err = json.Unmarshal(eventBytes, &evt)
|
if !ok {
|
||||||
if err != nil {
|
fmt.Println("Invalid event data format")
|
||||||
fmt.Println("Error unmarshaling event data:", err)
|
response.SendNotice(ws, "", "Invalid event data format")
|
||||||
response.SendNotice(ws, "", "Error unmarshaling event data")
|
return
|
||||||
return
|
}
|
||||||
}
|
eventBytes, err := json.Marshal(eventData)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error marshaling event data:", err)
|
||||||
|
response.SendNotice(ws, "", "Error marshaling event data")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Signature check moved here
|
var evt nostr.Event
|
||||||
if !utils.CheckSignature(evt) {
|
err = json.Unmarshal(eventBytes, &evt)
|
||||||
response.SendOK(ws, evt.ID, false, "invalid: signature verification failed")
|
if err != nil {
|
||||||
return
|
fmt.Println("Error unmarshaling event data:", err)
|
||||||
}
|
response.SendNotice(ws, "", "Error unmarshaling event data")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
eventSize := len(eventBytes) // Calculate event size
|
// Signature check moved here
|
||||||
|
if !utils.CheckSignature(evt) {
|
||||||
|
response.SendOK(ws, evt.ID, false, "invalid: signature verification failed")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if !handleBlacklistAndWhitelist(ws, evt) {
|
eventSize := len(eventBytes) // Calculate event size
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !handleRateAndSizeLimits(ws, evt, eventSize) {
|
if !handleBlacklistAndWhitelist(ws, evt) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is where I'll handle storage for multiple database types in the future
|
if !handleRateAndSizeLimits(ws, evt, eventSize) {
|
||||||
db.StoreMongoEvent(context.TODO(), evt, ws)
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is where I'll handle storage for multiple database types in the future
|
||||||
|
db.StoreMongoEvent(context.TODO(), evt, ws)
|
||||||
|
|
||||||
|
fmt.Println("Event processed:", evt.ID)
|
||||||
|
|
||||||
fmt.Println("Event processed:", evt.ID)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleBlacklistAndWhitelist(ws *websocket.Conn, evt nostr.Event) bool {
|
func handleBlacklistAndWhitelist(ws *websocket.Conn, evt nostr.Event) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user