Documentation
¶
Overview ¶
Package remote connects a running Flockdeck to a relay, so the window can be opened from another device.
The desktop never listens for anyone. It dials out to the relay, holds one WebSocket open, and carries a stream multiplexer over it; the relay opens a stream for each connection a paired browser makes, and each stream is served here by the very handlers the local window uses. Nothing on this machine is reachable from the network that was not before, and no port is opened.
What the relay is, and what it may see, is described in the relay's own design notes: traffic is TLS on both legs and the relay decrypts it to route it. It is trusted, and the help says so rather than implying otherwise.
Index ¶
- Constants
- Variables
- func CheckRelay(raw string) (string, error)
- func Clear() error
- func IsRevoked(err error) bool
- func QRSVG(text string) (string, error)
- func QRTerminal(text string) (string, error)
- func RelayURL(named string) (string, error)
- type APIError
- type Client
- type Config
- type Connector
- type Device
- type Host
- type Manager
- type Pairing
- type RegisterRequest
- type Registration
- type Roster
- type State
- type Status
Constants ¶
const ( KindDevice = "device" KindHost = "host" )
Pairing kinds.
const ( // CloseRevoked: the host's token is no longer accepted. CloseRevoked websocket.StatusCode = 4001 // CloseReplaced: another connection has come in for the same host, and a // host has only one. Most often that is a second Flockdeck on this machine, // started with -solo; fighting it for the slot would have the two of them // knock each other off the relay every few seconds for as long as both run. CloseReplaced websocket.StatusCode = 4002 )
The relay closes the tunnel with one of these when retrying would be wrong.
const DefaultRelay = "https://remote.flockdeck.ai"
DefaultRelay is the relay a machine is enrolled with when nobody names one.
It was https://relay.flockdeck.ai in v0.2.0, and a machine enrolled then keeps that address in its remote.json. That is fine: the relay still answers desktops on its old name, and sends a browser that arrives there to this one.
const File = "remote.json"
File is where the enrolment is kept, in the state directory.
const RelayEnv = "FLOCKDECK_RELAY"
RelayEnv overrides DefaultRelay, for somebody running a relay of their own or developing against one.
const Subprotocol = "flockdeck-relay.v1"
Subprotocol is what the tunnel is spoken as. A relay that does not know it is not one this build can talk to.
Variables ¶
var ErrNotEnabled = errors.New("remote access is not enabled on this machine; run `flockdeck remote enable` in a terminal")
ErrNotEnabled is what anything that needs an enrolment is told when there is none.
Functions ¶
func CheckRelay ¶
CheckRelay insists on a relay address that can be trusted with the token.
That means HTTPS. The host token and everything a paired device types cross this connection, and the relay being trusted is no help if the hop to it is not. Plain HTTP is allowed only to this machine itself, which is where a relay being developed or tested runs, and where there is no network for the traffic to cross.
func Clear ¶
func Clear() error
Clear forgets the enrolment. It is not an error for there to be none.
func QRSVG ¶
QRSVG draws text as a QR code, as an SVG document.
It is dark modules on a white square whatever the window's theme is. A code drawn in the theme's colours would be light on dark in this application, and while some readers cope with an inverted code, a phone's own camera is not reliably one of them.
func QRTerminal ¶
QRTerminal draws text as a QR code in text, two modules to a line.
Each character covers two rows with the half-block characters, which keeps the code square in a terminal whose cells are about twice as tall as they are wide. Light modules are the ones drawn, so on the dark background most terminals have, the code comes out the right way round: dark modules on a light field, quiet zone included.
Types ¶
type Client ¶
Client makes the relay's REST calls on behalf of an enrolled host.
type Config ¶
type Config struct {
Relay string `json:"relay"`
HostID string `json:"hostId"`
AccountID string `json:"accountId"`
Token string `json:"token"`
Name string `json:"name,omitempty"`
}
Config is this machine's enrolment with a relay.
Token is the credential the relay knows this host by. It is a secret with the same reach as the window itself — whoever holds it can mint pairing codes, and a paired device can type into every agent — so it lives in a 0600 file in the state directory beside the local server's own token, is never printed, and never travels anywhere but to the relay that issued it.
func Load ¶
Load returns the enrolment, or nil when this machine has none.
A file that is there and cannot be understood is an error rather than "not enabled": answering that would tell the user remote access is off while a relay still holds a live host for this machine, and invite them to enrol it a second time.
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector holds one host's tunnel to its relay open, and serves whatever arrives through it.
func NewConnector ¶
func NewConnector(cfg Config, version string, serve func(net.Listener) error, changed func()) *Connector
NewConnector prepares a tunnel for an enrolment; Start opens it.
func (*Connector) Start ¶
func (c *Connector) Start()
Start opens the tunnel and keeps it open until Stop, or until the relay says there is no point.
type Device ¶
type Device struct {
ID string `json:"id"`
Name string `json:"name"`
Created time.Time `json:"created"`
LastSeen time.Time `json:"lastSeen"`
}
Device is a browser paired with the account.
type Host ¶
type Host struct {
ID string `json:"id"`
Name string `json:"name"`
Online bool `json:"online"`
LastSeen time.Time `json:"lastSeen"`
Self bool `json:"self"`
}
Host is a desktop enrolled in the account; Self marks this one.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is remote access as a running instance has it: the enrolment on disk, and the tunnel that goes with it.
The enrolment is written by `flockdeck remote`, from another process, and the instance is told to look again. Reload is that looking: it brings the tunnel in line with whatever the file now says — opened, reopened to a different relay, or closed.
func NewManager ¶
NewManager makes a manager with nothing running. serve answers each tunnel's connections; changed is told whenever what the window should show moves.
func (*Manager) Close ¶
func (m *Manager) Close()
Close closes the tunnel, and every remote window with it.
func (*Manager) Reload ¶
Reload reads the enrolment again and makes the tunnel match it.
A tunnel that already matches is left alone, so reloading costs a working connection nothing. One that has given up — revoked, or displaced by another instance — is started again, because being asked to reload is somebody saying that whatever stopped it has been dealt with.
A file that cannot be read is reported and the tunnel left as it was: there is no telling what the file meant, and dropping every remote window over a half-written file is the worse guess.
type Pairing ¶
type Pairing struct {
Code string `json:"code"`
URL string `json:"url"`
ExpiresAt time.Time `json:"expiresAt"`
}
Pairing is a one-time code, and for a device the link that redeems it.
type RegisterRequest ¶
type RegisterRequest struct {
Name string `json:"name"`
Join string `json:"join,omitempty"`
Invite string `json:"invite,omitempty"`
}
RegisterRequest enrols a machine. Join puts it in the account a host-kind pairing code belongs to rather than a new one; Invite is what a relay that does not take registrations from just anyone asks for.
type Registration ¶
type Registration struct {
HostID string `json:"hostId"`
AccountID string `json:"accountId"`
Token string `json:"token"`
}
Registration is what the relay hands back for a new host.
func Register ¶
func Register(ctx context.Context, relay, version string, req RegisterRequest) (*Registration, error)
Register enrols this machine with a relay. It is the one call made without a token, because it is the one that gets one.
type Status ¶
type Status struct {
State State `json:"state"`
Detail string `json:"detail,omitempty"`
Since time.Time `json:"since"`
// RetryAt is when the next attempt is due, while one is being waited for.
RetryAt time.Time `json:"retryAt,omitzero"`
Relay string `json:"relay"`
HostID string `json:"hostId"`
Name string `json:"name,omitempty"`
}
Status is what the window and the command line are told about the tunnel.