ptystream

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package ptystream defines the framed duplex byte-stream protocol spoken over a hijacked takod exec connection. It is the machine contract for interactive exec: a control plane bridges these frames to a browser terminal over its own SSH connection.

After the HTTP/1.1 upgrade handshake (Upgrade: tako-pty/1) both sides exchange frames: 1 type byte, a 4-byte big-endian payload length, then the payload. The server's terminal frame is Exit; nothing follows it.

Index

Constants

View Source
const (
	// FrameStdin carries raw input bytes for the remote process.
	FrameStdin byte = 1
	// FrameStdout carries raw output bytes. A PTY merges stdout and stderr
	// into one stream by nature; non-PTY interactive exec merges them to
	// match, so there is no separate stderr frame.
	FrameStdout byte = 2
	// FrameResize carries a terminal size change: cols and rows as
	// big-endian uint16s (4 payload bytes).
	FrameResize byte = 3
	// FrameExit is the terminal frame: the remote command's exit code as a
	// big-endian int32 (4 payload bytes). -1 reports a run failure that
	// produced no exit code.
	FrameExit byte = 4
	// FrameContainer names the resolved target container. The server sends
	// it once before any output.
	FrameContainer byte = 5
	// FrameError carries a fatal server-side message emitted before Exit.
	FrameError byte = 6
)

Frame types. Stdin/Resize flow client to server; the rest flow server to client.

View Source
const MaxPayload = 1 << 20

MaxPayload bounds a single frame's payload. Larger frames are a protocol error: output is chunked by the PTY read loop and stdin by the terminal.

View Source
const Protocol = "tako-pty/1"

Protocol is the HTTP Upgrade token that selects this stream version. Version bumps get a new token; the server rejects unknown tokens.

Variables

This section is empty.

Functions

func DecodeExit

func DecodeExit(payload []byte) (int, error)

DecodeExit parses an Exit frame payload.

func EncodeExit

func EncodeExit(code int) []byte

EncodeExit renders an Exit frame payload.

func EncodeResize

func EncodeResize(size Winsize) []byte

EncodeResize renders a Resize frame payload.

func WriteFrame

func WriteFrame(w io.Writer, frameType byte, payload []byte) error

WriteFrame encodes one frame to w. Payloads above MaxPayload must be chunked by the caller.

Types

type Frame

type Frame struct {
	Type    byte
	Payload []byte
}

Frame is one decoded protocol frame.

func ReadFrame

func ReadFrame(r io.Reader) (Frame, error)

ReadFrame decodes the next frame from r.

type Winsize

type Winsize struct {
	Cols uint16
	Rows uint16
}

Winsize is a terminal size in character cells.

func DecodeResize

func DecodeResize(payload []byte) (Winsize, error)

DecodeResize parses a Resize frame payload.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer serializes concurrent frame writes onto one connection (e.g. a stdin pump and a SIGWINCH handler sharing the client side).

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter wraps w for concurrent frame writing.

func (*Writer) WriteFrame

func (fw *Writer) WriteFrame(frameType byte, payload []byte) error

WriteFrame writes one frame atomically with respect to other WriteFrame calls on this Writer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL