add more
This commit is contained in:
@@ -123,7 +123,7 @@ final class AgentListener
|
||||
}
|
||||
|
||||
match ($frame->type) {
|
||||
FrameType::DATA => $this->forwardDataToTarget($session, (string)($frame->payload['data'] ?? '')),
|
||||
FrameType::DATA => $this->forwardDataToTarget($session, $frame),
|
||||
FrameType::CLOSE => $this->closeSession($session, 'closed', null),
|
||||
default => null,
|
||||
};
|
||||
@@ -233,7 +233,7 @@ final class AgentListener
|
||||
$target->onMessage = function (AsyncTcpConnection $target, string $data) use ($session, $agentConnection): void {
|
||||
$session->bytesTargetToClient += strlen($data);
|
||||
$this->send($agentConnection, new Frame(FrameType::DATA, $session->sessionId, [
|
||||
'data' => base64_encode($data),
|
||||
'data_raw' => $data,
|
||||
]));
|
||||
};
|
||||
$target->onClose = fn () => $this->closeSession($session, 'closed', null);
|
||||
@@ -241,9 +241,9 @@ final class AgentListener
|
||||
$target->connect();
|
||||
}
|
||||
|
||||
private function forwardDataToTarget(TunnelSession $session, string $encoded): void
|
||||
private function forwardDataToTarget(TunnelSession $session, Frame $frame): void
|
||||
{
|
||||
$data = base64_decode($encoded, true);
|
||||
$data = $this->frameData($frame);
|
||||
if ($data === false) {
|
||||
$this->closeSession($session, 'failed', 'invalid_frame');
|
||||
return;
|
||||
@@ -259,6 +259,15 @@ final class AgentListener
|
||||
$this->closeSession($session, 'failed', $reason);
|
||||
}
|
||||
|
||||
private function frameData(Frame $frame): string|false
|
||||
{
|
||||
if (isset($frame->payload['data_raw']) && is_string($frame->payload['data_raw'])) {
|
||||
return $frame->payload['data_raw'];
|
||||
}
|
||||
|
||||
return base64_decode((string)($frame->payload['data'] ?? ''), true);
|
||||
}
|
||||
|
||||
private function rejectOpen(TcpConnection $agentConnection, Frame $frame, string $reason, string $userId, string $nodeId, ?string $policyId = null): void
|
||||
{
|
||||
$this->send($agentConnection, new Frame(FrameType::OPEN_FAIL, $frame->sessionId, ['reason' => $reason]));
|
||||
|
||||
Reference in New Issue
Block a user