hub

package
v2.7.8 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 33 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 hub implements EdgeFetch's self-hosted Go multi-node WebSocket controller (`--mode=hub` and hybrid mesh `--mode=hub,agent`), allowing one static Go binary to serve as both central fleet coordinator and fallback HTTP/2 + Chromium worker with zero external runtime dependencies beyond `coder/websocket`.

Capabilities

  • Accepts outbound Go worker connections on `GET /agent/ws` (authenticated via `EDGEFETCH_AGENT_TOKEN` or per-site `EDGEFETCH_AGENT_TOKENS`), streaming gzipped artifacts on `PUT /agent/artifacts/{sha}` and job completions on `POST /agent/reply`.
  • Routes requests across connected nodes using sticky host affinity, Least-Recently-Used (`lastJobAt`) fairness, capability matching (`browser-v1`), and per-`(site, host)` `429` cooldown failover, falling back automatically to the local in-process `*crawl.Crawler` when no remote agents are available.
  • Exposes `GET /health`, `GET /agents`, `GET /v1/capabilities`, `POST /fetch`, `POST /v1/scrape`, and a built-in Streamable HTTP Model Context Protocol server on `POST /mcp`.
  • When paired with `--mode=hub,agent` and `EDGEFETCH_HUB_URLS`, enables active-active multi-controller and Tailscale/LAN standby mesh topologies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseAgentTokensJSON

func ParseAgentTokensJSON(raw string) (map[string]string, error)

ParseAgentTokensJSON parses `EDGEFETCH_AGENT_TOKENS` (`{"site-1":"<token>"}`) and enforces >= 24-char secrets.

Types

type AgentInfo

type AgentInfo struct {
	SiteID       string   `json:"siteId"`
	Arch         string   `json:"arch"`
	Version      string   `json:"version,omitempty"`
	Capabilities []string `json:"capabilities"`
	Busy         bool     `json:"busy"`
	ConnectedAt  int64    `json:"connectedAt"`
	LastJobAt    int64    `json:"lastJobAt,omitempty"`
	JobsOK       int64    `json:"jobsOk"`
	JobsErr      int64    `json:"jobsErr"`
}

AgentInfo summarizes a connected worker node in `GET /agents` and MCP `list_agents`.

type Config

type Config struct {
	CallerToken         string
	AgentToken          string
	AgentTokens         map[string]string
	PeerURLs            []string
	PeerToken           string
	PeerHTTPClient      *http.Client
	FallbackCrawler     *crawl.Crawler
	BotSigner           *botauth.Signer
	BotPublicJWKs       []botauth.PublicJWK
	BotContactURL       string
	UserAgent           string
	AllowedLoopbackPort string
	MaxConcurrentCalls  int
	Allow               func(*url.URL) error
	Logger              *slog.Logger
	DispatchTimeout     time.Duration
	MaxArtifactMemory   int
	OtelExporter        *otel.Exporter
}

Config configures a self-hosted Go Hub controller instance.

type Server

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

Server coordinates connected Go edge workers and serves `/fetch`, `/v1/scrape`, and `/mcp`.

func NewServer

func NewServer(cfg Config) *Server

NewServer constructs a ready-to-serve Go Hub `http.Handler`.

func (*Server) Close

func (s *Server) Close() error

Close disconnects any active agent WebSockets cleanly during server shutdown.

func (*Server) DispatchOrFallback

func (s *Server) DispatchOrFallback(
	ctx context.Context,
	call crawl.FetchCall,
	target, preferredSite string,
	traceHdr http.Header,
) (reply crawl.FetchReply, via string, status int, err error)

DispatchOrFallback routes `call` to a connected WebSocket agent (failing over on 429/disconnect), or falls back to the Hub's in-process `FallbackCrawler` when `target` is `"auto"` or `"container"`.

func (*Server) ListAgents

func (s *Server) ListAgents() map[string]any

ListAgents returns fleet status across all currently connected WebSocket workers.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP routes control-plane (`/agent/*`) and caller-plane (`/health`, `/agents`, `/fetch`, `/v1/*`, `/mcp`) requests.

Jump to

Keyboard shortcuts

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