userruntime

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RuntimeMetadataHeader = "X-Memoh-Runtime-Metadata"

	CapabilityFS     = "fs"
	CapabilityExec   = "exec"
	CapabilityHostFS = "host_fs"
)
View Source
const (
	KeyPrefix = "mrk_"
)
View Source
const RuntimeGRPCMessageLimit = 16 << 20

Variables

View Source
var (
	ErrPipeNotConfigured     = errors.New("runtime pipe is not configured")
	ErrInvalidPipeConnection = errors.New("invalid runtime pipe connection")
	ErrPipeConnectionUsed    = errors.New("runtime pipe connection already consumed")
	ErrPipeHandshake         = errors.New("runtime pipe handshake failed")
)
View Source
var (
	ErrInvalidInput              = errors.New("invalid runtime input")
	ErrRuntimeConnectionNotReady = errors.New("runtime connection is no longer ready")
)
View Source
var ErrInvalidKey = errors.New("invalid runtime key")
View Source
var (
	ErrInvalidMetadata = errors.New("invalid runtime metadata")
)
View Source
var ErrRuntimeHubClosed = errors.New("runtime hub is closed")

Functions

func DefaultRuntimeName

func DefaultRuntimeName(key string) string

DefaultRuntimeName is the placeholder assigned at credential creation when the caller does not pick a name. It is derived from the credential key (not user input), so the first handshake can safely replace it with the machine's hostname without ever touching a user-chosen name.

func NewKey

func NewKey() (string, error)

func ValidateKeyFormat

func ValidateKeyFormat(key string) error

Types

type Connection

type Connection struct {
	RuntimeID    string
	ConnectionID string
	Info         RuntimeInfo
	Client       *bridge.Client

	Close func(reason string)
	// contains filtered or unexported fields
}

Connection is one immutable, ready generation of a registered Runtime. RuntimeID is stable; ConnectionID changes on every successful reconnect.

type ConnectionCommitGuard

type ConnectionCommitGuard func() error

type CreateRuntimeRequest

type CreateRuntimeRequest struct {
	Name string `json:"name"`
}

type DirectPipe

type DirectPipe struct{}

DirectPipe runs a single gRPC h2c client connection directly over the byte stream supplied by the Runtime WebSocket. ClientConn takes ownership of conn on every path, including validation and handshake failures.

A Runtime reconnect is a new WebSocket and therefore a new DirectPipe call. The dialer below deliberately cannot return the byte stream more than once, so grpc-go cannot transparently attach this ClientConn to a new transport after the WebSocket is lost.

func NewDirectPipe

func NewDirectPipe() *DirectPipe

func (*DirectPipe) ClientConn

func (*DirectPipe) ClientConn(ctx context.Context, conn net.Conn) (*grpc.ClientConn, error)

type HandshakeInfo

type HandshakeInfo struct {
	Version       int      `json:"version"`
	Hostname      string   `json:"hostname"`
	OS            string   `json:"os"`
	Arch          string   `json:"arch"`
	ClientVersion string   `json:"client_version"`
	WorkspaceBase string   `json:"workspace_base"`
	Capabilities  []string `json:"capabilities"`
}

func ParseHandshakeMetadata

func ParseHandshakeMetadata(encoded string) (HandshakeInfo, error)

type Hub

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

func NewHub

func NewHub(log *slog.Logger) *Hub

func (*Hub) Get

func (h *Hub) Get(runtimeID string) (*Connection, bool)

func (*Hub) Kick

func (h *Hub) Kick(runtimeID string, reason string)

func (*Hub) Shutdown

func (h *Hub) Shutdown(_ context.Context) error

Shutdown atomically prevents new registrations and closes every online generation. Hijacked WebSockets are not closed by http.Server.Shutdown.

type Pipe

type Pipe interface {
	ClientConn(ctx context.Context, conn net.Conn) (*grpc.ClientConn, error)
}

type Runtime

type Runtime struct {
	ID            string    `json:"id"`
	TeamID        string    `json:"team_id"`
	Name          string    `json:"name"`
	Key           string    `json:"key"`
	CreatedAt     time.Time `json:"created_at"`
	Online        bool      `json:"online"`
	WorkspaceBase string    `json:"workspace_base,omitempty"`
	Hostname      string    `json:"hostname,omitempty"`
	OS            string    `json:"os,omitempty"`
	Arch          string    `json:"arch,omitempty"`
	ClientVersion string    `json:"client_version,omitempty"`
	Capabilities  []string  `json:"capabilities,omitempty"`
}

Runtime is one registered client. Machine details only exist while its reverse-RPC connection is online; they are not persisted.

type RuntimeInfo

type RuntimeInfo struct {
	WorkspaceBase string
	Hostname      string
	OS            string
	Arch          string
	ClientVersion string
	Capabilities  []string
}

type Service

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

Service owns the persistent pending/activated credential registry and the in-memory reverse-RPC connections. Bot/session routing belongs outside this package.

func NewService

func NewService(store dbstore.UserRuntimeStore, hub *Hub) *Service

func (*Service) ActivateConnection

func (s *Service) ActivateConnection(ctx context.Context, key, runtimeID string, info HandshakeInfo, connection *Connection, guard ConnectionCommitGuard) error

ActivateConnection rechecks the credential and transport readiness before consuming the pending state, then checks readiness again at the publication boundary. The lifecycle lock prevents a concurrent revoke from publishing a replacement connection after it returns.

func (*Service) AuthenticateKey

func (s *Service) AuthenticateKey(ctx context.Context, key string) (Runtime, error)

func (*Service) Connection

func (s *Service) Connection(runtimeID string) (*Connection, bool)

func (*Service) CreateRuntime

func (s *Service) CreateRuntime(ctx context.Context, userID string, req CreateRuntimeRequest) (Runtime, error)

func (*Service) DeactivateConnection

func (s *Service) DeactivateConnection(runtimeID string, connection *Connection, reason string)

func (*Service) ListRuntimes

func (s *Service) ListRuntimes(ctx context.Context, userID string) ([]Runtime, error)

func (*Service) RevokeRuntime

func (s *Service) RevokeRuntime(ctx context.Context, userID, runtimeID string) error

Jump to

Keyboard shortcuts

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