rpc

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: Apache-2.0 Imports: 58 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeRW = iota
	TypeR
	TypeW
)
View Source
const BootstrapOID = "!bootstrap"

Variables

View Source
var (
	ErrResolveHTTP   = &ResolveError{Kind: ResolveHTTPError, Msg: "http request error"}
	ErrResolveStatus = &ResolveError{Kind: ResolveStatusError, Msg: "unexpected status code"}
	ErrResolveDecode = &ResolveError{Kind: ResolveDecodeError, Msg: "decode error"}
	ErrResolveLookup = &ResolveError{Kind: ResolveLookupError, Msg: "lookup error"}
)

Exported sentinel errors for common resolve error kinds

View Source
var (
	DefaultTransport  http3.Transport
	DefaultQUICConfig quic.Config

	DefaultLogLevel = slog.LevelInfo
)

Functions

func CanBe

func CanBe[T, I any]() bool

func NewResolveDecodeError

func NewResolveDecodeError(err error) error

NewResolveDecodeError creates a decode error

func NewResolveError

func NewResolveError(kind ResolveErrorKind, err error, msg string) error

NewResolveError creates a new ResolveError with the specified kind and underlying error

func NewResolveHTTPError

func NewResolveHTTPError(err error, format string, args ...interface{}) error

NewResolveHTTPError creates an HTTP request error

func NewResolveLookupError

func NewResolveLookupError(msg string) error

NewResolveLookupError creates a lookup error

func NewResolveStatusError

func NewResolveStatusError(statusCode int) error

NewResolveStatusError creates a status code error

func Propagator

func Propagator() propagation.TextMapPropagator

func RegisterInterface

func RegisterInterface[T any](fn any) bool

func SetupOTelSDK

func SetupOTelSDK(ctx context.Context) (shutdown func(context.Context) error, err error)

setupOTelSDK bootstraps the OpenTelemetry pipeline. If it does not return an error, make sure to call shutdown for proper cleanup.

func Tracer

func Tracer() otrace.Tracer

func WithRequireClientCerts

func WithRequireClientCerts(o *stateOptions)

func WithSkipVerify

func WithSkipVerify(o *stateOptions)

func Zero

func Zero[T any]() T

Types

type ActorCall

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

func (*ActorCall) Args

func (a *ActorCall) Args(v any)

func (*ActorCall) NewCapability

func (a *ActorCall) NewCapability(i *Interface) *Capability

func (*ActorCall) NewClient

func (a *ActorCall) NewClient(capa *Capability) Client

func (*ActorCall) Results

func (a *ActorCall) Results(v any)

type ActorClient

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

func (*ActorClient) Call

func (a *ActorClient) Call(ctx context.Context, name string, arg, ret any) error

func (*ActorClient) CallWithCaps

func (a *ActorClient) CallWithCaps(ctx context.Context, method string, args, result any, caps map[OID]*InlineCapability) error

func (*ActorClient) Close

func (a *ActorClient) Close() error

func (*ActorClient) NewClient

func (a *ActorClient) NewClient(capa *Capability) Client

func (*ActorClient) NewInlineCapability

func (a *ActorClient) NewInlineCapability(i *Interface, lower any) (*InlineCapability, OID, *Capability)

type ActorRegistry

type ActorRegistry interface {
	Register(ctx context.Context, name string, iface *Interface) error
	Client(ctx context.Context, name string) (Client, error)
	Close(ctx context.Context) error
}

func NewLocalActorRegistry

func NewLocalActorRegistry() ActorRegistry

type ActorResolver

type ActorResolver interface {
	Resolve(ctx context.Context, name string) (string, error)
}

type Authenticator

type Authenticator interface {
	// AuthenticateRequest authenticates an HTTP request and returns whether it's allowed
	// It can check JWT tokens, certificates, or other authentication methods
	AuthenticateRequest(ctx context.Context, r *http.Request) (authenticated bool, identity string, err error)

	// NoAuthorization is called when a request has no Authorization header
	// This allows the authenticator to decide if such requests should be allowed
	// (e.g., based on client certificates or to enforce mandatory authentication)
	NoAuthorization(ctx context.Context, r *http.Request) (allowed bool, identity string, err error)
}

