Documentation
¶
Overview ¶
client.go
Package client implements the RDP client, and carries the RFB (VNC) client this fork inherited from upstream alongside it.
The VNC client (VncClient) is exercised against a real server by scripts/vnc-dev.sh, which starts TigerVNC's Xtigervnc and runs the live tests in protocol/rfb. Its clipboard is implemented in both directions: text the server cuts arrives as the "clipboard-text" event, and SetClipboardText publishes with ClientCutText.
Index ¶
- Constants
- func Bpp(bp uint16) int
- type Bitmap
- type Client
- func (c *Client) Close()
- func (c *Client) KeyDown(sc int, name string)
- func (c *Client) KeyUp(sc int, name string)
- func (c *Client) Login() error
- func (c *Client) LoginContext(ctx context.Context) error
- func (c *Client) MouseDown(button, x, y int)
- func (c *Client) MouseMove(x, y int)
- func (c *Client) MouseUp(button, x, y int)
- func (c *Client) MouseWheel(scroll, x, y int)
- func (c *Client) OnBitmap(f func([]Bitmap))
- func (c *Client) OnClipboardText(f func(text string))
- func (c *Client) OnClose(f func())
- func (c *Client) OnError(f func(e error))
- func (c *Client) OnOrdersFrame(f func(dirty image.Rectangle))
- func (c *Client) OnPointer(f func(p *pdu.PointerDataPDU))
- func (c *Client) OnPointerPosition(f func(x, y int))
- func (c *Client) OnReady(f func())
- func (c *Client) OnSuccess(f func())
- func (c *Client) OnSurfaceFrame(f func(frameID uint32, surfaces []*rdpgfx.Surface))
- func (c *Client) OnSurfaceReset(f func(width, height int))
- func (c *Client) RequestClipboardText() error
- func (c *Client) Screen() *orders.Screen
- func (c *Client) SetClipboardText(text string) error
- type Control
- type RdpClient
- func (c *RdpClient) Close()
- func (c *RdpClient) KeyDown(sc int, name string)
- func (c *RdpClient) KeyUp(sc int, name string)
- func (c *RdpClient) Login(host, user, pwd string, width, height int) error
- func (c *RdpClient) MouseDown(button int, x, y int)
- func (c *RdpClient) MouseMove(x, y int)
- func (c *RdpClient) MouseUp(button int, x, y int)
- func (c *RdpClient) MouseWheel(scroll, x, y int)
- func (c *RdpClient) On(event string, f interface{})
- func (c *RdpClient) RequestClipboardText() error
- func (c *RdpClient) SetClipboardText(text string) error
- type Setting
- type VncClient
- func (c *VncClient) Close()
- func (c *VncClient) KeyDown(sc int, name string)
- func (c *VncClient) KeyUp(sc int, name string)
- func (c *VncClient) Login(host, user, pwd string, width, height int) error
- func (c *VncClient) MouseDown(button int, x, y int)
- func (c *VncClient) MouseMove(x, y int)
- func (c *VncClient) MouseUp(button int, x, y int)
- func (c *VncClient) MouseWheel(scroll, x, y int)
- func (c *VncClient) On(event string, f interface{})
- func (c *VncClient) RequestClipboardText() error
- func (c *VncClient) SetClipboardText(text string) error
Constants ¶
const ( CLIP_OFF = 0 CLIP_IN = 0x1 CLIP_OUT = 0x2 )
Clipboard directions accepted by the (currently inert) Setting.SetClipboard.
const ( TC_RDP = 0 TC_VNC = 1 )
Transport kinds accepted by NewClient: TC_RDP for RDP, TC_VNC for VNC (RFB).
const DefaultLoginTimeout = 30 * time.Second
DefaultLoginTimeout bounds how long Login waits for the RDP session to become ready after the transport handshake succeeds.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Bitmap ¶
type Bitmap struct {
DestLeft int `json:"destLeft"`
DestTop int `json:"destTop"`
DestRight int `json:"destRight"`
DestBottom int `json:"destBottom"`
Width int `json:"width"`
Height int `json:"height"`
BitsPerPixel int `json:"bitsPerPixel"`
IsCompress bool `json:"isCompress"`
Data []byte `json:"data"`
}
Bitmap is one decoded rectangle of the remote screen.
The rectangle is [DestLeft, DestRight) x [DestTop, DestBottom) on the desktop; Width and Height are the size of the source data and are usually equal to the destination size. Data is top-down BGRA (B first) at BitsPerPixel/8 bytes per pixel when IsCompress is false, which is how OnBitmap delivers RDP updates.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is one session with an RDP or VNC server. It picks a protocol-specific implementation from the type given to NewClient (RdpClient or VncClient) and exposes one API for input, events, the clipboard and the framebuffer.
A Client is safe for concurrent use. Build one with NewClient; the zero value is not usable. Nothing is sent until Login is called.
func NewClient ¶
NewClient returns an unconnected session for host, which must be "address:port". t selects the transport: TC_RDP for RDP, TC_VNC for VNC. A nil s is replaced by NewSetting, so the common call is NewClient(host, user, pass, TC_RDP, nil).
No connection is made here. Call Login to connect, and Close when done.
func (*Client) Close ¶
func (c *Client) Close()
Close ends the session and closes the underlying connection. It is safe to call more than once and on a client that never connected, and it is safe to call concurrently with input methods, which become no-ops once the connection is gone.
func (*Client) KeyDown ¶
KeyDown presses the key whose PC set 1 scancode is sc, with the same extended key handling as KeyUp. name is ignored.
func (*Client) KeyUp ¶
KeyUp releases the key whose PC set 1 scancode is sc. A value in 0xE000..0xE0FF is sent as an extended key: the low byte is the scancode and the 0xE0 prefix becomes the extended flag. name is accepted for source compatibility and ignored; the scancode is what reaches the server.
func (*Client) LoginContext ¶
LoginContext is Login with an explicit context. It returns only once the server has completed the connection sequence and the session is ready, or when the handshake fails, the connection is closed, or ctx expires.
func (*Client) MouseDown ¶
MouseDown presses button 0 (left), 1 (middle) or 2 (right) at (x, y), with the same numbering as MouseUp.
func (*Client) MouseMove ¶
MouseMove moves the pointer to (x, y) in screen pixels from the top left.
func (*Client) MouseUp ¶
MouseUp releases button 0 (left), 1 (middle) or 2 (right) at (x, y). Any other value only moves the pointer. The numbering is the sender's, not the protocol's.
func (*Client) MouseWheel ¶
MouseWheel turns the wheel by scroll notches at (x, y); positive is up (away from the user) and the magnitude is clamped to the protocol's 9 bit field.
func (*Client) OnBitmap ¶
OnBitmap registers f to be called with each bitmap update, already expanded and converted to BGRA at 32 bpp where the source was compressed. f may see the same underlying data reused by the next update, so copy anything it keeps. For VNC the Bitmap rectangles carry the VNC pixel format instead.
func (*Client) OnClipboardText ¶
OnClipboardText reports text the server has put on the clipboard. It only fires when the clipboard channel is enabled.
func (*Client) OnClose ¶
func (c *Client) OnClose(f func())
OnClose registers f to be called when the connection to the server is gone. Like the other handlers it may be registered before Login.
func (*Client) OnError ¶
OnError registers f to be called with a handshake or transport error. Handlers may be registered before Login; they are kept and delivered once the session layers exist.
func (*Client) OnOrdersFrame ¶ added in v0.3.0
OnOrdersFrame reports that a batch of drawing orders changed the screen, giving the area that changed. The pixels are in Client.Screen.
func (*Client) OnPointer ¶
func (c *Client) OnPointer(f func(p *pdu.PointerDataPDU))
OnPointer reports slow-path pointer updates (PDUTYPE2_POINTER), which carry either a new position or a pointer shape.
func (*Client) OnPointerPosition ¶
OnPointerPosition reports the server-side pointer position (fast-path FASTPATH_UPDATETYPE_PTR_POSITION). It is useful to confirm that mouse input reached the remote session.
func (*Client) OnReady ¶
func (c *Client) OnReady(f func())
OnReady registers f to be called once the session is negotiated and the server is about to send its first update. It fires before any bitmap or order callback.
func (*Client) OnSuccess ¶
func (c *Client) OnSuccess(f func())
OnSuccess registers f to be called when the server accepts the credentials, before the session is ready to draw.
func (*Client) OnSurfaceFrame ¶
OnSurfaceFrame reports each completed EGFX frame and the surfaces it touched. The pixel data lives on the surfaces, so callers that need it should copy what they need before returning.
func (*Client) OnSurfaceReset ¶
OnSurfaceReset reports the desktop size an EGFX server will composite into, which also means any previously known surfaces are gone.
func (*Client) RequestClipboardText ¶
RequestClipboardText asks the server for the clipboard text it last announced. OnClipboardText normally triggers this by itself, but a server can announce a format before it is able to serve it, in which case an explicit request made later is what gets the data.
func (*Client) Screen ¶ added in v0.3.0
Screen returns the framebuffer that drawing orders are rendered into, or nil when Setting.EnableOrders was not set. It holds BGRA pixels, top down, and is safe to read while the connection is running.
func (*Client) SetClipboardText ¶
SetClipboardText publishes text on the shared clipboard, so a paste on the server pastes it. It only does anything when the clipboard channel is enabled.
type Control ¶
type Control interface {
Login(host, user, passwd string, width, height int) error
KeyUp(sc int, name string)
KeyDown(sc int, name string)
MouseMove(x, y int)
MouseWheel(scroll, x, y int)
MouseUp(button int, x, y int)
MouseDown(button int, x, y int)
On(event string, msg interface{})
SetClipboardText(text string) error
RequestClipboardText() error
Close()
}
Control is the small surface both clients implement, so that Client can hold either one. Callers normally use Client rather than this.
type RdpClient ¶
type RdpClient struct {
// contains filtered or unexported fields
}
RdpClient is the RDP implementation of Control. NewClient builds one (stored unexported) for TC_RDP; callers interact with it through Client, which forwards input, events and the clipboard to it.
func (*RdpClient) Close ¶
func (c *RdpClient) Close()
Close closes the underlying transport. It is safe on a partially built client and more than once; input methods become no-ops afterwards.
func (*RdpClient) KeyDown ¶
KeyDown presses sc. See Client.KeyUp for the scancode and extended key conventions. name is ignored.
func (*RdpClient) KeyUp ¶
KeyUp releases sc. See Client.KeyUp for the scancode and extended key conventions. name is ignored.
func (*RdpClient) Login ¶
Login dials host, builds the protocol stack (TPKT/X.224/MCS/security/PDU) and starts the connection. user may be "user", "DOMAIN\user" or "domain/user": the domain is split off and sent separately.
Login returns once the connection has been established, which is before the session is usable. The session becomes ready asynchronously and is reported on the "ready" event; errors and closure arrive on "error" and "close". Use Client.Login or Client.LoginContext to connect and wait for readiness in one call.
func (*RdpClient) MouseMove ¶
MouseMove moves the pointer to (x, y) in screen pixels from the top left.
func (*RdpClient) MouseWheel ¶
MouseWheel turns the wheel by scroll notches at (x, y); positive is up.
func (*RdpClient) On ¶
On registers a handler for an event. It may be called before Login, in which case handlers are buffered and replayed once the layer that produces them exists; this ordering is what lets a caller register handlers and then call Login without losing the "ready" event.
Event names: "ready", "success", "error" (error), "close", "bitmap" ([]pdu.BitmapData), "surface-bits" (*pdu.SurfaceBitsCommand), "orders" ([]pdu.OrderPdu), "orders-frame" (image.Rectangle), "pointer" (*pdu.PointerDataPDU), "pointer-position" (*pdu.FastPathPointerPositionPDU), "clipboard-text" (string), and "gfx-frame"/"gfx-reset" from the graphics channel. f must have the type the event carries or the receive will panic.
func (*RdpClient) RequestClipboardText ¶
RequestClipboardText asks the server for its clipboard text.
func (*RdpClient) SetClipboardText ¶
SetClipboardText publishes text on the shared clipboard.
type Setting ¶
type Setting struct {
// Width and Height are the desktop size requested from the server, in
// pixels. They are sent in the MCS connect sequence and must be positive;
// NewSetting uses 1024x768.
Width int
Height int
// Protocol selects the security path: "tls" (the default) or "ssl" for
// TLS, "nla", "hybrid" or "credssp" for CredSSP, and "rdp" or "standard"
// for Standard RDP Security with no TLS. The empty string means TLS, and an
// unrecognised value falls back to TLS with a warning rather than failing.
Protocol string
// Timeout bounds the whole of Login, from dial to ready. Zero or negative
// means DefaultLoginTimeout (30s).
Timeout time.Duration
// LogLevel is applied to the package-global glog logger by NewClient. The
// default is glog.INFO; glog.NONE silences the library.
LogLevel glog.LEVEL
// NoFastPathInput forces keyboard/mouse input over the slow path even
// when the server advertised fast-path input. Useful for debugging.
NoFastPathInput bool
// EnableEGFX opens the dynamic virtual channel needed for the RDP
// Graphics Pipeline Extension, so the server can composite surfaces and
// send them as compressed bitmaps instead of bitmap updates.
//
// This is off by default: it has not been exercised against a server that
// speaks EGFX, and enabling it changes how the server draws the session.
EnableEGFX bool
// EnableClipboard opens the clipboard channel so text can be exchanged
// with the server. Use Client.OnClipboardText and Client.SetClipboardText
// to bridge it to the local clipboard.
EnableClipboard bool
// EnableOrders advertises support for the MEMBLT drawing order and renders
// the drawing orders that follow, into a framebuffer reachable through
// Client.Screen.
//
// It is off by default because it changes how the server draws the session
// and it cannot mix: once MEMBLT is advertised the server stops sending
// bitmap updates and puts everything through the bitmap cache instead. With
// it off the session is drawn from bitmap updates, which is correct, just
// larger on the wire.
EnableOrders bool
}
Setting configures a session. NewSetting returns one with usable defaults; the fields below are only read when Login is called, so they may be changed until then.
func NewSetting ¶
func NewSetting() *Setting
NewSetting returns a Setting with the default desktop size (1024x768), the default login timeout and INFO logging.
func (*Setting) SetClipboard ¶
SetClipboard is inert: it does nothing. Use Setting.EnableClipboard to open the clipboard channel.
func (*Setting) SetLogLevel ¶
func (s *Setting) SetLogLevel()
SetLogLevel pushes LogLevel into the package-global glog logger. NewClient already does this, so it only needs calling if the level is changed after the client is built.
func (*Setting) SetRequestedProtocol ¶
SetRequestedProtocol is inert: it does nothing. Set Setting.Protocol instead, which is read when Login negotiates the security path.
type VncClient ¶
type VncClient struct {
// contains filtered or unexported fields
}
VncClient is the RFB (VNC) client. It is exercised against a real server by scripts/vnc-dev.sh, which starts TigerVNC and runs the live tests: a frame is received and parsed, and the clipboard works in both directions. Raw and CopyRect encodings only, and RequestClipboardText is not implemented.
Login blocks until the handshake completes, fails, or the configured timeout expires, so it is safe to register handlers and drive input afterwards; before it returns those calls do nothing rather than panic.
func (*VncClient) Close ¶
func (c *VncClient) Close()
Close implements the Control interface. It does nothing until Login has completed.
func (*VncClient) KeyDown ¶
KeyDown implements the Control interface. It does nothing until Login has completed.
func (*VncClient) KeyUp ¶
KeyUp implements the Control interface. It does nothing until Login has completed.
func (*VncClient) Login ¶
Login dials the server and returns only once the RFB handshake has completed, the handshake has failed, or the timeout expires. The handshake is event driven, so it is driven to a result the caller can see instead of returning while it is still running. scripts/vnc-dev.sh runs this against a real server.
func (*VncClient) MouseDown ¶
MouseDown implements the Control interface. It does nothing until Login has completed.
func (*VncClient) MouseMove ¶
MouseMove implements the Control interface. It does nothing until Login has completed.
func (*VncClient) MouseUp ¶
MouseUp implements the Control interface. It does nothing until Login has completed.
func (*VncClient) MouseWheel ¶
MouseWheel implements the Control interface. It does nothing until Login has completed.
func (*VncClient) On ¶
On registers a listener. A listener registered before Login is held until there is a connection to attach it to, so a caller that registers before connecting still receives events.
func (*VncClient) RequestClipboardText ¶
RequestClipboardText is not supported by RFB and says so. Unlike the RDP clipboard channel, RFB has no client message that asks for the server's cut text: the server sends ServerCutText whenever its clipboard changes, and the only client-to-server message, ClientCutText, publishes rather than requests. Text therefore arrives through OnClipboardText with no request behind it.
func (*VncClient) SetClipboardText ¶
SetClipboardText publishes text on the server's clipboard. RFB carries it as one ClientCutText message. There is no acknowledgement, so a nil error only means the bytes were written to the socket.