Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions powernap/pkg/transport/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,30 @@ func (r *Router) Route(ctx context.Context, req *jsonrpc2.Request) (any, error)
r.mu.RLock()
defer r.mu.RUnlock()

// Check if it's a notification (no ID)
if req.ID == (jsonrpc2.ID{}) {
// Safely extract params, defaulting to "null" if not present.
params := json.RawMessage("null")
if req.Params != nil {
params = *req.Params
}

// Check if it's a notification (no ID). Use req.Notif rather than
// comparing the ID to its zero value because jsonrpc2.ID{} (Num: 0)
// is indistinguishable from a legitimate integer ID of 0.
if req.Notif {
if handler, ok := r.notificationHandlers[req.Method]; ok {
handler(ctx, req.Method, *req.Params)
handler(ctx, req.Method, params)
}
return nil, nil
}

// It's a request
if handler, ok := r.handlers[req.Method]; ok {
return handler(ctx, req.Method, *req.Params)
return handler(ctx, req.Method, params)
}

// Use default handler if available
if r.defaultHandler != nil {
return r.defaultHandler(ctx, req.Method, *req.Params)
return r.defaultHandler(ctx, req.Method, params)
}

return nil, fmt.Errorf("no handler for method: %s", req.Method)
Expand Down