mobilehub

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 19 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

Package mobilehub routes the public mobile protocol to the Sidecar process that owns a selected terminal. It does not own terminal state or leases.

Index

Constants

View Source
const (
	OwnerCatalogTimeout = 8 * time.Second
	CatalogQueryTimeout = 13 * time.Second
)
View Source
const (
	OwnerHandshakeTimeout = 5 * time.Second
	OwnerStderrBytes      = 8 << 10
)

Variables

View Source
var (
	ErrIncompleteTargetSelection = errors.New("mobile hub: incomplete public target selection")
	ErrTargetOtherHub            = errors.New("mobile hub: this terminal belongs to another hub; refresh the sessions list")
	ErrTargetIdentityChanged     = errors.New("this terminal was replaced or restarted since the sessions list was loaded; refresh to reattach")
	ErrOwnerUnavailable          = errors.New("the host that owns this terminal is unavailable; retrying")
	ErrOwnerRemoved              = errors.New("the host that owns this terminal is no longer configured; refresh the sessions list")
	ErrOwnerNotServing           = errors.New("the host that owns this terminal is disabled or cannot serve terminals; enable or upgrade it in Sidecar")
)

Target lookup refusals. Only a real identity mismatch tells the client the terminal it listed is gone; an unreachable owner is a transient condition the client retries, so the two must never share a wire code.

View Source
var (
	ErrOwnerOutputOverflow = errors.New("mobile hub: owner output queue overflow")
	ErrOwnerClosed         = errors.New("mobile hub: owner stream closed")
)
View Source
var ErrOwnerNegotiationUnsupported = errors.New("owning service does not support requested terminal capabilities")

ErrOwnerNegotiationUnsupported distinguishes an older owner's hello refusal from a changed target or route. Never retry or silently downgrade the hello.

Functions

This section is empty.

Types

type BoundOwner

type BoundOwner struct {
	Authority CatalogAuthority
	// Capabilities is populated from this stream's validated owner hello.
	// The public broker uses the observed limits and timing; it never assumes
	// the owner's defaults match its own.
	Capabilities mobileproto.Capabilities
	Start        func(context.Context) (LineStream, mobileproto.Response, error)
	Validate     func(context.Context) error
}

BoundOwner is one current owner route. Start and Validate must remain bound to the same runtime client and stable registration represented by Authority.

type CatalogAuthority

type CatalogAuthority struct {
	HubID, HubConfigGeneration, OwnerHostID, RegistrationFingerprint string
}

CatalogAuthority identifies the hub configuration and stable owner registration that authorize one public catalog projection.

type CatalogRouter

type CatalogRouter struct {
	// contains filtered or unexported fields
}

func NewCatalogRouter

func NewCatalogRouter(directory OwnerDirectory) (*CatalogRouter, error)

func (*CatalogRouter) Lookup

Lookup reconstructs one public selector from the current owning catalog. This works across a fresh hub API process; no process-local catalog map is treated as authority. The returned stream remains open for target resolve.

func (*CatalogRouter) LookupWithHello added in v1.16.0

func (r *CatalogRouter) LookupWithHello(ctx context.Context, selector string, expected mobileproto.TargetIdentity, capabilities *mobileproto.ClientCapabilities, viewer *mobileproto.Viewer) (BoundOwner, LineStream, TargetBinding, error)

LookupWithHello negotiates terminal options when opening the selected owner, before the catalog query. A second hello on an established stream is invalid.

func (*CatalogRouter) Query

Query obtains one current unfiltered Project snapshot from each online owning service, then applies the phone's query once at the hub. Each owner gets exactly one catalog stream. Owners are asked concurrently, at most maxConcurrentOwnerQueries at a time, so a slow or unreachable remote never delays the others; the composed catalog and its failures are still in directory order.

The aggregate row, candidate and encoded-byte bounds are charged as each owner's catalog arrives, before it is retained. Charges only grow, so the first arrival that overflows makes the overflow certain: the query cancels every owner still running and refuses at once rather than holding the request, and every retained catalog, until the slowest owner answers.

A remote owner is bounded by ownerTimeout so one SSH route cannot hold the whole query. This machine's own owner is bounded only by the query's deadline: its collection is local work, and cutting it at the remote bound under load used to report the hub's own host offline with no rows while it was merely busy.

type CurrentDirectory

type CurrentDirectory struct {
	Identity                     mobile.CatalogIdentity
	Local                        OwnerEndpoint
	LocalRegistrationFingerprint string
	Remotes                      []RegisteredOwner
}

CurrentDirectory is the complete current hub authority. Provider calls must reload the owning config rather than return a startup snapshot.

type DirectoryProvider

type DirectoryProvider func(context.Context) (CurrentDirectory, error)

type DirectorySnapshot

type DirectorySnapshot struct {
	Identity  mobile.CatalogIdentity
	Hosts     []mobileproto.CatalogHost
	Endpoints []OwnerEndpoint
	Failures  []mobileproto.CatalogFailure
	Validate  func(context.Context) error
}

DirectorySnapshot freezes the hub configuration and available owner set for one catalog or target lookup. Validate rejects reload, removal or retargeting before the result can become authority.

type LineStream

type LineStream interface {
	WriteLine([]byte) error
	ReadLine(context.Context) ([]byte, error)
	Close()
}

LineStream is one hello-validated owning mobile service.

func StartLocal

StartLocal starts the hub machine's owning service in process, consumes and validates its private hello, and returns the same bounded line seam used for remote owners.

type LocalServiceFactory

type LocalServiceFactory func(io.Reader, io.Writer) (*mobile.Service, error)

type OwnerDirectory

type OwnerDirectory interface {
	Snapshot(context.Context) (DirectorySnapshot, error)
}

type OwnerEndpoint

type OwnerEndpoint struct {
	Host mobileproto.CatalogHost
	Bind func(context.Context) (BoundOwner, error)
}

OwnerEndpoint is one public host and a binder for its current owner route.

type OwnerStream

type OwnerStream struct {
	// contains filtered or unexported fields
}

OwnerStream is one validated remote `mobile serve` process. It forwards raw protocol lines after consuming the owner's private hello. Negotiated repaint frames coalesce by fence metadata; terminal payloads remain opaque.

func StartOwner

StartOwner starts the owning Sidecar through the exact bound registry client, sends the protocol's private hello, validates the actual owner capabilities, and revalidates the route before returning.

func (*OwnerStream) Close

func (s *OwnerStream) Close()

Close closes owner stdin and cancels the SSH command. The owner's existing EOF and process cleanup own exact lease release.

func (*OwnerStream) ReadLine

func (s *OwnerStream) ReadLine(ctx context.Context) ([]byte, error)

ReadLine reads one raw owner response or event with the caller's deadline.

func (*OwnerStream) Wait

func (s *OwnerStream) Wait(ctx context.Context) error

Wait reports the owner process result. Context cancellation is a normal local close; callers still treat unexpected EOF before close as terminal.

func (*OwnerStream) WriteLine

func (s *OwnerStream) WriteLine(line []byte) error

WriteLine forwards exactly one client request after current route validation. It appends the JSONL delimiter and never generates heartbeat or any other request itself.

type ProtocolBroker

type ProtocolBroker struct {
	// contains filtered or unexported fields
}

ProtocolBroker projects the v0 envelope and negotiated extensions over the service that owns a terminal. It never owns terminal state, sequence advancement, geometry, presence or input retry.

func NewProtocolBroker

func NewProtocolBroker(router *CatalogRouter) (*ProtocolBroker, error)

func (*ProtocolBroker) Run

func (b *ProtocolBroker) Run(ctx context.Context, input io.Reader, output io.Writer) error

Run owns input/output for this protocol lifetime, closing them on shutdown when they implement io.Closer. A non-closeable Reader/Writer must itself return on cancellation; arbitrary blocking Go IO cannot be interrupted. Queues are bounded: one scanned request, one owner event, eight public output lines with a 16 MiB aggregate budget, plus the selected LineStream's own eight-line bound. No additional owner streams accumulate across selections.

type RegisteredOwner

type RegisteredOwner struct {
	Host     hosts.Host
	Name     string
	Disabled bool
}

RegisteredOwner is one configured remote owner in display order. Disabled registrations remain visible but never create a registry client or route.

type RegistryDirectory

type RegistryDirectory struct {
	// contains filtered or unexported fields
}

RegistryDirectory projects current config and registry health into the catalog router. Terminal authority remains in each owning mobile service.

func NewRegistryDirectory

func NewRegistryDirectory(lifetime context.Context, registry *hosts.Registry, current DirectoryProvider) (*RegistryDirectory, error)

func (*RegistryDirectory) Snapshot

func (*RegistryDirectory) WaitInitial

func (d *RegistryDirectory) WaitInitial(ctx context.Context, maximum time.Duration) error

WaitInitial gives newly started remote observers a bounded opportunity to publish their first health result. A timeout is not an error: the next catalog snapshot keeps those owners visible as connecting failures while still returning every available owner. Caller cancellation remains fatal.

func (*RegistryDirectory) WaitOwner

func (d *RegistryDirectory) WaitOwner(ctx context.Context, hostID string, maximum time.Duration) error

WaitOwner waits only for the selected owner. A disconnected unrelated host must never delay terminal resolution on an owner that is already usable.

type RemappedCatalog

type RemappedCatalog struct {
	Source   mobile.CatalogSource
	Bindings map[string]TargetBinding
}

RemappedCatalog is one owner source ready for shared hub composition.

func RemapOwnerCatalog

func RemapOwnerCatalog(authority CatalogAuthority, snapshot mobileproto.CatalogSnapshot) (RemappedCatalog, error)

RemapOwnerCatalog converts one current owner's unfiltered project snapshot into stable hub-public identities. Raw owner handles and identities never leave this boundary.

type RouteRegistry

type RouteRegistry interface {
	ValidateMobileRoute(hosts.MobileRouteAuthority) error
	MobileSidecarCommand(context.Context, hosts.MobileRouteAuthority) (*exec.Cmd, error)
}

RouteRegistry is the narrow registered-host seam the hub uses. The production implementation is hosts.Registry; tests can inject owner processes without an SSH server.

type TargetBinding

type TargetBinding struct {
	PublicSelector string
	PublicExpected mobileproto.TargetIdentity
	OwnerSelector  string
	OwnerExpected  mobileproto.TargetIdentity
}

TargetBinding retains the raw owner identity behind one public opaque selector. It is process-local acceleration only. A fresh hub process reconstructs the same binding from a current owner catalog and exact-matches PublicExpected before forwarding reconnect.

Jump to

Keyboard shortcuts

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