Documentation
¶
Index ¶
- Constants
- func BindUDP(low, high int) (*net.UDPConn, int, error)
- func GenerateKey() ([]byte, string, error)
- func MarshalHostMessage(instrs []HostInstruction) []byte
- func MarshalUserMessage(instrs []UserInstruction) []byte
- type Attr
- type Cell
- type Client
- type Color
- type ColorType
- type Conn
- type Fragment
- type FragmentAssembler
- type Framebuffer
- type HostInstruction
- type LatchControl
- type OCB
- type PacketAddr
- type PacketConn
- type PreparedTakeover
- type RecvResult
- type Server
- func (s *Server) Close()
- func (s *Server) CommitTakeover(t *PreparedTakeover) error
- func (s *Server) ConnectLine() string
- func (s *Server) Done() <-chan struct{}
- func (s *Server) KeyBase64() string
- func (s *Server) Port() int
- func (s *Server) PrepareTakeover() (*PreparedTakeover, error)
- func (s *Server) Serve() error
- func (s *Server) ServeConn(conn PacketConn) error
- func (s *Server) ServeRW(rw io.ReadWriteCloser, resize func(cols, rows uint16)) error
- func (s *Server) SetNetworkTimeout(timeout time.Duration)
- func (s *Server) Takeover() (string, error)
- func (s *Server) WriteTo(w io.Writer) (int64, error)
- type Transport
- func (t *Transport) AckedByRemote() uint64
- func (t *Transport) ForceNextSend()
- func (t *Transport) HasCap(bit byte) bool
- func (t *Transport) LastRecv() time.Time
- func (t *Transport) LastRecvNewNum() uint64
- func (t *Transport) LastRecvOldNum() uint64
- func (t *Transport) RTO() time.Duration
- func (t *Transport) Recv(wire []byte) (RecvResult, error)
- func (t *Transport) RemoteCaps() []byte
- func (t *Transport) SentNum() uint64
- func (t *Transport) SetCaps(caps []byte)
- func (t *Transport) SetPending(diff []byte)
- func (t *Transport) ThrowawayNum() uint64
- func (t *Transport) Tick() [][]byte
- type TransportInstruction
- type UserInstruction
Constants ¶
const ( CtrlSessionListReq uint32 = 1 CtrlSessionListResp uint32 = 2 CtrlSessionSwitch uint32 = 3 CtrlSessionSwitched uint32 = 4 CtrlSessionCreate uint32 = 5 CtrlSessionCreated uint32 = 6 )
const (
CapSessionControl byte = 1 << 0
)
Variables ¶
This section is empty.
Functions ¶
func GenerateKey ¶
GenerateKey creates a random 128-bit mosh key and returns it as base64.
func MarshalHostMessage ¶
func MarshalHostMessage(instrs []HostInstruction) []byte
MarshalHostMessage encodes a list of HostInstructions as a HostMessage protobuf.
func MarshalUserMessage ¶
func MarshalUserMessage(instrs []UserInstruction) []byte
MarshalUserMessage encodes a list of UserInstructions as a UserMessage protobuf.
Types ¶
type Attr ¶
type Attr struct {
FG Color
BG Color
Bold bool
Dim bool
Italic bool
Under bool
Blink bool
Reverse bool
Strike bool
}
Attr holds SGR attributes for a cell.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a mosh client. It connects to a mosh server over UDP, handles the SSP transport, and provides send/recv for terminal I/O.
func Dial ¶
Dial connects to a mosh server over UDP. The key is the base64-encoded mosh key (with or without padding).
func DialConn ¶
DialConn creates a mosh client over an existing datagram connection. Use this with WebTransport or other non-UDP transports.
func DialConnManual ¶
DialConnManual creates a mosh client without an internal sendLoop. The caller must call Tick() periodically (e.g., every 8-16ms) to flush outgoing datagrams. Use this in WASM where Go timers are unreliable.
func DialConnRaw ¶
DialConnRaw creates a mosh client with no internal goroutines. The caller must call Tick() for sending AND RecvRaw() for receiving. Use this when the caller needs raw transport diffs (e.g., for framebuffer state tracking in the WASM client).
func (*Client) Recv ¶
Recv reads accumulated terminal output, blocking until output is available or the timeout expires. Returns nil on timeout.
func (*Client) RecvRaw ¶
RecvRaw reads one datagram from the connection and processes it through the transport. Returns the raw diff payload, or nil if no complete message was received (timeout, fragment, replay). The caller can use Transport().LastRecvOldNum()/LastRecvNewNum() to get the state numbers for this diff.
type Conn ¶
type Conn interface {
// Read reads a datagram. Returns the number of bytes read.
// Must respect deadlines set by SetReadDeadline.
Read(b []byte) (int, error)
// Write writes a datagram.
Write(b []byte) (int, error)
// SetReadDeadline sets the deadline for Read calls.
SetReadDeadline(t time.Time) error
// Close closes the connection.
Close() error
}
Conn is a datagram-oriented connection used by the mosh transport. UDP, WebTransport, and other datagram transports implement this interface.
type Fragment ¶
Fragment is a single mosh datagram fragment.
func Fragmentize ¶
Fragmentize splits a protobuf-encoded message into fragments. Each fragment carries at most maxFragmentPayload bytes.
func UnmarshalFragment ¶
UnmarshalFragment decodes a fragment from wire format.
type FragmentAssembler ¶
type FragmentAssembler struct {
// contains filtered or unexported fields
}
FragmentAssembler reassembles fragments into complete messages.
type Framebuffer ¶
type Framebuffer struct {
W, H int
Cells []Cell
CurX int
CurY int
CurVis bool
AltScreen bool
AppCursorKeys bool
AppKeypad bool
}
Framebuffer represents a terminal screen state for mosh SSP. The server captures this from the VT emulator; the diff between two Framebuffers produces the ANSI escape sequences sent as HostBytes.
func NewFramebuffer ¶
func NewFramebuffer(w, h int) *Framebuffer
NewFramebuffer allocates a blank framebuffer.
func SnapshotEmulator ¶
func SnapshotEmulator(emu *vt.Emulator, cursorVisible bool) *Framebuffer
SnapshotEmulator captures the VT emulator state into a Framebuffer.
func SnapshotEmulatorWithModes ¶
func SnapshotEmulatorWithModes(emu *vt.Emulator, cursorVisible, appCursorKeys, appKeypad bool) *Framebuffer
SnapshotEmulatorWithModes captures the VT emulator state and externally tracked terminal input modes into a Framebuffer.
func (*Framebuffer) CellAt ¶
func (fb *Framebuffer) CellAt(x, y int) *Cell
CellAt returns a pointer to the cell at (x, y).
func (*Framebuffer) Diff ¶
func (fb *Framebuffer) Diff(old *Framebuffer) []byte
Diff produces the minimal ANSI escape sequence to transform old into fb. This is what goes into HostBytes.hoststring in the mosh protocol.
type HostInstruction ¶
type HostInstruction struct {
Hoststring []byte
Width int32 // 0 = not present
Height int32 // 0 = not present
EchoAckNum int64 // -1 = not present
Control *LatchControl
}
HostInstruction is one instruction within a HostMessage. Represents the extension fields of HostBuffers.Instruction:
field 2 → HostBytes { field 4: hoststring }
field 3 → ResizeMessage { field 5: width, field 6: height }
field 7 → EchoAck { field 8: echo_ack_num }
func UnmarshalHostMessage ¶
func UnmarshalHostMessage(data []byte) ([]HostInstruction, error)
UnmarshalHostMessage decodes a HostMessage protobuf into a list of HostInstructions.
type LatchControl ¶
LatchControl is a latch extension control message.
type OCB ¶
type OCB struct {
// contains filtered or unexported fields
}
OCB implements AES-128-OCB3 authenticated encryption (RFC 7253).
func NewOCBFromBase64 ¶
NewOCBFromBase64 creates an OCB cipher from a base64-encoded key.
type PacketAddr ¶
type PacketAddr string
PacketAddr is a lightweight net.Addr for injected packet transports.
func (PacketAddr) Network ¶
func (a PacketAddr) Network() string
func (PacketAddr) String ¶
func (a PacketAddr) String() string
type PacketConn ¶
type PacketConn interface {
ReadFrom(p []byte) (int, net.Addr, error)
WriteTo(p []byte, addr net.Addr) (int, error)
Close() error
LocalAddr() net.Addr
}
PacketConn is a datagram-oriented server transport. It is intentionally smaller than net.PacketConn so embedders can provide non-UDP transports, while still exposing LocalAddr for MOSH CONNECT lines.
type PreparedTakeover ¶
type PreparedTakeover struct {
// contains filtered or unexported fields
}
PreparedTakeover holds a generated key/transport association that can later be committed by a trusted control plane. Preparing does not affect the currently attached client.
func (*PreparedTakeover) KeyBase64 ¶
func (t *PreparedTakeover) KeyBase64() string
KeyBase64 returns the prepared mosh key as a base64 string without padding.
type RecvResult ¶
RecvResult reports whether a datagram passed the authenticated transport layer and, when available, the reassembled SSP diff payload.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a native mosh server. It listens on UDP, runs a shell in a PTY, bridges data through the SSP transport, and diffs terminal framebuffers to produce HostMessage updates for the client.
func NewServer ¶
NewServer creates a native mosh server. It binds a UDP port, generates a key, and is ready to serve.
func NewServerConn ¶
func NewServerConn(shell string, conn PacketConn) (*Server, error)
NewServerConn creates a native mosh server over an injected packet transport. The packet transport may be UDP or a tunnel-provided datagram connection. LocalAddr is used to populate Port and ConnectLine.
func (*Server) CommitTakeover ¶
func (s *Server) CommitTakeover(t *PreparedTakeover) error
CommitTakeover applies a prepared association while keeping the existing PTY/shell and terminal state alive.
func (*Server) ConnectLine ¶
ConnectLine returns the MOSH CONNECT line that clients parse.
func (*Server) Done ¶
func (s *Server) Done() <-chan struct{}
Done returns a channel that is closed when the server shuts down.
func (*Server) KeyBase64 ¶
KeyBase64 returns the mosh key as a base64 string (22 chars, no padding).
func (*Server) PrepareTakeover ¶
func (s *Server) PrepareTakeover() (*PreparedTakeover, error)
PrepareTakeover generates a fresh client association without applying it. Call CommitTakeover only after the replacement attach channel is ready.
func (*Server) ServeConn ¶
func (s *Server) ServeConn(conn PacketConn) error
ServeConn replaces the server's packet transport and then calls Serve.
func (*Server) ServeRW ¶
func (s *Server) ServeRW(rw io.ReadWriteCloser, resize func(cols, rows uint16)) error
ServeRW runs the event loop using an external io.ReadWriteCloser instead of spawning a shell in a PTY. The caller provides terminal I/O through rw and a resize callback. When rw is closed or reaches EOF, the server shuts down.
func (*Server) SetNetworkTimeout ¶
SetNetworkTimeout sets the idle network timeout. The server exits when no authenticated packets are received for this duration. A non-positive timeout restores the default.
func (*Server) Takeover ¶
Takeover resets the client association and transport key while keeping the existing PTY/shell and terminal state alive. It is intended for a trusted control plane that wants a fresh client process to attach to an existing server session without reusing old SSP sequence numbers.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport implements the mosh State Synchronization Protocol (SSP).
It manages sequence numbering, acknowledgements, retransmission timing, and the fragment/encrypt/decrypt pipeline. Both client and server use the same Transport with different direction bits.
The caller provides state diffs (server: terminal output, client: keystrokes) and receives remote state updates.
func NewTransport ¶
NewTransport creates a transport. isServer determines direction bits.
func (*Transport) AckedByRemote ¶
AckedByRemote returns the highest state number the remote has acked.
func (*Transport) ForceNextSend ¶
func (t *Transport) ForceNextSend()
ForceNextSend forces the next tick to send, even with no pending diff.
func (*Transport) LastRecvNewNum ¶
LastRecvNewNum returns the newNum from the most recently received diff.
func (*Transport) LastRecvOldNum ¶
LastRecvOldNum returns the oldNum from the most recently received diff.
func (*Transport) Recv ¶
func (t *Transport) Recv(wire []byte) (RecvResult, error)
Recv processes an incoming wire datagram. It returns Authenticated only after direction, replay, OCB tag, and timestamp checks pass. Authenticated datagrams may still have no complete diff yet, for example heartbeats, duplicate fragments, or partial fragments.
func (*Transport) RemoteCaps ¶
func (*Transport) SetPending ¶
SetPending sets the diff payload to send on the next tick.
func (*Transport) ThrowawayNum ¶
ThrowawayNum returns the server's throwaway number — states below this are no longer referenced by the server and can be safely pruned.
type TransportInstruction ¶
type TransportInstruction struct {
ProtocolVersion uint32
OldNum uint64
NewNum uint64
AckNum uint64
ThrowawayNum uint64
Diff []byte
Chaff []byte
LatchCaps []byte
}
TransportInstruction is the outer transport wrapper (TransportBuffers.Instruction).
Field numbers:
1: protocol_version (uint32) 2: old_num (uint64) 3: new_num (uint64) 4: ack_num (uint64) 5: throwaway_num (uint64) 6: diff (bytes) 7: chaff (bytes)
func (*TransportInstruction) Marshal ¶
func (ti *TransportInstruction) Marshal() []byte
func (*TransportInstruction) Unmarshal ¶
func (ti *TransportInstruction) Unmarshal(data []byte) error
type UserInstruction ¶
type UserInstruction struct {
Keys []byte
Width int32 // 0 = not present
Height int32 // 0 = not present
Control *LatchControl
}
UserInstruction is one instruction within a UserMessage. Represents the extension fields of ClientBuffers.Instruction:
field 2 → Keystroke { field 4: keys }
field 3 → ResizeMessage { field 5: width, field 6: height }