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)
|
||||
defer cancel()
|
||||
|
||||
eventChan := make(chan events.Event)
|
||||
logOutput := make(chan []byte)
|
||||
installOutput := make(chan []byte)
|
||||
eventChan := make(chan events.Event, 8)
|
||||
logOutput := make(chan []byte, 8)
|
||||
installOutput := make(chan []byte, 8)
|
||||
h.server.Events().On(eventChan, e...)
|
||||
h.server.LogSink().On(logOutput)
|
||||
h.server.InstallSink().On(installOutput)
|
||||
|
|
|
@ -267,11 +267,18 @@ func (h *Handler) setJwt(token *tokens.WebsocketPayload) {
|
|||
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.
|
||||
func (h *Handler) HandleInbound(ctx context.Context, m Message) error {
|
||||
if m.Event != AuthenticationEvent {
|
||||
if err := h.TokenValid(); err != nil {
|
||||
h.unsafeSendJson(Message{
|
||||
_ = h.unsafeSendJson(Message{
|
||||
Event: JwtErrorEvent,
|
||||
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, ""))
|
||||
|
||||
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.
|
||||
if permission, exists := actions[action]; exists {
|
||||
if !h.GetJwt().HasPermission(permission) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user