@@ -81,7 +81,7 @@ pub mod rpc_capnp;
81
81
/// [rpc-twoparty.capnp](https://github.com/capnproto/capnproto/blob/master/c%2B%2B/src/capnp/rpc-twoparty.capnp).
82
82
pub mod rpc_twoparty_capnp;
83
83
84
- /// Like `try!()`, but for functions that return a `Promise<T, E>` rather than a `Result<T, E>`.
84
+ /// Like [ `try!()`] , but for functions that return a [ `Promise<T, E>`] rather than a [ `Result<T, E>`] .
85
85
///
86
86
/// Unwraps a `Result<T, E>`. In the case of an error `Err(e)`, immediately returns from the
87
87
/// enclosing function with `Promise::err(e)`.
@@ -110,8 +110,15 @@ pub mod twoparty;
110
110
111
111
use capnp:: message;
112
112
113
+ /// A message to be sent by a [`VatNetwork`].
113
114
pub trait OutgoingMessage {
115
+ /// Gets the message body, which the caller may fill in any way it wants.
116
+ ///
117
+ /// The standard RPC implementation initializes it as a Message as defined
118
+ /// in `schema/rpc.capnp`.
114
119
fn get_body ( & mut self ) -> :: capnp:: Result < :: capnp:: any_pointer:: Builder > ;
120
+
121
+ /// Same as `get_body()`, but returns the corresponding reader type.
115
122
fn get_body_as_reader ( & self ) -> :: capnp:: Result < :: capnp:: any_pointer:: Reader > ;
116
123
117
124
/// Sends the message. Returns a promise for the message that resolves once the send has completed.
@@ -123,44 +130,73 @@ pub trait OutgoingMessage {
123
130
Rc < message:: Builder < message:: HeapAllocator > > ,
124
131
) ;
125
132
133
+ /// Takes the inner message out of `self`.
126
134
fn take ( self : Box < Self > ) -> :: capnp:: message:: Builder < :: capnp:: message:: HeapAllocator > ;
127
135
}
128
136
137
+ /// A message received from a [`VatNetwork`].
129
138
pub trait IncomingMessage {
139
+ /// Gets the message body, to be interpreted by the caller.
140
+ ///
141
+ /// The standard RPC implementation interprets it as a Message as defined
142
+ /// in `schema/rpc.capnp`.
130
143
fn get_body ( & self ) -> :: capnp:: Result < :: capnp:: any_pointer:: Reader > ;
131
144
}
132
145
146
+ /// A two-way RPC connection.
147
+ ///
148
+ /// A connection can be created by [`VatNetwork::connect()`].
133
149
pub trait Connection < VatId > {
150
+ /// Returns the connected vat's authenticated VatId. It is the VatNetwork's
151
+ /// responsibility to authenticate this, so that the caller can be assured
152
+ /// that they are really talking to the identified vat and not an imposter.
134
153
fn get_peer_vat_id ( & self ) -> VatId ;
154
+
155
+ /// Allocates a new message to be sent on this connection.
156
+ ///
157
+ /// If `first_segment_word_size` is non-zero, it should be treated as a
158
+ /// hint suggesting how large to make the first segment. This is entirely
159
+ /// a hint and the connection may adjust it up or down. If it is zero,
160
+ /// the connection should choose the size itself.
135
161
fn new_outgoing_message ( & mut self , first_segment_word_size : u32 ) -> Box < dyn OutgoingMessage > ;
136
162
137
163
/// Waits for a message to be received and returns it. If the read stream cleanly terminates,
138
164
/// returns None. If any other problem occurs, returns an Error.
139
165
fn receive_incoming_message ( & mut self ) -> Promise < Option < Box < dyn IncomingMessage > > , Error > ;
140
166
141
- // Waits until all outgoing messages have been sent, then shuts down the outgoing stream. The
142
- // returned promise resolves after shutdown is complete.
167
+ /// Waits until all outgoing messages have been sent, then shuts down the outgoing stream. The
168
+ /// returned promise resolves after shutdown is complete.
143
169
fn shutdown ( & mut self , result : :: capnp:: Result < ( ) > ) -> Promise < ( ) , Error > ;
144
170
}
145
171
172
+ /// Network facility between vats, it determines how to form connections between
173
+ /// vats.
174
+ ///
175
+ /// ## Vat
176
+ ///
177
+ /// Cap'n Proto RPC operates between vats, where a "vat" is some sort of host of
178
+ /// objects. Typically one Cap'n Proto process (in the Unix sense) is one vat.
146
179
pub trait VatNetwork < VatId > {
147
- /// Returns None if `hostId` refers to the local vat.
180
+ /// Connects to `host_id`.
181
+ ///
182
+ /// Returns None if `host_id` refers to the local vat.
148
183
fn connect ( & mut self , host_id : VatId ) -> Option < Box < dyn Connection < VatId > > > ;
149
184
150
185
/// Waits for the next incoming connection and return it.
151
186
fn accept ( & mut self ) -> Promise < Box < dyn Connection < VatId > > , :: capnp:: Error > ;
152
187
188
+ /// A promise that cannot be resolved until the shutdown.
153
189
fn drive_until_shutdown ( & mut self ) -> Promise < ( ) , Error > ;
154
190
}
155
191
156
192
/// A portal to objects available on the network.
157
193
///
158
- /// The RPC implemententation sits on top of an implementation of `VatNetwork`, which
194
+ /// The RPC implementation sits on top of an implementation of [ `VatNetwork`] , which
159
195
/// determines how to form connections between vats. The RPC implementation determines
160
196
/// how to use such connections to manage object references and make method calls.
161
197
///
162
198
/// At the moment, this is all rather more general than it needs to be, because the only
163
- /// implementation of `VatNetwork` is `twoparty::VatNetwork`. However, eventually we
199
+ /// implementation of `VatNetwork` is [ `twoparty::VatNetwork`] . However, eventually we
164
200
/// will need to have more sophisticated `VatNetwork` implementations, in order to support
165
201
/// [level 3](https://capnproto.org/rpc.html#protocol-features) features.
166
202
///
@@ -228,7 +264,8 @@ impl<VatId> RpcSystem<VatId> {
228
264
result
229
265
}
230
266
231
- /// Connects to the given vat and returns its bootstrap interface.
267
+ /// Connects to the given vat and returns its bootstrap interface, returns
268
+ /// a client that can be used to invoke the bootstrap interface.
232
269
pub fn bootstrap < T > ( & mut self , vat_id : VatId ) -> T
233
270
where
234
271
T : :: capnp:: capability:: FromClientHook ,
0 commit comments