mirror

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolVersion = 3

	TagClientHello byte = 0x01
	TagClose       byte = 0x05
	TagInput       byte = 0x06
	TagOutput      byte = 0x07
	TagReady       byte = 0x08
	TagShutdown    byte = 0x0a
	TagError       byte = 0x0b

	MaxWireMessage       = 128 << 10
	MaxClientQueueBytes  = 1 << 20
	MaxHandshakes        = 16
	MaxClients           = 8
	HandshakeTimeout     = 5 * time.Second
	TunnelStartupTimeout = 30 * time.Second
)

Variables

View Source
var (
	ErrCipherPoisoned   = errors.New("mirror cipher is poisoned")
	ErrCounterExhausted = errors.New("mirror cipher counter exhausted")
)
View Source
var ErrClientQueueFull = errors.New("mirror client outbound queue is full")

Functions

func ChunkOutput

func ChunkOutput(data []byte) [][]byte

func DecodeControl

func DecodeControl(tag byte, payload []byte, dst any) error

func DeriveKeys

func DeriveKeys(secret, serverNonce, clientNonce []byte) (c2s, s2c [32]byte, err error)

func EncodeControl

func EncodeControl(tag byte, value any) ([]byte, error)

func PairingURL

func PairingURL(publicURL string, secret Secret) (string, error)

func ParseCloudflaredVersion

func ParseCloudflaredVersion(output string) (string, error)

func TerminalQR

func TerminalQR(pairingURL string) (string, error)

func ValidateClientFrame

func ValidateClientFrame(tag byte, value any) error

func ValidateServerFrame

func ValidateServerFrame(tag byte, value any) error

Types

type Client

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

func (*Client) SendControl

func (c *Client) SendControl(ctx context.Context, tag byte, value any) error

func (*Client) SendOutput

func (c *Client) SendOutput(ctx context.Context, output []byte) error

type ClientHandler

type ClientHandler interface {
	Connected(context.Context, *Client) error
	Close(*Client) error
	Input(*Client, []byte) error
	Disconnected(*Client)
}

type ClientHello

type ClientHello struct {
	Version int `json:"version"`
}

type DiagnosticRecord

type DiagnosticRecord struct {
	Level          string
	Component      string
	Event          string
	Code           string
	Path           string
	ViewerGeometry *ViewerGeometryDiagnostic
}

type DiagnosticSink

type DiagnosticSink interface {
	Write(DiagnosticRecord) error
}

func NewJSONLDiagnosticSink

func NewJSONLDiagnosticSink(path string) DiagnosticSink

type DiagnosticSinkFunc

type DiagnosticSinkFunc func(DiagnosticRecord) error

func (DiagnosticSinkFunc) Write

func (f DiagnosticSinkFunc) Write(record DiagnosticRecord) error

type Event

type Event struct {
	Snapshot *Snapshot
}

type HostSession

type HostSession struct {
	ID           string
	WindowID     string
	Generation   string
	Name         string
	Kind         string
	Bell         bool
	Activity     int64
	SeenActivity int64
}

type Identity

type Identity struct {
	ID         string
	WindowID   string
	Generation string
}

type LocalServer

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

func StartLocalServer

func StartLocalServer(ctx context.Context, options ServerOptions) (*LocalServer, error)

func (*LocalServer) Close

func (s *LocalServer) Close(ctx context.Context) error

func (*LocalServer) LocalURL

func (s *LocalServer) LocalURL() string

func (*LocalServer) ServeHTTP

func (s *LocalServer) ServeHTTP(response http.ResponseWriter, request *http.Request)

func (*LocalServer) SetPublicHost

func (s *LocalServer) SetPublicHost(host string)

func (*LocalServer) SetSecret

func (s *LocalServer) SetSecret(secret Secret)

type Manager

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

func NewManager

func NewManager(options ManagerOptions) (*Manager, error)

func (*Manager) ClientCount

func (m *Manager) ClientCount() int

func (*Manager) Close

func (m *Manager) Close(client *Client) error

func (*Manager) Connected

func (m *Manager) Connected(ctx context.Context, client *Client) error

func (*Manager) Disconnected

func (m *Manager) Disconnected(client *Client)

func (*Manager) Events

func (m *Manager) Events() <-chan Event

func (*Manager) Input

func (m *Manager) Input(client *Client, data []byte) error

func (*Manager) Rotate

func (m *Manager) Rotate(ctx context.Context) error

func (*Manager) Shutdown

func (m *Manager) Shutdown(ctx context.Context) error

func (*Manager) Snapshot

func (m *Manager) Snapshot() Snapshot

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

