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 Server
- func (s *Server) Close()
- func (s *Server) ConnectLine() string
- func (s *Server) Done() <-chan struct{}
- func (s *Server) KeyBase64() string
- func (s *Server) Port() int
- func (s *Server) Serve() error
- func (s *Server) ServeRW(rw io.ReadWriteCloser, resize func(cols, rows uint16)) 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) []byte
- 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 ¶ added in v0.3.0
DialConn creates a mosh client over an existing datagram connection. Use this with WebTransport or other non-UDP transports.
func DialConnManual ¶ added in v0.3.0
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 ¶ added in v0.4.0
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 ¶ added in v0.4.0
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 ¶ added in v0.3.0
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.
func (*FragmentAssembler) Add ¶
func (a *FragmentAssembler) Add(f Fragment) []byte
Add processes a fragment and returns the reassembled message when complete. Returns nil if the message is not yet complete. Drops fragments from old instruction IDs.
type Framebuffer ¶
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 ¶ added in v0.2.0
func SnapshotEmulator(emu *vt.Emulator, cursorVisible bool) *Framebuffer
SnapshotEmulator captures the VT emulator state 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 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 (*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) 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.
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 ¶ added in v0.2.1
AckedByRemote returns the highest state number the remote has acked.
func (*Transport) ForceNextSend ¶ added in v0.2.1
func (t *Transport) ForceNextSend()
ForceNextSend forces the next tick to send, even with no pending diff.
func (*Transport) LastRecvNewNum ¶ added in v0.4.0
LastRecvNewNum returns the newNum from the most recently received diff.
func (*Transport) LastRecvOldNum ¶ added in v0.4.0
LastRecvOldNum returns the oldNum from the most recently received diff.
func (*Transport) Recv ¶
Recv processes an incoming wire datagram. Returns the diff payload if a complete message was reassembled, or nil.
func (*Transport) RemoteCaps ¶
func (*Transport) SetPending ¶
SetPending sets the diff payload to send on the next tick.
func (*Transport) ThrowawayNum ¶ added in v0.5.0
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 }