csp_server

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: Apache-2.0, MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const INIT_PID = 1

Variables

View Source
var (
	ErrEmpty  = errors.New("empty")
	ErrClosed = errors.New("closed")
)

Functions

func DialWithRetries

func DialWithRetries(addr *net.TCPAddr) (net.Conn, error)

DialWithRetries dials addr in waitTime intervals until it either succeeds or exceeds maxRetries retries.

func ServeModule

func ServeModule[T ~capnp.ClientKind](addr *net.TCPAddr, t T)

ServeModule ensures the host side of the TCP connection with addr=addr used for CAPNP RPCs is provided by client.

Types

type AtomicCounter

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

AtomicCounter is an atomic counter that increases the

func NewAtomicCounter

func NewAtomicCounter(start uint32) AtomicCounter

func (AtomicCounter) Dec

func (p AtomicCounter) Dec() uint32

Decrease by 1.

func (AtomicCounter) Get

func (p AtomicCounter) Get() uint32

Get current value.

func (AtomicCounter) Inc

func (p AtomicCounter) Inc() uint32

Increase by 1.

type BytecodeCache

type BytecodeCache map[string][]byte

TODO mikel Make BytecodeCache keep a list of the bcs it has sorted by last usage Set and enforce a limited list size and a limited memory size

func (BytecodeCache) Get

func (BytecodeCache) Has

func (BytecodeCache) Put

type Chan

type Chan api.Chan

func NewChan

func NewChan(s ChanServer) Chan

func (Chan) AddRef

func (c Chan) AddRef() Chan

func (Chan) Client

func (c Chan) Client() capnp.Client

func (Chan) Close

func (c Chan) Close(ctx context.Context) error

func (Chan) NewCloser

func (c Chan) NewCloser(ctx context.Context) (Closer, capnp.ReleaseFunc)

func (Chan) NewRecver

func (c Chan) NewRecver(ctx context.Context) (Recver, capnp.ReleaseFunc)

func (Chan) NewSendCloser

func (c Chan) NewSendCloser(ctx context.Context) (SendCloser, capnp.ReleaseFunc)

func (Chan) NewSender

func (c Chan) NewSender(ctx context.Context) (Sender, capnp.ReleaseFunc)

func (Chan) Recv

func (c Chan) Recv(ctx context.Context) (casm.Future, capnp.ReleaseFunc)

func (Chan) Release

func (c Chan) Release()

func (Chan) Send

func (c Chan) Send(ctx context.Context, v Value) error

type ChanServer

type ChanServer interface {
	RecvServer
	SendCloseServer
	NewRecver(context.Context, MethodNewRecver) error
	NewSendCloser(context.Context, MethodNewSendCloser) error
}

type CloseServer

type CloseServer interface {
	Close(context.Context, MethodClose) error
}

type Closer

type Closer api.Chan

func NewCloser

func NewCloser(c CloseServer) Closer

func (Closer) AddRef

func (c Closer) AddRef() Closer

func (Closer) Close

func (c Closer) Close(ctx context.Context) error

func (Closer) Release

func (c Closer) Release()

type MethodClose

type MethodClose = api.Closer_close

type MethodNewCloser

type MethodNewCloser = api.SendCloser_newCloser

type MethodNewRecver

type MethodNewRecver = api.Chan_newRecver

type MethodNewSendCloser

type MethodNewSendCloser = api.Chan_newSendCloser

type MethodNewSender

type MethodNewSender = api.SendCloser_newSender

type MethodRecv

type MethodRecv = api.Recver_recv

type MethodSend

type MethodSend = api.Sender_send

type ProcNode

type ProcNode struct {
	// Pid contais the Process ID.
	Pid uint32
	// Left contains a child process.
	Left *ProcNode
	// Right contains a sibling process.
	Right *ProcNode
}

ProcNode represents a process in the process tree.

func (*ProcNode) String

func (n *ProcNode) String() string

type ProcTree

type ProcTree struct {
	// TODO move context out of tree
	Ctx context.Context
	// PIDC is a couter that increases to assign new PIDs.
	PIDC AtomicCounter
	// TPC keeps track of the number of processes in the tree.
	TPC AtomicCounter
	// Root of the process tree.
	Root *ProcNode
	// Map of processes associated to their PIDs. MUST be initialized.
	Map map[uint32]api.Process_Server
}

ProcTree represents the process tree of an executor. It is represented a binary tree, in which the left branch of a node represents a child process, while the right branch represents a sibling process (shares the same parent). TODO: thread safety.

func NewProcTree

func NewProcTree(ctx context.Context) ProcTree

NewProcTree is the default constuctor for ProcTree, but it may also be maually constructed.

func (ProcTree) AddToMap

func (pt ProcTree) AddToMap(pid uint32, p api.Process_Server)

func (ProcTree) Find

func (pt ProcTree) Find(pid uint32) *ProcNode

Find returns a node in the process tree with PID=pid. nil if not found.

func (ProcTree) FindParent

func (pt ProcTree) FindParent(pid uint32) *ProcNode

FindParent returns the parent of the process with PID=pid. nil if not found.

func (ProcTree) Insert

func (pt ProcTree) Insert(pid, ppid uint32) error

Insert creates a node with PID=pid as a child of PID=ppid.

func (*ProcTree) Kill

func (pt *ProcTree) Kill(pid uint32)

