packagebridge

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package packagebridge exposes narrow, generation-bound kernel operations to a single supervised package host. It intentionally has no database, file, configuration, or arbitrary-query API.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCapabilityRejected = errors.New("package bridge capability rejected")
	ErrBridgeClosed       = errors.New("package bridge is closed")
)

Functions

This section is empty.

Types

type Allowlist

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

Allowlist binds every bridge operation to one package and v2 route id.

func NewAllowlist

func NewAllowlist(operations ...Operation) (*Allowlist, error)

func NewAllowlistWithFallback

func NewAllowlistWithFallback(fallback OperationResolver, operations ...Operation) (*Allowlist, error)

NewAllowlistWithFallback composes static package operations with a resolver that still requires an exact package, route, and operation match.

func (*Allowlist) Allows

func (a *Allowlist) Allows(packageID, routeID, operation string) bool

func (*Allowlist) Invoke

func (a *Allowlist) Invoke(ctx context.Context, call Call) (Response, error)

type Call

type Call struct {
	Host      HostIdentity
	Request   Request
	Operation string
	Payload   []byte
}

Call is delivered only after a capability, package identity, route, and operation have all been verified.

type Factory

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

func NewFactory

func NewFactory(allowlist *Allowlist, webSocketResolvers ...WebSocketOperationResolver) *Factory

func (*Factory) NewSession

func (f *Factory) NewSession(identity HostIdentity) (*Session, *os.File, error)
type Header struct {
	Name  string
	Value string
}

type HostIdentity

type HostIdentity struct {
	PackageID  string
	Version    string
	Generation uint64
}

HostIdentity is fixed when a child process is started. The socketpair makes this identity process-local rather than client-asserted.

type Operation

type Operation struct {
	PackageID string
	RouteID   string
	Name      string
	Handler   OperationHandler
}

type OperationHandler

type OperationHandler func(context.Context, Call) (Response, error)

func NewHTTPAdapter

func NewHTTPAdapter(handler gin.HandlerFunc) OperationHandler

NewHTTPAdapter turns a deliberately allowlisted legacy Gin handler into a bridge operation. It uses only the request snapshot retained by Session; package-supplied payload bytes are never treated as an HTTP request.

type OperationResolver

type OperationResolver interface {
	Resolve(packageID, routeID, operation string) (OperationHandler, bool)
}

OperationResolver provides an additional exact operation source. It is used for handlers registered during router construction, not for path matching or arbitrary package-supplied operation names.

type Request

type Request struct {
	RequestID     string
	RouteID       string
	Method        string
	Body          []byte
	PrincipalJSON []byte
	MetadataJSON  []byte
	Deadline      time.Time
}

Request is kernel-derived request state retained behind a capability. A package never supplies these values to the bridge RPC.

type Response

type Response struct {
	StatusCode uint32
	Body       []byte
	Headers    []Header
}

Response is an explicit parent-produced answer to one allowed bridge operation. Package code cannot obtain this authority except by consuming a verified capability.

type RouteRegistry

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

RouteRegistry is populated only while Gin routes are constructed. It keeps the legacy-compatible handler behind the kernel's exact bridge operation checks; it does not inspect package-controlled paths or route declarations.

func DefaultRouteRegistry

func DefaultRouteRegistry() *RouteRegistry

DefaultRouteRegistry is shared by the production router and its host supervisor. Tests may use NewRouteRegistry for isolated contracts.

func NewRouteRegistry

func NewRouteRegistry() *RouteRegistry

func (*RouteRegistry) Allowlist

func (r *RouteRegistry) Allowlist() *Allowlist

Allowlist exposes the registered routes through the same exact-operation interface used by static bridge handlers.

func (*RouteRegistry) MustRegister

func (r *RouteRegistry) MustRegister(packageID, routeID string, handler gin.HandlerFunc)

MustRegister is for static router declarations. A bad declaration is a process-startup error, not a recoverable request-time condition.

func (*RouteRegistry) MustRegisterWebSocket

func (r *RouteRegistry) MustRegisterWebSocket(packageID, routeID string, handler gin.HandlerFunc)

MustRegisterWebSocket is for static router declarations. Invalid ownership is a process-startup error, not a request-time fallback condition.

func (*RouteRegistry) Register

func (r *RouteRegistry) Register(packageID, routeID string, handler gin.HandlerFunc) error

Register binds an exact package route to one Gin handler. Rebuilding a router may replace the handler for the same package/route, but a route id can never be rebound to another package.

func (*RouteRegistry) RegisterWebSocket

func (r *RouteRegistry) RegisterWebSocket(packageID, routeID string, handler gin.HandlerFunc) error

RegisterWebSocket binds an exact package route to a legacy-compatible WebSocket handler. It shares ownership checks with unary routes.

func (*RouteRegistry) Resolve

func (r *RouteRegistry) Resolve(packageID, routeID, operation string) (OperationHandler, bool)

func (*RouteRegistry) ResolveWebSocket

func (r *RouteRegistry) ResolveWebSocket(packageID, routeID, operation string) (WebSocketOperationHandler, bool)

type Session

type Session struct {
	packagebridgev1.UnimplementedKernelPackageBridgeServer
	// contains filtered or unexported fields
}

Session owns one endpoint of an inherited Unix socketpair. The returned child file is passed once through exec.ExtraFiles and is never addressable by a filesystem path.

func NewSession

func NewSession(identity HostIdentity, handler *Allowlist, webSocketResolvers ...WebSocketOperationResolver) (*Session, *os.File, error)

func (*Session) Close

func (s *Session) Close() error

func (*Session) Invoke

func (*Session) Mint

func (s *Session) Mint(request Request) ([]byte, error)

Mint creates an opaque one-shot capability for a dispatch already admitted by the kernel. It is not an authority token that a package can fabricate.

func (*Session) OpenWebSocket

func (*Session) Revoke

func (s *Session) Revoke(raw []byte)

Revoke removes an unconsumed capability once the outer package-host dispatch returns. Calling it after a successful bridge call is harmless.

type SessionFactory

type SessionFactory interface {
	NewSession(HostIdentity) (*Session, *os.File, error)
}

SessionFactory creates a fresh private endpoint for every supervised host.

type WebSocketClose

type WebSocketClose struct {
	Code   uint32
	Reason string
}

type WebSocketFrame

type WebSocketFrame struct {
	Data  []byte
	Close *WebSocketClose
}

WebSocketFrame is a post-open bridge frame. A nil Close denotes a data frame, including an empty payload.

type WebSocketOperationHandler

type WebSocketOperationHandler func(context.Context, Call, WebSocketStream) error

func NewWebSocketAdapter

func NewWebSocketAdapter(handler gin.HandlerFunc) WebSocketOperationHandler

NewWebSocketAdapter runs an allowlisted legacy Gin WebSocket handler over a private in-memory connection. The package host receives only opaque frames; the legacy handler and its database access remain in the kernel process.

type WebSocketOperationResolver

type WebSocketOperationResolver interface {
	ResolveWebSocket(packageID, routeID, operation string) (WebSocketOperationHandler, bool)
}

WebSocketOperationResolver provides exact streaming operations registered during router construction. It is separate from unary operations so a package cannot upgrade a route merely by changing a declaration.

type WebSocketStream

type WebSocketStream interface {
	Recv() (WebSocketFrame, error)
	Send(WebSocketFrame) error
}

WebSocketStream is the kernel-side end of a private package bridge stream. Exactly one reader and one writer may operate concurrently.

Jump to

Keyboard shortcuts

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