Authenticator is an interface for authenticating RPC requests

type Call

type Call interface {
	NewClient(capa *Capability) Client
	Args(v any)
	Results(v any)
	NewCapability(i *Interface) *Capability
}

type Capability

type Capability struct {
	OID     OID    `cbor:"0,keyasint" json:"oid"`
	Address string `cbor:"1,keyasint" json:"address"`
	User    []byte `cbor:"2,keyasint" json:"owner"`
	Issuer  []byte `cbor:"3,keyasint" json:"issue"`

	RestoreState *InterfaceState `cbor:"4,keyasint" json:"restore-state"`

	Inline bool `cbor:"5,keyasint" json:"inline"`
}

type Client

type Client interface {
	CallWithCaps(ctx context.Context, method string, args, result any, caps map[OID]*InlineCapability) error
	Call(ctx context.Context, method string, args, result any) error
	NewInlineCapability(i *Interface, lower any) (*InlineCapability, OID, *Capability)
	NewClient(capa *Capability) Client
	Close() error
}

type CurrentConnectionInfo

type CurrentConnectionInfo struct {
	PeerSubject string
}

func ConnectionInfo

func ConnectionInfo(ctx context.Context) *CurrentConnectionInfo

type DebugAuthResponse

type DebugAuthResponse struct {
	Success       bool              `json:"success"`
	ServerVersion string            `json:"server_version,omitempty"`
	AuthMethod    string            `json:"auth_method,omitempty"`
	Identity      string            `json:"identity,omitempty"`
	UserInfo      map[string]string `json:"user_info,omitempty"`
	Message       string            `json:"message,omitempty"`
}

DebugAuthResponse represents the response from the debug-auth endpoint

type DescField

type DescField struct {
	Name  string `yaml:"name"`
	Type  string `yaml:"type"`
	Index int    `yaml:"index"`

	Element string       `yaml:"element"`
	Union   []UnionField `yaml:"union,omitempty"`
	// contains filtered or unexported fields
}

type DescFile

type DescFile struct {
	Imports    map[string]Import `yaml:"imports"`
	Types      []*DescType       `yaml:"types"`
	Interfaces []*DescInterface  `yaml:"interfaces"`
}

type DescInterface

type DescInterface struct {
	Name        string         `yaml:"name"`
	Method      []*DescMethods `yaml:"methods"`
	Generic     []string       `yaml:"generic,omitempty"`
	Constraints []string       `yaml:"constraints,omitempty"`
}

type DescMethods

type DescMethods struct {
	Name       string           `yaml:"name"`
	Index      int              `yaml:"index"`
	Parameters []*DescParamater `yaml:"parameters"`
	Results    []*DescParamater `yaml:"results"`
}

type DescParamater

type DescParamater struct {
	Name    string `yaml:"name"`
	Type    string `yaml:"type"`
	Element string `yaml:"element,omitempty"`
}

type DescType

type DescType struct {
	Type        string       `yaml:"type"`
	Fields      []*DescField `yaml:"fields"`
	Compact     bool         `yaml:"compact,omitempty"`
	Generic     []string     `yaml:"generic,omitempty"`
	Constraints []string     `yaml:"constraints,omitempty"`
	// contains filtered or unexported fields
}

func (*DescType) CalculateOffsets

func (t *DescType) CalculateOffsets(usertypes map[string]*DescType)

func (*DescType) Readable

func (t *DescType) Readable() bool

func (*DescType) Validate

func (t *DescType) Validate() error

func (*DescType) Writeable

func (t *DescType) Writeable() bool

type Dispatcher

type Dispatcher interface {
	Dispatch(ctx context.Context, oid OID, method string, call Call) error
	Bind(oid OID, iface *Interface) error
}

type ErrorCategory

type ErrorCategory interface {
	ErrorCategory() string
}

type ErrorCode

type ErrorCode interface {
	ErrorCode() string
}

type ErrorMessage