type ManagerOptions

type ManagerOptions struct {
	Workspace   string
	Target      *HostSession
	Viewers     ViewerFactory
	StartServer func(context.Context, ServerOptions) (ServerResource, error)
	StartTunnel func(context.Context, string) (TunnelResource, error)
	Random      io.Reader
	Diagnostics DiagnosticSink
}

type Opener

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

func NewOpener

func NewOpener(key [32]byte) (*Opener, error)

func (*Opener) Open

func (o *Opener) Open(ciphertext []byte) (byte, []byte, error)

type PTYViewerFactory

type PTYViewerFactory struct {
	SessionSocket string
	Endpoint      tmux.Endpoint
	TmuxPath      string
	Environment   []string
	Record        func(DiagnosticRecord)
	// contains filtered or unexported fields
}

func (*PTYViewerFactory) Cleanup

func (f *PTYViewerFactory) Cleanup() error

Cleanup retries restoration for pins whose last viewer has already exited. Failed pins stay in the factory so a later lifecycle cleanup can try again.

func (*PTYViewerFactory) Prepare

func (f *PTYViewerFactory) Prepare(
	ctx context.Context,
	identity Identity,
	output func([]byte) error,
) (PreparedViewer, error)

type PreparedViewer

type PreparedViewer interface {
	Geometry() ViewerGeometry
	Start() (Viewer, error)
	Close() error
}

type ProtocolError

type ProtocolError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Retry   bool   `json:"retry"`
}

type Ready

type Ready struct {
	ID         string `json:"id"`
	Generation string `json:"generation"`
	Columns    uint16 `json:"columns"`
	Rows       uint16 `json:"rows"`
}

type Sealer

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

func NewSealer

func NewSealer(key [32]byte) (*Sealer, error)

func (*Sealer) Seal

func (s *Sealer) Seal(tag byte, payload []byte) ([]byte, error)

type Secret

type Secret [32]byte

func NewSecret

func NewSecret(random io.Reader) (Secret, error)

func ParseSecret

func ParseSecret(raw string) (Secret, error)

func (Secret) String

func (s Secret) String() string

type ServerOptions

type ServerOptions struct {
	Secret     Secret
	PublicHost string
	Handler    ClientHandler
	Random     io.Reader
	Record     func(DiagnosticRecord)
}

type ServerResource

type ServerResource interface {
	LocalURL() string
	SetPublicHost(string)
	SetSecret(Secret)
	Close(context.Context) error
}

type Shutdown

type Shutdown struct {
	Reason string `json:"reason"`
	Retry  bool   `json:"retry"`
}

type Snapshot

type Snapshot struct {
	State              State
	PublicURL          string
	PairingURL         string
	QR                 string
	Err                string
	DiagnosticsWarning string
	CleanupWarning     string
}

type State

type State uint8
const (
	StateStopped State = iota
	StateStarting
	StateReady
	StateFailed
)

type Tunnel

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

func StartTunnel

func StartTunnel(ctx context.Context, localURL string, options TunnelOptions) (*Tunnel, error)

func (*Tunnel) Close

func (t *Tunnel) Close() error

func (*Tunnel) Done

func (t *Tunnel) Done() <-chan error

func (*Tunnel) URL

func (t *Tunnel) URL() string

type TunnelOptions

type TunnelOptions struct {
	LookPath       pathLookup
	Command        commandFactory
	StartupTimeout time.Duration
	StopTimeout    time.Duration
	Record         func(DiagnosticRecord)
}

type TunnelResource

type TunnelResource interface {
	URL() string
	Done() <-chan error
	Close() error
}

type Viewer

type Viewer interface {
	Write([]byte) error
	Close() error
	Done() <-chan error
}

type ViewerFactory

type ViewerFactory interface {
	Prepare(
		ctx context.Context,
		identity Identity,
		output func([]byte) error,
	) (PreparedViewer, error)
}

type ViewerGeometry

type ViewerGeometry struct {
	Columns uint16
	Rows    uint16
	// contains filtered or unexported fields
}

type ViewerGeometryDiagnostic

type ViewerGeometryDiagnostic struct {
	CapturedColumns uint16 `json:"captured_columns"`
	CapturedRows    uint16 `json:"captured_rows"`
	ClientColumns   uint16 `json:"client_columns"`
	ClientRows      uint16 `json:"client_rows"`
	WindowColumns   uint16 `json:"window_columns"`
	WindowRows      uint16 `json:"window_rows"`
	StatusRows      uint16 `json:"status_rows"`
	Corrected       bool   `json:"corrected"`
}

Jump to

Keyboard shortcuts

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