pub struct Agent { /* private fields */ }Expand description
One agent: an owner of lanes, channels, capabilities and promises.
Implementations§
Source§impl Agent
impl Agent
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an agent kernel with an unpredictable capability secret.
The secret comes from the operating system’s CSPRNG. A clock-derived seed would make capability ids guessable to a peer that can estimate the start time, which defeats unforgeability.
Sourcepub fn with_secret(secret: [u8; 32]) -> Self
pub fn with_secret(secret: [u8; 32]) -> Self
Create an agent with a fixed secret (tests, deterministic replays).
Sourcepub fn cell(&self) -> &KernelCell
pub fn cell(&self) -> &KernelCell
The shared cell, for transports and adapters that need direct access.
Sourcepub fn register(&self, provider: Box<dyn Provider>) -> ProviderId
pub fn register(&self, provider: Box<dyn Provider>) -> ProviderId
Register a provider and return its id.
Sourcepub fn set_latency(&self, latency_ms: u64)
pub fn set_latency(&self, latency_ms: u64)
Configure the simulated provider latency (milliseconds per batch).
Sourcepub fn mint(
&self,
provider: ProviderId,
object: u64,
attrs: CapAttrs,
) -> Result<CapHandle>
pub fn mint( &self, provider: ProviderId, object: u64, attrs: CapAttrs, ) -> Result<CapHandle>
Mint a first-generation capability.
Sourcepub fn attenuate(
&self,
parent: &CapHandle,
attrs: CapAttrs,
) -> Result<CapHandle>
pub fn attenuate( &self, parent: &CapHandle, attrs: CapAttrs, ) -> Result<CapHandle>
Attenuate a capability. Refuses any widening.
Sourcepub fn import(&self, id: CapId) -> CapHandle
pub fn import(&self, id: CapId) -> CapHandle
Import a capability id without owning a reference.
This is how a peer handle is reconstructed from the wire: the id must
already exist in this kernel, otherwise the first call fails with
rpc/unknown-capability. Importing never proves authority; the registry
does.
Sourcepub fn revoke(&self, cap: &CapHandle)
pub fn revoke(&self, cap: &CapHandle)
Revoke a capability and every capability derived from it.
Sourcepub fn create_lane(
&self,
name: impl Into<String>,
budget: Budget,
) -> Result<LaneId>
pub fn create_lane( &self, name: impl Into<String>, budget: Budget, ) -> Result<LaneId>
Create a lane.
Sourcepub fn attenuate_lane(&self, lane: LaneId, budget: Budget) -> Result<()>
pub fn attenuate_lane(&self, lane: LaneId, budget: Budget) -> Result<()>
Attenuate a lane’s budget.
Sourcepub fn destroy_lane(&self, lane: LaneId) -> Result<()>
pub fn destroy_lane(&self, lane: LaneId) -> Result<()>
Destroy a lane and drop its queued work.
Queued jobs are removed from the dispatch queue and their promises are rejected, so a destroyed lane cannot keep spending budget or produce side effects after the fact.
Sourcepub fn create_channel(
&self,
name: impl Into<String>,
direction: Direction,
) -> Result<ChannelId>
pub fn create_channel( &self, name: impl Into<String>, direction: Direction, ) -> Result<ChannelId>
Create a channel.
Sourcepub fn subscribe(&self, lane: LaneId, channel: ChannelId) -> Result<()>
pub fn subscribe(&self, lane: LaneId, channel: ChannelId) -> Result<()>
Subscribe a lane to a channel.
Sourcepub fn send(
&self,
lane: LaneId,
channel: ChannelId,
payload: Value,
caps: &[CapHandle],
) -> Result<u64>
pub fn send( &self, lane: LaneId, channel: ChannelId, payload: Value, caps: &[CapHandle], ) -> Result<u64>
Send a message, transferring capabilities with it.
Sourcepub fn recv(&self, channel: ChannelId) -> Result<Option<Message>>
pub fn recv(&self, channel: ChannelId) -> Result<Option<Message>>
Receive the next message on a channel.
Sourcepub fn call(
&self,
lane: LaneId,
cap: &CapHandle,
method: &str,
args: Vec<Arg>,
) -> Result<PromiseHandle>
pub fn call( &self, lane: LaneId, cap: &CapHandle, method: &str, args: Vec<Arg>, ) -> Result<PromiseHandle>
Issue a call. The returned promise is pending until the kernel runs.
Sourcepub fn run(&self) -> u64
pub fn run(&self) -> u64
Run until no job is queued. Returns the number of provider round-trips.
Sourcepub fn round_trips(&self) -> u64
pub fn round_trips(&self) -> u64
Round-trips observed so far.
Sourcepub fn await_promise(&self, promise: &PromiseHandle) -> Result<Value>
pub fn await_promise(&self, promise: &PromiseHandle) -> Result<Value>
Await a promise, running the kernel until it settles.
Sourcepub fn resolve(&self, promise: &PromiseHandle, value: Value) -> Result<()>
pub fn resolve(&self, promise: &PromiseHandle, value: Value) -> Result<()>
Resolve a pending promise manually (used by peers that answer out of band).
Sourcepub fn cancel(&self, promise: &PromiseHandle) -> Result<()>
pub fn cancel(&self, promise: &PromiseHandle) -> Result<()>
Cancel a promise.
A job that has not been dispatched yet is removed from the queue, so a cancellation really prevents the provider call (and its side effects). A job already in flight cannot be stopped; its result is discarded.
Sourcepub fn take_drops(&self, provider: ProviderId) -> Vec<(u64, CapId)>
pub fn take_drops(&self, provider: ProviderId) -> Vec<(u64, CapId)>
Drain drop notifications recorded by one provider.