Capnp_rpc_unix.Vat
A Vat is an actor in the CapTP network, composed of objects that can call each other directly.
An actor in the CapTP network. A Vat may be connected to other Vats over CapTP network connections. Typically an application will create only a single Vat. See the Capnp_rpc_unix
module for a higher-level API.
val create :
?tags:Logs.Tag.set ->
?restore:Capnp_rpc_net.Restorer.t ->
?address:Network.Address.t ->
sw:Eio.Switch.t ->
secret_key:Capnp_rpc_net.Auth.Secret_key.t Stdlib.Lazy.t ->
Network.t ->
t
create ~sw ~restore ~address ~secret_key network
is a new Vat that uses restore
to restore sturdy refs hosted at this vat to live capabilities for peers. The Vat will suggest that other parties connect to it using address
. Turning off the switch will disconnect any active connections.
val run_connection :
t ->
mode:[ `Accept | `Connect ] ->
Capnp_rpc_net.Endpoint.t ->
(CapTP.t -> unit) ->
unit
run_connection t ~mode endpoint r
runs the protocol over endpoint
, which is a connection to another vat. Once connected, r conn
is called with the new connection. When run_connection
returns, endpoint
can be closed. mode
is used if two Vats connect to each other at the same time to decide which connection to drop. Use `Connect
if t
initiated the new connection. If there is already a connection to endpoint
, run_connection
may call r
on that instead and then return.
val public_address : t -> Network.Address.t option
public_address t
is the address that peers should use when connecting to this Vat to locate and authenticate it.
val sturdy_ref :
t ->
Capnp_rpc_net.Restorer.Id.t ->
'a Capnp_rpc.Std.Sturdy_ref.t
sturdy_ref t service_id
is a sturdy ref for service_id
, hosted at this Vat. Fails if this Vat does not accept incoming connections.
val export : t -> 'a Capnp_rpc.Std.Sturdy_ref.t -> Uri.t
export t sr
turns sr
into a URI, which can be displayed and imported into another Vat.
val sturdy_uri : t -> Capnp_rpc_net.Restorer.Id.t -> Uri.t
sturdy_uri t id
is sturdy_ref t id |> export t
.
val import :
t ->
Uri.t ->
('a Capnp_rpc.Std.Sturdy_ref.t, [> `Msg of string ]) Stdlib.result
import t uri
parses uri
as a "capnp://" URI.
val import_exn : t -> Uri.t -> 'a Capnp_rpc.Std.Sturdy_ref.t
import_exn
is a wrapper for import
that raises an exception if it fails.
val dump : t Fmt.t