Documentation
¶
Index ¶
Constants ¶
const ( TypeTimeRequest = "time.request" TypeTimeResponse = "time.response" TypeOrgInfoRequest = "org.info.request" TypeOrgInfoResponse = "org.info.response" // TypeConnectionRequest is sent from cloud to cluster when a POP // server needs the cluster to establish an HTTP/3 connection. TypeConnectionRequest = "connection.request" )
Message type constants matching the cloud's wire protocol.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client maintains a persistent WebSocket connection to the cloud coordination service with automatic reconnection.
func NewClient ¶
func NewClient(cloudURL string, authClient *cloudauth.AuthClient, router *MessageRouter, log *slog.Logger) *Client
NewClient creates a new WebSocket client.
func (*Client) OnConnect ¶
OnConnect registers a callback invoked each time a WebSocket connection is established. The handler can use Send to queue messages for the new connection.
func (*Client) Run ¶
Run maintains the WebSocket connection with reconnection. It blocks until the context is cancelled.
type Config ¶
type Config struct {
CloudURL string
ClusterXID string
AuthClient *cloudauth.AuthClient
Ingress *httpingress.Server
Log *slog.Logger
}
Config holds the configuration for the global router.
type ConnectionRequest ¶
type ConnectionRequest struct {
POPXID string `json:"pop_xid"`
POPAddress string `json:"pop_address"`
Hostname string `json:"hostname"`
RequestID string `json:"request_id"`
ConnectToken string `json:"connect_token"`
}
ConnectionRequest is the payload for connection.request messages.
type Envelope ¶
type Envelope struct {
Type string `json:"type"`
Data json.RawMessage `json:"data"`
}
Envelope is the wire format for all messages on the WebSocket.
type GlobalRouter ¶
type GlobalRouter struct {
// contains filtered or unexported fields
}
GlobalRouter connects the cluster to the cloud coordination service and manages POP connections for inbound traffic forwarding.
func (*GlobalRouter) OrganizationID ¶
func (gr *GlobalRouter) OrganizationID() string
OrganizationID returns the organization ID reported by the cloud.
func (*GlobalRouter) Run ¶
func (gr *GlobalRouter) Run(ctx context.Context) error
Run starts the global router. It blocks until the context is cancelled.
func (*GlobalRouter) TimeOffset ¶
func (gr *GlobalRouter) TimeOffset() time.Duration
TimeOffset returns the estimated clock offset between this cluster and the cloud, computed via simplified NTP.
type MessageHandler ¶
type MessageHandler func(ctx context.Context, data json.RawMessage) error
MessageHandler processes an inbound message.
type MessageRouter ¶
type MessageRouter struct {
// contains filtered or unexported fields
}
MessageRouter dispatches inbound messages by type.
func NewMessageRouter ¶
func NewMessageRouter() *MessageRouter
NewMessageRouter creates a new MessageRouter.
func (*MessageRouter) Dispatch ¶
func (r *MessageRouter) Dispatch(ctx context.Context, env Envelope) error
Dispatch routes a message to the appropriate handler.
func (*MessageRouter) Handle ¶
func (r *MessageRouter) Handle(msgType string, handler MessageHandler)
Handle registers a handler for a given message type.
type OrgInfoResponse ¶
type OrgInfoResponse struct {
OrganizationID string `json:"organization_id"`
}
OrgInfoResponse is the payload for org.info.response messages.
type POPManager ¶
type POPManager struct {
// contains filtered or unexported fields
}
POPManager manages HTTP/3 connections to POP servers. When the cloud sends a connection.request, the manager establishes two QUIC connections to the POP:
- Control plane (ALPN "h3"): POST /connect with the connect_token
- Data plane (ALPN "pop-data"): authenticated by IP match, then serves incoming HTTP/3 requests forwarded by the POP
func NewPOPManager ¶
func NewPOPManager(clusterXID string, ingress *httpingress.Server, log *slog.Logger) *POPManager
NewPOPManager creates a new POP connection manager.
func (*POPManager) ConnectedPOPs ¶
func (m *POPManager) ConnectedPOPs() []string
ConnectedPOPs returns the XIDs of all currently connected POPs.
func (*POPManager) HandleConnectionRequest ¶
func (m *POPManager) HandleConnectionRequest(ctx context.Context, req ConnectionRequest) error
HandleConnectionRequest processes a connection.request from the cloud. It establishes connections to the specified POP if one does not already exist.
func (*POPManager) RemovePOP ¶
func (m *POPManager) RemovePOP(popXID string)
RemovePOP closes and removes the connection to a specific POP.
type TimeRequest ¶
TimeRequest is the payload for time.request messages.