websocket: add small buffer to listener channels
This commit is contained in:
parent
764aed89ae
commit
766692bfe6
|
@ -87,9 +87,9 @@ func (h *Handler) listenForServerEvents(ctx context.Context) error {
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
eventChan := make(chan events.Event)
|
eventChan := make(chan events.Event, 8)
|
||||||
logOutput := make(chan []byte)
|
logOutput := make(chan []byte, 8)
|
||||||
installOutput := make(chan []byte)
|
installOutput := make(chan []byte, 8)
|
||||||
h.server.Events().On(eventChan, e...)
|
h.server.Events().On(eventChan, e...)
|
||||||
h.server.LogSink().On(logOutput)
|
h.server.LogSink().On(logOutput)
|
||||||
h.server.InstallSink().On(installOutput)
|
h.server.InstallSink().On(installOutput)
|
||||||
|
|
|
@ -267,11 +267,18 @@ func (h *Handler) setJwt(token *tokens.WebsocketPayload) {
|
||||||
h.Unlock()
|
h.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var actions = map[server.PowerAction]string{
|
||||||
|
server.PowerActionStart: PermissionSendPowerStart,
|
||||||
|
server.PowerActionStop: PermissionSendPowerStop,
|
||||||
|
server.PowerActionRestart: PermissionSendPowerRestart,
|
||||||
|
server.PowerActionTerminate: PermissionSendPowerStop,
|
||||||
|
}
|
||||||
|
|
||||||
// HandleInbound handles an inbound socket request and route it to the proper action.
|
// HandleInbound handles an inbound socket request and route it to the proper action.
|
||||||
func (h *Handler) HandleInbound(ctx context.Context, m Message) error {
|
func (h *Handler) HandleInbound(ctx context.Context, m Message) error {
|
||||||
if m.Event != AuthenticationEvent {
|
if m.Event != AuthenticationEvent {
|
||||||
if err := h.TokenValid(); err != nil {
|
if err := h.TokenValid(); err != nil {
|
||||||
h.unsafeSendJson(Message{
|
_ = h.unsafeSendJson(Message{
|
||||||
Event: JwtErrorEvent,
|
Event: JwtErrorEvent,
|
||||||
Args: []string{err.Error()},
|
Args: []string{err.Error()},
|
||||||
})
|
})
|
||||||
|
@ -339,12 +346,6 @@ func (h *Handler) HandleInbound(ctx context.Context, m Message) error {
|
||||||
{
|
{
|
||||||
action := server.PowerAction(strings.Join(m.Args, ""))
|
action := server.PowerAction(strings.Join(m.Args, ""))
|
||||||
|
|
||||||
actions := make(map[server.PowerAction]string)
|
|
||||||
actions[server.PowerActionStart] = PermissionSendPowerStart
|
|
||||||
actions[server.PowerActionStop] = PermissionSendPowerStop
|
|
||||||
actions[server.PowerActionRestart] = PermissionSendPowerRestart
|
|
||||||
actions[server.PowerActionTerminate] = PermissionSendPowerStop
|
|
||||||
|
|
||||||
// Check that they have permission to perform this action if it is needed.
|
// Check that they have permission to perform this action if it is needed.
|
||||||
if permission, exists := actions[action]; exists {
|
if permission, exists := actions[action]; exists {
|
||||||
if !h.GetJwt().HasPermission(permission) {
|
if !h.GetJwt().HasPermission(permission) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user