@enclave-vm/runtime package - building blocks of a runtime worker: session bookkeeping and the channels between a worker and a broker.
Installation
Runtime Worker
A runtime worker keeps the sessions of the requests that the embedding application hands to it. It has no network interface of its own.createRuntimeWorker(config?)
Create a runtime worker. The class of the returned object is exported asRuntimeWorkerImpl.
RuntimeConfig
RuntimeWorkerImpl
start()
Mark the worker as running, so thathandleRequest() accepts execute requests. No server is started and no port is opened. Throws when the worker is neither idle nor stopped.
stop()
Cancel and remove the sessions the worker holds.getStats()
Get the worker’s statistics.getSessions()
Get the sessions the worker holds.handleRequest(request, channel)
Handle one request from the embedding application. The caller is trusted: nothing authenticates a request or checks where it came from.Session Executor
SessionExecutor
Holds one session and forwards its events to a channel. It keeps the session’s code and never runs it.execute() always rejects with RuntimeNotImplementedError. The first call ends the session: the channel receives session_init, then a final event with ok: false and error.code: 'NOT_IMPLEMENTED'. dispose() stops forwarding events to the channel.
createSessionExecutor(options)
Create a session executor.RuntimeNotImplementedError
Thrown by the operations of this package that are not implemented.Channels
RuntimeChannel
The interface between a worker and the other end of a session.MemoryChannel
In-process channel that keeps the events sent to it.send() and injectMessage() throw when the channel is closed.
createMemoryChannelPair()
Create two connected memory channels: what one sends, the message handlers of the other receive.WebSocketChannel
The client side of a WebSocket connection. It connects to a URL and nothing more: there is no WebSocket server in this package.- The channel sends no credentials. Authenticate the connection in the server behind the URL.
- Incoming messages are parsed as JSON and handed to the handlers without validation against a schema. Validate them in the handler.
- While the channel is not connected,
send()keeps at mostmaxBufferedMessagesevents and drops the rest. The kept events are sent when the channel connects. - Where there is no global
WebSocket, the channel needs thewspackage, which is not installed with this package.
Command Line
The package installs anenclave-runtime program. It does not start a worker: it checks its arguments, prints that a standalone worker is not implemented, and exits with code 1.
An unknown option or an invalid value prints a message and exits with code 1.
Other Types
RuntimeWorker is the interface of a worker without handleRequest(). WebSocketServer and ConnectionHandler are exported as types only: the package has no implementation of them.
Related
- Runtime Overview - What the package contains
- @enclave-vm/broker - Broker API
- @enclave-vm/core - Sandbox API