server

package
v0.3.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 49 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

linkgone.go answers a window that arrives at a one-time link (see server.go's WindowURL) that has already been used, or has run out, with a page in the house style rather than a bare refusal -- and says which of the two it was, since they read very differently: a link used a moment too late is ordinary, where a link already used by the time its own window got to it is the one thing in R3.7.2 worth a person's attention.

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, so nothing else on the machine can drive the agents through it. The window is handed it through a one-time link (see WindowURL), never in the URL on its browser's command line.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoWindowLinks = errors.New("the instance gives out no one-time links")

ErrNoWindowLinks is what RequestWindowURL returns for an instance from a build that gives out no one-time links, which knows no /window.

View Source
var ErrNotOurs = errors.New("what answers there is not the instance on record")

ErrNotOurs marks an answer from something other than the instance on record: a service of another kind that has taken the port since, or another user's flockdeck, which refuses this token. Either way the record the address came from is stale, and nothing there is to be asked to quit.

View Source
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.

View Source
var Version = "dev"

Version is reported by the health endpoint. main sets it at startup.

Functions

func Identify added in v0.3.3

func Identify(baseURL, token string) (*healthMsg, error)

Identify asks what answers at a recorded address who it is, once: Probe without its patience for an instance that is busy. It is what `flockdeck -quit` asks before asking anything to stop, and a wedged instance is the one it most needs to reach.

An instance that answers but is not ready comes back with ErrNotReady and what it said of itself, its process id among it. Anything that is not this user's flockdeck comes back with ErrNotOurs.

func Probe

func Probe(baseURL, token string) (*healthMsg, error)

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

func RequestOpen(baseURL, token, path string) error

RequestOpen asks a running instance to open a project.

func RequestQuit

func RequestQuit(baseURL, token string, pid int) error

RequestQuit asks a running instance to shut down, and waits for it to have gone: to have stopped answering, and then, where pid names its process, for that process to have exited. pid is what the instance said it was, and 0 where nothing was said.

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.

Its port closing is not the end of it either. The port is closed first, so that nothing reaches the workspace while it is saved; saving every project, stopping the agents and clearing the record all come after. Returning as the port closed let `flockdeck -quit && flockdeck` start a second instance beside the first one's agents, still running.

func RequestRemoteReload added in v0.2.0

func RequestRemoteReload(baseURL, token string) error

RequestRemoteReload asks a running instance to reread the enrolment.

func RequestWindowURL added in v0.3.3

func RequestWindowURL(baseURL, token string) (string, error)

RequestWindowURL asks a running instance for a one-time link to open a window at.

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)
	Rename(ctx context.Context, name string) 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, rename this machine 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 New

func New(ws *workspace.Workspace) (*Server, error)

New starts a server for the workspace on a free loopback port.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the listening address.

func (*Server) Attach

func (s *Server) Attach()

Attach reverses a detach, so closing the window quits again.

func (*Server) BaseURL

func (s *Server) BaseURL() string

BaseURL is the address without the token, for the health and control endpoints a second launch uses.

func (*Server) ClientCount

func (s *Server) ClientCount() int

ClientCount reports how many windows are currently connected.

func (*Server) Close

func (s *Server) Close() error

Close shuts the server down.

func (*Server) ConversationHookEvent added in v0.3.8

func (s *Server) ConversationHookEvent(paneID string)

ConversationHookEvent is told a pane's id whenever a hook event about it arrives (see Workspace.SetConversationHook), which is the sign that its transcript may have grown a line worth tailing. A pane already held by the hub -- a client has it open, or has had it open before -- is simply re-tailed. One never opened by any client is still worth a stream of its own now, so the phone's inbox row can show a preview of an agent pane nobody has looked at yet: resolvePane answers found=false for a shell or a pane that has gone, which is the only filter needed to keep this to agent panes.

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) Detached

func (s *Server) Detached() bool

Detached reports whether the application should outlive its windows.

func (*Server) LocalClientCount added in v0.2.0

func (s *Server) LocalClientCount() int

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 (s *Server) NewWindowLink() (url, link string)

NewWindowLink is WindowURL, together with the link's own token -- not the full URL -- for SetLinkFile.

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

func (s *Server) RemoteHandler() http.Handler

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

func (s *Server) ServeRemote(l net.Listener) error

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) SetLinkFile added in v0.3.5

func (s *Server) SetLinkFile(link, path string) bool

SetLinkFile records that link's one-time link was written into a local redirect file at path (see appwindow), so that file is removed the moment the link is redeemed or runs out, instead of left for somebody to come across later. It reports whether link was still outstanding to record this against; where it was not -- redeemed or expired already, in the moment between the file being written and this being called -- the caller should remove path itself, since nothing will do it on its behalf.

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) Stopped added in v0.3.3

func (s *Server) Stopped() <-chan struct{}

Stopped is closed once the workspace goroutine has let go of the workspace for good: after Close, and after the change it was applying as the server closed has run its course. Until then the workspace is still that goroutine's, and saving or closing it from anywhere else races it.

func (*Server) Token

func (s *Server) Token() string

Token returns the per-run token.

func (*Server) URL

func (s *Server) URL() string

URL is the address of the interface, including the token that authorises it, for somebody to open by hand: it is what a run without a window prints. A window this program opens is given WindowURL instead.

func (*Server) Update

func (s *Server) Update() *UpdateView

Update returns the staged release, or nil when there is none.

func (*Server) Wake

func (s *Server) Wake()

Wake tells the server that workspace state changed and clients should be updated. It is safe to call from any goroutine and never blocks.

func (*Server) WindowURL added in v0.3.3

func (s *Server) WindowURL() string

WindowURL is an address for a window this program opens: a link that can be used once, within windowLinkLife, and that the page exchanges for the token, in a cookie, as it loads.

The window used to be opened at URL, and the address a browser is started with stays on its command line for as long as it runs -- all day, for the window -- where any other user of the machine can read it, in ps or /proc/<pid>/cmdline. With the token from it, a program of theirs could open the control socket and drive every agent: a WebSocket client that is not a browser sends no Origin to be turned away for. A link that has been used, or has run out, opens nothing.

A link is no safer to leave on a command line than the token was -- anybody quick enough to read it there could redeem it first -- so appwindow writes it into a private local file instead, and starts the browser at that. NewWindowLink is WindowURL for a caller in a position to have that file removed the moment the link stops being any good, rather than left for appwindow's own backstop timer to find; a second launch asking over /window (see handleWindow) has no such moment to hand it, and its file relies on that timer alone.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL