hub

package
v0.10.0-dev.23 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main()

Main is the entry point for the telahubd binary. The cmd/telahubd shim calls this; tests do not -- they call Run() directly with an in-process config to avoid touching os.Args, telelog initialization, or service-mode dispatch.

func ResetForTesting

func ResetForTesting()

ResetForTesting wipes every piece of package-level mutable state in the hub: registered machines, per-WebSocket state, history events, pending management requests, UDP relay sessions, the global config, and the auth store. Tests call this in t.Cleanup so the next test starts from a clean slate.

This is a stop-gap until the hub is refactored into an instance type that can hold its own state. For now, "one hub per process" remains the rule and tests must run sequentially.

func Run

func Run(ctx context.Context, listenAddr string, addrCh chan<- string) error

Run starts the hub HTTP/WebSocket server and the supporting background goroutines (UDP relay, keepalive, session reaper, pair-code cleanup, portal sync). It blocks until ctx is cancelled, then shuts the server down gracefully and returns. Errors during startup are returned immediately; errors during normal operation that warrant shutdown are logged and cause Run to return after the cancel.

Run assumes the package-level configuration globals (globalCfg, globalAuth, httpPort, etc.) have already been populated by the caller. Production callers go through Main() which loads them from a YAML config and environment variables. Tests populate them directly via SetTestConfig and friends.

listenAddr is the bind address. Production passes "0.0.0.0:<port>"; tests pass "127.0.0.1:0" to get a random port. The actual listening address is reported on the addrCh channel (if non-nil) so tests can learn the chosen port.

func SetTestConfig

func SetTestConfig(cfg *Config)

SetTestConfig installs a config into the hub's package-level globals so a test-supplied configuration takes effect before Run is called. Production code goes through Main() which does the same population from a YAML file.

func SetUDPPortForTesting

func SetUDPPortForTesting(p int)

SetUDPPortForTesting overrides the package-level UDP port. Tests pass 0 here to ask the OS for a random free port -- this is the only way to do it because applyHubConfig deliberately ignores zero values (production callers use zero to mean "use the default").

func SetVersion

func SetVersion(v string)

SetVersion overrides the package-level version string. Called once from the cmd/telahubd shim before Main() so log lines and the self-update channel comparison see the real linker-supplied version.

Types

type BridgeConfig

type BridgeConfig = bridgeConfig

BridgeConfig is the exported name for bridgeConfig. It lets callers such as the in-process test harness (internal/teststack) construct bridge entries without a YAML round-trip.

type Config

type Config = hubConfig

Config is an alias for the package's internal hubConfig type. Exported only so the in-process test harness can construct a config without going through a YAML round-trip on disk.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig reads and parses a hub YAML config file from disk. Returns a *Config that can be passed to SetTestConfig and Run().

Jump to

Keyboard shortcuts

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