Kill recursively kills a process and it's children

func (*ProcTree) NextPid

func (pt *ProcTree) NextPid() uint32

NextPid returns the next avaiable PID and ensures it does not collide with any existing processes.

func (ProcTree) Pop

func (pt ProcTree) Pop(pid uint32) *ProcNode

Pop removes the node with PID=pid and replaces it with a sibling in the process tree.

func (*ProcTree) PpidOrInit

func (pt *ProcTree) PpidOrInit(ppid uint32) uint32

ppidOrInit checks for a process with pid=ppid and returns ppid if found, INIT_PID otherwise.

func (ProcTree) Trim

func (pt ProcTree) Trim(ctx context.Context)

Trim all orphaned branches.

type RecvServer

type RecvServer interface {
	Recv(context.Context, MethodRecv) error
}

type Recver

type Recver api.Recver

func NewRecver

func NewRecver(r RecvServer) Recver

func (Recver) AddRef

func (r Recver) AddRef() Recver

func (Recver) Client

func (r Recver) Client() capnp.Client

func (Recver) Recv

func (r Recver) Recv(ctx context.Context) (casm.Future, capnp.ReleaseFunc)

func (Recver) Release

func (r Recver) Release()

type Runtime

type Runtime struct {
	Runtime wazero.Runtime
	Cache   BytecodeCache
	Tree    ProcTree

	// HostModule is unused for now.
	HostModule *wazergo.ModuleInstance[*proc.Module]
}

Runtime is the main Executor implementation. It spawns WebAssembly- based processes. The zero-value Runtime panics.

func (Runtime) Exec

func (r Runtime) Exec(ctx context.Context, call api.Executor_exec) error

func (Runtime) ExecCached

func (r Runtime) ExecCached(ctx context.Context, call api.Executor_execCached) error

func (Runtime) Executor

func (r Runtime) Executor() csp.Executor

Executor provides the Executor capability.

type SendCloseServer

type SendCloseServer interface {
	SendServer
	CloseServer
	NewSender(context.Context, MethodNewSender) error
	NewCloser(context.Context, MethodNewCloser) error
}

type SendCloser

type SendCloser api.SendCloser

func NewSendCloser

func NewSendCloser(sc SendCloseServer) SendCloser

func (SendCloser) AddRef

func (sc SendCloser) AddRef() SendCloser

func (SendCloser) Client

func (sc SendCloser) Client() capnp.Client

func (SendCloser) Close

func (sc SendCloser) Close(ctx context.Context) error

func (SendCloser) NewCloser

func (sc SendCloser) NewCloser(ctx context.Context) (Closer, capnp.ReleaseFunc)

func (SendCloser) NewSender

func (sc SendCloser) NewSender(ctx context.Context) (Sender, capnp.ReleaseFunc)

func (SendCloser) Release

func (sc SendCloser) Release()

func (SendCloser) Send

func (sc SendCloser) Send(ctx context.Context, v Value) error

type SendServer

type SendServer interface {
	Send(context.Context, MethodSend) error
}

type Sender

type Sender api.Sender

func NewSender

func NewSender(s SendServer) Sender

func (Sender) AddRef

func (s Sender) AddRef() Sender

func (Sender) Client

func (s Sender) Client() capnp.Client

func (Sender) Release

func (s Sender) Release()

func (Sender) Send

func (s Sender) Send(ctx context.Context, v Value) error

type SyncChan

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

SyncChan is a synchronous channel server. Both senders and receivers will block until a matching call arrives.

The zero-value SyncChan is ready to use.

func (*SyncChan) Close

func (ch *SyncChan) Close(ctx context.Context, call MethodClose) error

func (*SyncChan) NewCloser

func (ch *SyncChan) NewCloser(ctx context.Context, call MethodNewCloser) error

func (*SyncChan) NewRecver

func (ch *SyncChan) NewRecver(ctx context.Context, call MethodNewRecver) error

func (*SyncChan) NewSendCloser

func (ch *SyncChan) NewSendCloser(ctx context.Context, call MethodNewSendCloser) error

func (*SyncChan) NewSender

func (ch *SyncChan) NewSender(ctx context.Context, call MethodNewSender) error

func (*SyncChan) Recv

func (ch *SyncChan) Recv(ctx context.Context, call MethodRecv) error

func (*SyncChan) Send

func (ch *SyncChan) Send(ctx context.Context, call MethodSend) error

type Value

type Value func(api.Sender_send_Params) error

func Client

func Client[T ~capnp.ClientKind](t T) Value

Client takes any client-like type and converts it into a value capable of being sent through a channel.

func Data

func Data[T ~[]byte](t T) Value

Data takes any []byte-like type and converts it into a value capable of being sent through a channel.

func List

func List[T ~capnp.ListKind](t T) Value

List takes any capnp list and converts it into a value capable of being sent through a channel.

func Ptr

func Ptr(ptr capnp.Ptr) Value

Ptr takes any capnp pointer and converts it into a value capable of being sent through a channel.

func Struct

func Struct[T ~capnp.StructKind](t T) Value

Struct takes any capnp struct and converts it into a value capable of being sent through a channel.

func Text

func Text[T ~string](t T) Value

Text takes any string-like type and converts it into a value capable of being sent through a channel.

Jump to

Keyboard shortcuts

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