Documentation
¶
Overview ¶
Package protocol is the message format of Remote Work (SPEC §10.18): the messages the host and the client send each other once the login is done, in a binary form that is versioned, length-prefixed and limited in size.
A message is a type byte, a length (4 bytes, big endian) and a payload of exactly that length:
type:1 | length:4 | payload:length
The length is checked against the limit of the type before anything is read or allocated, so a peer that lies about it costs nothing: no decoder allocates more than the limit of the type it was told (MaxPayload). A message is refused, never repaired, when its type is unknown, its length is over the limit, it ends early, it has bytes left over, or a field holds a value the format does not allow (an unknown enum, a string that is not UTF-8, a number that is not finite, a size of zero). Every accepted message encodes back to the bytes it was decoded from.
The package imports nothing of Emetos but the errors package, so the tests of the transports can use it. The pixels travel as Tile messages, the pictures themselves are made by package tiles. A Missing lists the tiles of the newest picture a client did not receive on the datagrams of package transport (step 15.3).
Index ¶
- Constants
- func Append(dst []byte, m Message) ([]byte, error)
- func MaxPayload(t Type) (int, bool)
- func TilesAcross(n int) int
- func ValidSize(width, height int) bool
- type Clipboard
- type Disconnect
- type FrameConfirm
- type Hello
- type Key
- type KeyKind
- type Message
- type Missing
- type Mouse
- type MouseKind
- type Notification
- type NotificationAction
- type Ping
- type Reader
- type Reason
- type Refresh
- type Resize
- type Scroll
- type Severity
- type Tile
- type Type
- type Writer
Constants ¶
const ( // TileSize is the side of a tile in pixels: the picture is cut into squares of 64x64, the ones at the right and bottom // edges smaller. TileSize = 64 // BytesPerPixel is the size of a pixel of a tile before it is deflated: R, G, B, A, one byte each, not premultiplied. BytesPerPixel = 4 // MaxTileData is the limit of the deflated data of one tile: a whole tile does not deflate to more than the pixels // themselves plus the few bytes of the format, so this holds with room to spare. MaxTileData = TileSize*TileSize*BytesPerPixel + 1024 // MaxDimension is the largest width or height of a picture. MaxDimension = 7680 // MaxPixels is the largest picture, in pixels (a 4K display): it bounds the memory of the pictures both sides keep. MaxPixels = 3840 * 2160 // MaxToken is the longest session token. MaxToken = 64 // MaxKeyText is the longest text of a key event, in bytes. MaxKeyText = 32 // MaxClipboard is the longest clipboard text, in bytes. MaxClipboard = 1 << 20 // MaxSource, MaxMessageText, MaxActions and MaxActionLabel limit a notification: the name of its source, its text, the // number of its actions and the label of an action, in bytes where they are texts. MaxSource = 128 MaxMessageText = 4096 MaxActions = 8 MaxActionLabel = 128 // MaxReasonText is the longest explanation of a disconnect. MaxReasonText = 256 )
The limits of the fields.
const ( // ButtonPrimary is the left button. ButtonPrimary uint8 = 1 << iota // ButtonSecondary is the right button. ButtonSecondary // ButtonMiddle is the wheel button. ButtonMiddle )
The bits of Mouse.Buttons, the ones of Glutter's pointer buttons.
const HeaderSize = 5
HeaderSize is the size of the type and the length that start every message.
const Magic = "EMRW"
Magic starts every Hello, so that a stream that is not Remote Work is refused at its first message.
const MaxFrameTiles = 4096
MaxFrameTiles is the most tiles one picture sends: the datagram layer of the transports numbers the tiles of a picture with a u16, and a Missing lists them in a bitmap of at most MaxFrameTiles/8 bytes. A picture of the largest size (MaxPixels) has 2,040 tiles at most.
const MaxMessage = HeaderSize + MaxClipboard
MaxMessage is the size of the largest message, header included: what a buffer for any message needs.
const Version = 1
Version is the version of the protocol. Hello carries it and the two sides must agree: a peer with another version is refused (Hello.Check), because the format has no way to skip what it does not know.
Variables ¶
This section is empty.
Functions ¶
func Append ¶
Append encodes the message, header included, after dst and returns the extended slice. On an error dst is returned as it was. Nothing is allocated beyond what the message needs (the size of its payload is at most MaxPayload).
The error has the tags RemoteWorkEncodeInvalid (a field the format does not allow), RemoteWorkEncodeTooLarge (a field over its limit) and RemoteWorkNilMessage.
func MaxPayload ¶
MaxPayload is the limit of the payload of a type, and false for a byte that is no type.
func TilesAcross ¶
TilesAcross is the number of tiles in a row (or column) of a picture that is n pixels wide (or high).
Types ¶
type Clipboard ¶
type Clipboard struct {
// Text is the text, at most MaxClipboard bytes of UTF-8.
Text string
}
Clipboard carries the text of a copy or a paste, only when the user copies or pastes. Field: Text, the whole payload.
type Disconnect ¶
type Disconnect struct {
// Reason is why the session ends.
Reason Reason
// Text explains it, at most MaxReasonText bytes; may be empty.
Text string
}
Disconnect ends the session. Fields: Reason (1 byte) and Text (2-byte length, text).
type FrameConfirm ¶
type FrameConfirm struct {
// Frame is the number of the picture the client has, at least 1.
Frame uint64
}
FrameConfirm tells the host that the client has the whole picture Frame: the next pictures are sent as the changes to it. Field: Frame (8 bytes).
type Hello ¶
type Hello struct {
// Version is the version of the protocol the sender speaks.
Version uint16
// Token is the session token (SPEC §10.18), at most MaxToken bytes; the host's answer carries none.
Token []byte
}
Hello opens a session: the client sends it first, with the token the host gave it over the SSH channel, and the host answers with its own (an empty token). Fields: the Magic (4 bytes), Version (2), the length of Token (1) and Token.
type Key ¶
type Key struct {
// Kind is whether the key went down, up or repeats.
Kind KeyKind
// Physical is the USB HID usage of the key (Glutter's PhysicalKeyboardKey), which does not depend on the layout.
Physical uint64
// Logical is the ID of the key (Glutter's LogicalKeyboardKey), which does.
Logical uint64
// Text is what the key typed, at most MaxKeyText bytes; empty for a release or a key that types nothing.
Text string
}
Key is a key event with the text it produced, so that the layout of the client's keyboard and its input method decide what is typed. Fields: Kind (1 byte), Physical (8), Logical (8), the length of Text (1) and Text.
type Message ¶
type Message interface {
// Type is the type byte of the message.
Type() Type
// contains filtered or unexported methods
}
Message is one message of the protocol. The types are the ones of this package, so a message can be made only here.
func Decode ¶
Decode decodes one message that fills b exactly, a datagram for instance. The length in the header is checked against the limit of the type before the payload is looked at, and the fields of the message are copied out of b.
The error has the tags RemoteWorkTruncated, RemoteWorkUnknownType, RemoteWorkTooLarge, RemoteWorkTrailing, RemoteWorkBadValue and RemoteWorkBadMagic.
type Missing ¶
type Missing struct {
// Frame is the picture, counted from 1 as in Tile.
Frame uint64
// Total is the number of tiles of the picture (Tile.Total), at least 1 and at most MaxFrameTiles.
Total uint32
// Bitmap has a bit set for each tile the client lacks: at least one, and none past Total.
Bitmap []byte
}
Missing is how a client asks the host for the tiles of the newest picture that did not arrive on the datagrams (step 15.3; the SSH channel loses nothing and never sends it). The tiles of a picture are numbered from 0 in the order the host sent them; the bitmap has one bit for each, set (bit i % 8 of byte i / 8) for the ones the client lacks. Fields: Frame (8 bytes), Total (4) and Bitmap, which fills the rest of the payload and is exactly (Total+7)/8 bytes.
func NewMissing ¶
NewMissing makes the Missing of a picture from what the client has: have[i] says whether tile i arrived. It returns nil when nothing is missing or the picture has no tiles or too many.
type Mouse ¶
type Mouse struct {
// Kind is whether the pointer moved or a button went down or up.
Kind MouseKind
// Buttons are the buttons that are down after the event, as bits of the Button constants.
Buttons uint8
// X and Y are the position, finite numbers.
X, Y float32
}
Mouse is a pointer event in the coordinates of the view, in pixels. Fields: Kind (1 byte), Buttons (1), X (4, a 32-bit float) and Y (4).
type Notification ¶
type Notification struct {
// ID identifies the notification in NotificationAction.
ID uint64
// Severity is how serious it is.
Severity Severity
// Source is who raised it, at most MaxSource bytes.
Source string
// Message is the text, at most MaxMessageText bytes.
Message string
// Actions are the labels of the buttons, at most MaxActions of at most MaxActionLabel bytes.
Actions []string
}
Notification is a notification of the workspace, shown on the client with its actions; an action that is chosen comes back as a NotificationAction and runs on the host. Fields: ID (8 bytes), Severity (1), Source (2-byte length, text), Message (2-byte length, text), the number of actions (1) and each label (2-byte length, text).
type NotificationAction ¶
type NotificationAction struct {
// ID is the ID of the Notification.
ID uint64
// Action is the index in the Actions of the notification, below MaxActions.
Action uint8
}
NotificationAction is the action of a notification that the user chose on the client. Fields: ID (8 bytes) and Action (1).
type Ping ¶
type Ping struct {
// Seq numbers the ping; the answer repeats it.
Seq uint64
// Reply is true in the answer.
Reply bool
}
Ping measures the round trip and keeps a quiet session from idling out: the peer answers with the same Seq and Reply set. Fields: Seq (8 bytes) and Reply (1, 0 or 1).
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader decodes the messages of a stream, one after the other. It holds one buffer, as large as the largest payload it has seen, so it allocates nothing more than the limit of the type of the message it reads. Its methods are not safe for concurrent use.
func (*Reader) Next ¶
Next reads the next message. A stream that ends between two messages gives an error whose cause is io.EOF; one that ends inside a message gives io.ErrUnexpectedEOF. After any error but a RemoteWorkReadFailed the stream is out of step and must be closed: the format has no way to find the next message.
The error has the tags of Decode and RemoteWorkReadFailed.
type Reason ¶
type Reason uint8
Reason is why a session ends.
const ( // ReasonClosed: the sender ended the session on purpose (the user closed the tab). ReasonClosed Reason = iota // ReasonHost: the user of the host pressed Disconnect. ReasonHost // ReasonIdle: the idle timeout of the host passed. ReasonIdle // ReasonOff: Remote Work was turned off for the workspace. ReasonOff // ReasonProtocol: the peer sent something the protocol does not allow. ReasonProtocol // ReasonVersion: the peer speaks another version of the protocol. ReasonVersion // ReasonReplaced: another client took the session. ReasonReplaced // ReasonWorkspaceClosed: the workspace was closed on the host. ReasonWorkspaceClosed )
The reasons of a disconnect.
type Refresh ¶
type Refresh struct{}
Refresh asks the host to send the whole picture again (a client that lost its picture, or came back). It has no fields.
type Resize ¶
type Resize struct {
// Width and Height are the size, allowed by ValidSize.
Width, Height uint16
}
Resize is the size of the client's view, in pixels; the host makes its view that large. Fields: Width (2 bytes) and Height (2).
type Scroll ¶
type Scroll struct {
// X and Y are the position of the pointer, in pixels.
X, Y float32
// DX and DY are the distance scrolled, in pixels, positive towards the right and the bottom.
DX, DY float32
}
Scroll is a scroll of the wheel or the trackpad. Fields: X, Y, DX and DY (4 bytes each, 32-bit floats).
type Tile ¶
type Tile struct {
// Frame is the number of the picture, counted from 1.
Frame uint64
// Base is the picture the tiles of Frame are the changes to: the last one the client confirmed, 0 for none (then every
// tile of the picture is sent). It is below Frame.
Base uint64
// Width and Height are the size of the picture in pixels (ValidSize).
Width, Height uint16
// X and Y are the column and the row of the tile, in tiles.
X, Y uint16
// Total is the number of tiles that Frame sends, at least 1 and at most the number of tiles of the picture; the
// client has the picture when it has that many.
Total uint32
// Data is the deflated pixels of the tile (package tiles), 1 to MaxTileData bytes.
Data []byte
}
Tile is one changed tile of a picture. It stands alone, so that it can travel as a datagram: it says which picture it is of, how large that is, where the tile is and how many tiles the picture has to change. Fields: Frame (8 bytes), Base (8), Width (2), Height (2), X (2), Y (2), Total (4) and Data, which fills the rest of the payload.
type Type ¶
type Type uint8
Type is the type byte of a message.
const ( // TypeHello opens a session, in both directions. TypeHello Type = iota + 1 // TypeTile carries one changed tile of a picture. TypeTile // TypeFrameConfirm says which picture the client has completely. TypeFrameConfirm // TypeRefresh asks for the whole picture again. TypeRefresh // TypeKey is a key event with the text it produced. TypeKey // TypeMouse is a pointer event. TypeMouse // TypeScroll is a scroll of the wheel or the trackpad. TypeScroll // TypeClipboard carries the text of a copy or a paste. TypeClipboard // TypeNotification is a notification of the workspace with its actions. TypeNotification // TypeNotificationAction is the action of a notification the user chose. TypeNotificationAction // TypeResize is the size of the client's view. TypeResize // TypePing measures the round trip and keeps the session from idling. TypePing // TypeDisconnect ends the session with a reason. TypeDisconnect // TypeMissing lists the tiles of the newest picture that a client lost on the datagrams (step 15.3). TypeMissing )
The types of the messages. A byte that is not one of them is refused (RemoteWorkUnknownType): the versions of the two sides are equal, so there is nothing to skip.