Documentation
¶
Overview ¶
Package server exposes the workspace to the browser front end.
It listens on the loopback interface only and requires a token that is generated per run and handed to the window in its URL, so nothing else on the machine can drive the agents through it.
Index ¶
- Variables
- func Probe(baseURL, token string) (*healthMsg, error)
- func RequestOpen(baseURL, token, path string) error
- func RequestQuit(baseURL, token string) error
- func RequestRemoteReload(baseURL, token string) error
- type RemoteAccess
- type Server
- func (s *Server) Addr() string
- func (s *Server) Attach()
- func (s *Server) BaseURL() string
- func (s *Server) ClientCount() int
- func (s *Server) Close() error
- func (s *Server) Detach()
- func (s *Server) Detached() bool
- func (s *Server) LocalClientCount() int
- func (s *Server) RefreshGitNow()
- func (s *Server) RemoteHandler() http.Handler
- func (s *Server) ServeRemote(l net.Listener) error
- func (s *Server) SetRemote(r RemoteAccess)
- func (s *Server) SetUpdate(u *UpdateView)
- func (s *Server) Token() string
- func (s *Server) URL() string
- func (s *Server) Update() *UpdateView
- func (s *Server) Wake()
- type UpdateView
Constants ¶
This section is empty.
Variables ¶
var ErrNotReady = errors.New("the instance is not ready")
ErrNotReady marks the one failure worth waiting out: flockdeck is listening on that address, it just cannot answer for its workspace this moment.
It is exported for the launch deciding what an error from Probe means. Every other failure says nothing is there; this one says an instance is there and busy, and taking it for a stale record would start a rival set of agents beside the ones it is busy with.
var Version = "dev"
Version is reported by the health endpoint. main sets it at startup.
Functions ¶
func Probe ¶
Probe checks whether a recorded instance is alive and answering, and returns what it reports about itself.
An instance that answers but reports itself not ready is given a while: the caller's only other option is to declare the record stale and start a rival instance, which splits the agents in two and is much the worse mistake.
func RequestOpen ¶
RequestOpen asks a running instance to open a project.
func RequestQuit ¶
RequestQuit asks a running instance to shut down, and waits for it to have gone.
The instance answers as soon as it has accepted the request; stopping every agent and saving the layout comes after. Returning on the acceptance made `flockdeck -quit` say "stopped" while it was still going, and left the next launch racing it: a `flockdeck` typed straight afterwards would probe the instance on its way out, find it answering, and attach to a process that was about to exit -- ending up with a window onto nothing.
func RequestRemoteReload ¶ added in v0.2.0
RequestRemoteReload asks a running instance to reread the enrolment.
Types ¶
type RemoteAccess ¶ added in v0.2.0
type RemoteAccess interface {
Status() (remote.Status, bool)
Client() (*remote.Client, error)
Reload() error
Enable(ctx context.Context, req remote.EnableRequest) (replaced bool, err error)
Disable(ctx context.Context, force bool) (untold error, err error)
Reconnect() error
}
RemoteAccess is what the server needs of remote access: to say how the tunnel is, to reach the relay on the window's behalf, to be told to reread the enrolment, and to turn it on and off and try the relay again from the dialog as `flockdeck remote` does from a terminal.
type Server ¶
type Server struct {
// OnLastClientGone is called when the final window closes, so the
// application can decide whether to shut down.
OnLastClientGone func()
// OnQuit is called when a shutdown is requested from the interface or by
// another launch of the binary.
OnQuit func()
// OnRestart is called when the interface asks to come back up on a newly
// downloaded version. It is separate from OnQuit because the shutdown has
// to know whether to start the program again once it has replaced it.
OnRestart func()
// OnDetach is called when the instance becomes detached -- from a window,
// or by -detach at start -- once each time it goes from attached to
// detached, and never on the workspace goroutine. It is how the application
// lets go of what tied it to the way it was started: on Windows, the console
// a -no-window run was launched from, whose closing would otherwise end it.
OnDetach func()
// contains filtered or unexported fields
}
Server serves the front end and the live connections behind it.
func (*Server) Attach ¶
func (s *Server) Attach()
Attach reverses a detach, so closing the window quits again.
func (*Server) BaseURL ¶
BaseURL is the address without the token, for the health and control endpoints a second launch uses.
func (*Server) ClientCount ¶
ClientCount reports how many windows are currently connected.
func (*Server) Detach ¶
func (s *Server) Detach()
Detach makes the application keep running after its last window closes, so the agents carry on and can be reattached to later. OnDetach is told once each time the instance goes from attached to detached, on a goroutine of its own: a window's Detach arrives on the workspace goroutine, and whatever the hook does is not that goroutine's to wait for.
func (*Server) LocalClientCount ¶ added in v0.2.0
LocalClientCount reports how many windows on this machine are connected — every window, that is, but the ones reached through the relay.
It is what decides whether the application is still being looked at. A remote window is somebody elsewhere, and whether it is open says nothing about the window on the desk: closing that one still quits an instance that was not detached, and a remote window closing never quits anything. The way to leave the agents running for a remote window to find is the same as it always was — detach.
func (*Server) RefreshGitNow ¶
func (s *Server) RefreshGitNow()
RefreshGitNow asks the git loop to re-examine the checkouts straight away. It is safe to call from any goroutine and never blocks; a request made while one is already pending is folded into it.
func (*Server) RemoteHandler ¶ added in v0.2.0
RemoteHandler is the window's own set of handlers, with every request marked as having arrived through the tunnel.
func (*Server) ServeRemote ¶ added in v0.2.0
ServeRemote answers the connections arriving on l, which is one tunnel's worth of them, until l is closed or the server is.
Closing l ends the serving but not a WebSocket already handed over: those have left net/http's hands, and it is closing the tunnel under them — which is what the caller does when it closes l — that ends them.
func (*Server) SetRemote ¶ added in v0.2.0
func (s *Server) SetRemote(r RemoteAccess)
SetRemote hands the server its remote access, which may be nil.
func (*Server) SetUpdate ¶
func (s *Server) SetUpdate(u *UpdateView)
SetUpdate records that a release has been staged and is ready to be applied by a restart, and has the windows told.
Nothing else would tell them. A snapshot goes out when something changes, and a release is staged in the background, hours into a run, most likely while the agents sit waiting and nobody is touching the window -- which is then not told until something unrelated happens.
func (*Server) URL ¶
URL is the address the window should open, including the token that authorises it.
func (*Server) Update ¶
func (s *Server) Update() *UpdateView
Update returns the staged release, or nil when there is none.
type UpdateView ¶
type UpdateView struct {
Version string `json:"version"`
Notes string `json:"notes,omitempty"`
URL string `json:"url,omitempty"`
}
UpdateView is a downloaded release as the interface shows it.