anywhere

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package anywhere implements the runtime-side connector for Miren Anywhere, the connectivity feature that links a cluster to Miren Cloud's POP network for NAT traversal and inbound request forwarding.

Index

Constants

View Source
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

func (c *Client) OnConnect(fn func(ctx context.Context))

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

func (c *Client) Run(ctx context.Context) error

Run maintains the WebSocket connection with reconnection. It blocks until the context is cancelled.

func (*Client) Send

func (c *Client) Send(env *Envelope)

Send queues an envelope for delivery to the cloud. Non-blocking; drops the message if the outbox is full.

func (*Client) SendMessage

func (c *Client) SendMessage(msgType string, data any) error

SendMessage marshals data and queues it for delivery.

type Config

type Config struct {
	CloudURL   string
	ClusterXID string
	AuthClient *cloudauth.AuthClient
	Ingress    *httpingress.Server
	Log        *slog.Logger
}

Config holds the configuration for the Miren Anywhere connector.

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 Connector

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

Connector connects the cluster to the cloud coordination service and manages POP connections for inbound traffic forwarding. It is the runtime side of Miren Anywhere.

func New

func New(cfg Config) *Connector

New creates a Connector. It wires up the cloud client and POP manager, registers the connection, time-sync, and org-info message handlers, and arranges for a time-sync and org-info request to be sent on each new connection.

func (*Connector) OrganizationID

func (c *Connector) OrganizationID() string

OrganizationID returns the organization ID reported by the cloud.

func (*Connector) Run

func (c *Connector) Run(ctx context.Context) error

Run starts the connector. It blocks until the context is cancelled.

func (*Connector) TimeOffset

func (c *Connector) TimeOffset() time.Duration

TimeOffset returns the estimated clock offset between this cluster and the cloud, computed via simplified NTP.

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 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:

  1. Control plane (ALPN "h3"): POST /connect with the connect_token
  2. 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) Close

func (m *POPManager) Close()

Close shuts down all POP connections.

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

type TimeRequest struct {
	ClientTransmitTime time.Time `json:"client_transmit_time"`
}

TimeRequest is the payload for time.request messages.

type TimeResponse

type TimeResponse struct {
	ClientTransmitTime time.Time `json:"client_transmit_time"`
	ServerReceiveTime  time.Time `json:"server_receive_time"`
	ServerTransmitTime time.Time `json:"server_transmit_time"`
}

TimeResponse carries the four timestamps needed for simplified NTP.

Jump to

Keyboard shortcuts

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