type ErrorMessage interface {
	ErrorMessage() string
}

type ForbidRestore

type ForbidRestore interface {
	// contains filtered or unexported methods
}

type Generator

type Generator struct {
	Imports    map[string]Import
	Types      []*DescType
	Interfaces []*DescInterface
	// contains filtered or unexported fields
}

func NewGenerator

func NewGenerator() (*Generator, error)

func (*Generator) Generate

func (g *Generator) Generate(pkgName string) (string, error)

func (*Generator) Read

func (g *Generator) Read(path string) error

type HasReconstructFromState

type HasReconstructFromState interface {
	ReconstructFromState(is *InterfaceState) (*Interface, error)
}

type HasRestoreState

type HasRestoreState interface {
	RestoreState(iface any) (any, error)
}

type IfaceReg

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

func NewIfaceReg

func NewIfaceReg() *IfaceReg

type Import

type Import struct {
	Path   string   `yaml:"path"`
	Import string   `yaml:"import"`
	Types  []string `yaml:"types"`
}

type InlineCapability

type InlineCapability struct {
	*Capability
	*Interface
}

type Interface

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

func NewInterface

func NewInterface(methods []Method, obj any) *Interface

func (*Interface) SetAroundContext

func (i *Interface) SetAroundContext(fn func(ctx context.Context, call Call) (context.Context, func()))

func (*Interface) Value

func (i *Interface) Value() any

type InterfaceCreators

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

func NewInterfaceCreators

func NewInterfaceCreators() *InterfaceCreators

type InterfaceDescriptor

type InterfaceDescriptor struct {
}

type InterfaceState

type InterfaceState struct {
	Category  string `cbor:"0,keyasint" json:"category"`
	Interface string `cbor:"1,keyasint" json:"interface"`
	Data      any    `cbor:"2,keyasint" json:"data"`
}

func (*InterfaceState) Decode

func (i *InterfaceState) Decode(v any) error

type LocalActorRegistry

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

func (*LocalActorRegistry) Client

func (r *LocalActorRegistry) Client(ctx context.Context, name string) (Client, error)

func (*LocalActorRegistry) Close

func (r *LocalActorRegistry) Close(ctx context.Context) error

func (*LocalActorRegistry) Register

func (r *LocalActorRegistry) Register(ctx context.Context, name string, iface *Interface) error

type Method

type Method struct {
	Name          string
	InterfaceName string
	Index         int
	Handler       func(ctx context.Context, call Call) error
}

type NetworkCall

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

func Local

func Local(args ...any) *NetworkCall

func (*NetworkCall) Args

func (c *NetworkCall) Args(v any)

func (*NetworkCall) NewCapability

func (c *NetworkCall) NewCapability(i *Interface) *Capability

func (*NetworkCall) NewClient

func (c *NetworkCall) NewClient(capa *Capability) Client

func (*NetworkCall) RemoteAddr

func (c *NetworkCall) RemoteAddr() string

func (*NetworkCall) Results

func (c *NetworkCall) Results(v any)

func (*NetworkCall) String

func (c *NetworkCall) String() string

type NetworkClient

type NetworkClient struct {
	State *State
	// contains filtered or unexported fields
}

func LocalClient

func LocalClient(iface *Interface) *NetworkClient

func (*NetworkClient) Call

func (c *NetworkClient) Call(ctx context.Context, method string, args, result any) error

func (*NetworkClient) CallWithCaps

func (c *NetworkClient) CallWithCaps(ctx context.Context, method string, args, result any, caps map[OID]*InlineCapability) error

func (*NetworkClient) Close

func (c *NetworkClient) Close() error

func (*NetworkClient) HasMethod

func (c *NetworkClient) HasMethod(ctx context.Context, method string) bool

HasMethod checks if the remote interface supports a given method. Returns false if the method doesn't exist or if the server doesn't support introspection.

func (*NetworkClient) ListMethods

func (c *NetworkClient) ListMethods(ctx context.Context) ([]string, error)

ListMethods returns the list of methods available on this capability. Returns an error if the server doesn't support method introspection (old servers).

