fix(gateway): use registered control flows
This commit is contained in:
+17
-14
@@ -23,6 +23,9 @@ const (
|
||||
defaultControlLimit = 128 * 1024
|
||||
clientControlBacklog = 64
|
||||
applicationError = quic.ApplicationErrorCode(0x100)
|
||||
controlFlowID = "control.ack.v1"
|
||||
inputFlowID = "input.sequenced.v1"
|
||||
clipboardFlowID = "clipboard.text.v1"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -446,11 +449,11 @@ func (s *gatewaySession) clipboardLoop() {
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err := s.reportClipboardAudit(value.Direction, "forwarded", clipboardAuditTextBytes(value.Text), "forwarded"); err != nil {
|
||||
if err := s.sendClipboard(value); err != nil {
|
||||
s.result <- err
|
||||
return
|
||||
}
|
||||
if err := s.sendClipboard(value); err != nil {
|
||||
if err := s.reportClipboardAudit(value.Direction, "forwarded", clipboardAuditTextBytes(value.Text), "forwarded"); err != nil {
|
||||
s.result <- err
|
||||
return
|
||||
}
|
||||
@@ -499,7 +502,7 @@ func (s *gatewaySession) controlLoop() {
|
||||
return
|
||||
}
|
||||
switch frame.FlowID {
|
||||
case "control":
|
||||
case controlFlowID:
|
||||
sequence, sequenceErr := channelSequence(frame.Sequence)
|
||||
if sequenceErr != nil {
|
||||
s.result <- sequenceErr
|
||||
@@ -509,7 +512,7 @@ func (s *gatewaySession) controlLoop() {
|
||||
s.result <- err
|
||||
return
|
||||
}
|
||||
case "input":
|
||||
case inputFlowID:
|
||||
sequence, sequenceErr := channelSequence(frame.Sequence)
|
||||
if sequenceErr != nil {
|
||||
s.result <- sequenceErr
|
||||
@@ -519,7 +522,7 @@ func (s *gatewaySession) controlLoop() {
|
||||
s.result <- err
|
||||
return
|
||||
}
|
||||
case "clipboard":
|
||||
case clipboardFlowID:
|
||||
value, decodeErr := protocol.DecodeGatewayClipboardText(payload)
|
||||
if decodeErr != nil {
|
||||
s.result <- ErrProviderMalformed
|
||||
@@ -625,7 +628,7 @@ func (s *gatewaySession) sendControl(sequence uint32, payload []byte) error {
|
||||
if len(payload) > 1024 {
|
||||
return ErrFramePayloadLimit
|
||||
}
|
||||
frame := protocol.ChannelFrame{Version: "1", FlowID: "control", Sequence: int64(sequence), Flags: 0, FragmentIndex: 0, FragmentCount: 1, TimestampMs: time.Now().UnixMilli(), Payload: base64.StdEncoding.EncodeToString(payload)}
|
||||
frame := protocol.ChannelFrame{Version: "1", FlowID: controlFlowID, Sequence: int64(sequence), Flags: 0, FragmentIndex: 0, FragmentCount: 1, TimestampMs: time.Now().UnixMilli(), Payload: base64.StdEncoding.EncodeToString(payload)}
|
||||
encoded, err := protocol.EncodeChannelFrame(frame)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -640,7 +643,7 @@ func (s *gatewaySession) sendClipboard(value protocol.GatewayClipboardText) erro
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
frame := protocol.ChannelFrame{Version: "1", FlowID: "clipboard", Sequence: int64(s.sequence.Add(1)), Flags: 0, FragmentIndex: 0, FragmentCount: 1, TimestampMs: time.Now().UnixMilli(), Payload: base64.StdEncoding.EncodeToString(payload)}
|
||||
frame := protocol.ChannelFrame{Version: "1", FlowID: clipboardFlowID, Sequence: int64(s.sequence.Add(1)), Flags: 0, FragmentIndex: 0, FragmentCount: 1, TimestampMs: time.Now().UnixMilli(), Payload: base64.StdEncoding.EncodeToString(payload)}
|
||||
encoded, err := protocol.EncodeChannelFrame(frame)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -899,7 +902,7 @@ func (c *Client) SendInput(event InputEvent) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
frame := protocol.ChannelFrame{Version: "1", FlowID: "input", Sequence: int64(event.Sequence), Flags: 0, FragmentIndex: 0, FragmentCount: 1, TimestampMs: time.Now().UnixMilli(), Payload: base64.StdEncoding.EncodeToString(payload)}
|
||||
frame := protocol.ChannelFrame{Version: "1", FlowID: inputFlowID, Sequence: int64(event.Sequence), Flags: 0, FragmentIndex: 0, FragmentCount: 1, TimestampMs: time.Now().UnixMilli(), Payload: base64.StdEncoding.EncodeToString(payload)}
|
||||
encoded, err := protocol.EncodeChannelFrame(frame)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -924,7 +927,7 @@ func (c *Client) SendClipboard(value protocol.GatewayClipboardText) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
frame := protocol.ChannelFrame{Version: "1", FlowID: "clipboard", Sequence: 0, Flags: 0, FragmentIndex: 0, FragmentCount: 1, TimestampMs: time.Now().UnixMilli(), Payload: base64.StdEncoding.EncodeToString(payload)}
|
||||
frame := protocol.ChannelFrame{Version: "1", FlowID: clipboardFlowID, Sequence: 0, Flags: 0, FragmentIndex: 0, FragmentCount: 1, TimestampMs: time.Now().UnixMilli(), Payload: base64.StdEncoding.EncodeToString(payload)}
|
||||
encoded, err := protocol.EncodeChannelFrame(frame)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -933,7 +936,7 @@ func (c *Client) SendClipboard(value protocol.GatewayClipboardText) error {
|
||||
}
|
||||
|
||||
func (c *Client) sendControl(sequence uint32, payload []byte) error {
|
||||
frame := protocol.ChannelFrame{Version: "1", FlowID: "control", Sequence: int64(sequence), Flags: 0, FragmentIndex: 0, FragmentCount: 1, TimestampMs: time.Now().UnixMilli(), Payload: base64.StdEncoding.EncodeToString(payload)}
|
||||
frame := protocol.ChannelFrame{Version: "1", FlowID: controlFlowID, Sequence: int64(sequence), Flags: 0, FragmentIndex: 0, FragmentCount: 1, TimestampMs: time.Now().UnixMilli(), Payload: base64.StdEncoding.EncodeToString(payload)}
|
||||
encoded, err := protocol.EncodeChannelFrame(frame)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -956,7 +959,7 @@ func (c *Client) ReceiveFrame(ctx context.Context) (Frame, error) {
|
||||
}
|
||||
|
||||
func (c *Client) ReceiveProviderEvent(ctx context.Context) (ProviderEvent, error) {
|
||||
payload, err := c.receiveControlPayload(ctx, "control")
|
||||
payload, err := c.receiveControlPayload(ctx, controlFlowID)
|
||||
if err != nil {
|
||||
return ProviderEvent{}, err
|
||||
}
|
||||
@@ -967,7 +970,7 @@ func (c *Client) ReceiveProviderEvent(ctx context.Context) (ProviderEvent, error
|
||||
}
|
||||
|
||||
func (c *Client) ReceiveClipboard(ctx context.Context) (protocol.GatewayClipboardText, error) {
|
||||
payload, err := c.receiveControlPayload(ctx, "clipboard")
|
||||
payload, err := c.receiveControlPayload(ctx, clipboardFlowID)
|
||||
if err != nil {
|
||||
return protocol.GatewayClipboardText{}, err
|
||||
}
|
||||
@@ -975,7 +978,7 @@ func (c *Client) ReceiveClipboard(ctx context.Context) (protocol.GatewayClipboar
|
||||
}
|
||||
|
||||
func (c *Client) receiveControlPayload(ctx context.Context, flowID string) ([]byte, error) {
|
||||
if c == nil || c.control == nil || (flowID != "control" && flowID != "clipboard") {
|
||||
if c == nil || c.control == nil || (flowID != controlFlowID && flowID != clipboardFlowID) {
|
||||
return nil, ErrProviderMalformed
|
||||
}
|
||||
c.controlReadMu.Lock()
|
||||
@@ -1000,7 +1003,7 @@ func (c *Client) receiveControlPayload(ctx context.Context, flowID string) ([]by
|
||||
return nil, err
|
||||
}
|
||||
frame, err := protocol.DecodeChannelFrame(data)
|
||||
if err != nil || (frame.FlowID != "control" && frame.FlowID != "clipboard") {
|
||||
if err != nil || (frame.FlowID != controlFlowID && frame.FlowID != clipboardFlowID) {
|
||||
return nil, ErrProviderMalformed
|
||||
}
|
||||
payload, err := base64.StdEncoding.DecodeString(frame.Payload)
|
||||
|
||||
Reference in New Issue
Block a user