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 ¶
- func ParseAgentTokensJSON(raw string) (map[string]string, error)
- type AgentInfo
- type Config
- type Server
- func (s *Server) Close() error
- func (s *Server) DispatchOrFallback(ctx context.Context, call crawl.FetchCall, target, preferredSite string, ...) (reply crawl.FetchReply, via string, status int, err error)
- func (s *Server) ListAgents() map[string]any
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 (*Server) Close ¶
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 ¶
ListAgents returns fleet status across all currently connected WebSocket workers.