func (*NetworkClient) NewCapability

func (c *NetworkClient) NewCapability(i *Interface, lower any) *Capability

func (*NetworkClient) NewClient

func (c *NetworkClient) NewClient(capa *Capability) Client

func (*NetworkClient) NewInlineCapability

func (c *NetworkClient) NewInlineCapability(i *Interface, lower any) (*InlineCapability, OID, *Capability)

func (*NetworkClient) String

func (c *NetworkClient) String() string

type NoOpAuthenticator

type NoOpAuthenticator struct{}

NoOpAuthenticator is a no-op authenticator that allows all requests

func (*NoOpAuthenticator) AuthenticateRequest

func (n *NoOpAuthenticator) AuthenticateRequest(ctx context.Context, r *http.Request) (bool, string, error)

func (*NoOpAuthenticator) NoAuthorization

func (n *NoOpAuthenticator) NoAuthorization(ctx context.Context, r *http.Request) (bool, string, error)

type NoRestore

type NoRestore struct{}

type OID

type OID string

type ResolveError

type ResolveError struct {
	Kind       ResolveErrorKind
	Err        error
	Msg        string
	StatusCode int // HTTP status code for ResolveStatusError
}

ResolveError represents an error that occurred during capability resolution

func (*ResolveError) Error

func (e *ResolveError) Error() string

func (*ResolveError) Is

func (e *ResolveError) Is(target error) bool

func (*ResolveError) Unwrap

func (e *ResolveError) Unwrap() error

type ResolveErrorKind

type ResolveErrorKind int

ResolveErrorKind represents different kinds of capability resolution errors

const (
	ResolveHTTPError ResolveErrorKind = iota
	ResolveStatusError
	ResolveDecodeError
	ResolveLookupError
)

type ResolverFunc

type ResolverFunc func(ctx context.Context, name string) (string, error)

func (ResolverFunc) Resolve

func (f ResolverFunc) Resolve(ctx context.Context, name string) (string, error)

type Server

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

func (*Server) Clone

func (s *Server) Clone(state *State) *Server

func (*Server) Deref

func (s *Server) Deref(oid OID) bool

func (*Server) ExposeValue

func (s *Server) ExposeValue(name string, iface *Interface)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type State

type State struct {
	*StateCommon
	// contains filtered or unexported fields
}

func NewState

func NewState(ctx context.Context, opts ...StateOption) (*State, error)

func (*State) Client

func (s *State) Client(name string) (*NetworkClient, error)

func (*State) Close

func (s *State) Close() error

func (*State) Connect

func (s *State) Connect(remote string, name string) (*NetworkClient, error)

func (*State) ListenAddr

func (s *State) ListenAddr() string

func (*State) LoopbackAddr

func (s *State) LoopbackAddr() string

func (*State) Server

func (s *State) Server() *Server

type StateCommon

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

type StateOption

type StateOption func(*stateOptions)

func WithAuthenticator

func WithAuthenticator(auth Authenticator) StateOption

func WithBearerToken

func WithBearerToken(token string) StateOption

func WithBindAddr

func WithBindAddr(addr string) StateOption

func WithCert

func WithCert(certPath, keyPath string) StateOption

func WithCertPEMs

func WithCertPEMs(certData, keyData []byte) StateOption

func WithCertificateVerification

func WithCertificateVerification(caCert []byte) StateOption

func WithEndpoint

func WithEndpoint(endpoint string) StateOption

func WithLocalConnect

func WithLocalConnect(addr string) StateOption

func WithLocalServer

func WithLocalServer(addr string) StateOption

func WithLogLevel

func WithLogLevel(level slog.Level) StateOption

func WithLogger

func WithLogger(log *slog.Logger) StateOption

type UnionField

type UnionField struct {
	Name    string `yaml:"name"`
	Index   int    `yaml:"index"`
	Type    string `yaml:"type"`
	Element string `yaml:"element,omitempty"`
}

Directories

Path Synopsis
cmd
rpcgen command

Jump to

Keyboard shortcuts

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