mirror of
https://github.com/hanzoai/compute.git
synced 2026-10-30 14:50:41 +00:00
guacamole's tunnel handler reached the raw request to read query params before upgrading, which is the one thing zip's wsx.Upgrade does not hand back -- it takes the connection and drops the Ctx. So the parameters are read from the Ctx BEFORE the upgrade and carried in, which is what the upgrade boundary actually allows and removes the last reason this path wanted a foreign framework. Whole suite green: 8 packages ok, none skipped, object's 67s integration pass included. Co-authored-by: Hanzo Dev <[email protected]>
69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
// Copyright 2023 Hanzo Industries Inc. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package controllers
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zap-proto/zip/wsx"
|
|
|
|
"github.com/hanzoai/visor/util/guacamole"
|
|
)
|
|
|
|
type GuacamoleHandler struct {
|
|
ws *wsx.Conn
|
|
tunnel *guacamole.Tunnel
|
|
ctx context.Context
|
|
cancel context.CancelFunc
|
|
}
|
|
|
|
func NewGuacamoleHandler(ws *wsx.Conn, tunnel *guacamole.Tunnel) *GuacamoleHandler {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
return &GuacamoleHandler{
|
|
ws: ws,
|
|
tunnel: tunnel,
|
|
ctx: ctx,
|
|
cancel: cancel,
|
|
}
|
|
}
|
|
|
|
func (r GuacamoleHandler) Start() {
|
|
go func() {
|
|
for {
|
|
select {
|
|
case <-r.ctx.Done():
|
|
return
|
|
default:
|
|
instruction, err := r.tunnel.Read()
|
|
if err != nil {
|
|
guacamole.Disconnect(r.ws, TunnelClosed, "Remote connection shut down")
|
|
return
|
|
}
|
|
if len(instruction) == 0 {
|
|
continue
|
|
}
|
|
err = r.ws.WriteMessage(wsx.TextMessage, instruction)
|
|
if err != nil {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}()
|
|
}
|
|
|
|
func (r GuacamoleHandler) Stop() {
|
|
r.cancel()
|
|
}
|