comparison osx/include/capnp/rpc.h @ 49:3ab5a40c4e3b

Add Capnp and KJ builds for OSX
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 25 Oct 2016 14:48:23 +0100
parents
children 0994c39f1e94
comparison
equal deleted inserted replaced
48:9530b331f8c1 49:3ab5a40c4e3b
1 // Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
2 // Licensed under the MIT License:
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE.
21
22 #ifndef CAPNP_RPC_H_
23 #define CAPNP_RPC_H_
24
25 #if defined(__GNUC__) && !defined(CAPNP_HEADER_WARNINGS)
26 #pragma GCC system_header
27 #endif
28
29 #include "capability.h"
30 #include "rpc-prelude.h"
31
32 namespace capnp {
33
34 template <typename VatId, typename ProvisionId, typename RecipientId,
35 typename ThirdPartyCapId, typename JoinResult>
36 class VatNetwork;
37 template <typename SturdyRefObjectId>
38 class SturdyRefRestorer;
39
40 template <typename VatId>
41 class BootstrapFactory: public _::BootstrapFactoryBase {
42 // Interface that constructs per-client bootstrap interfaces. Use this if you want each client
43 // who connects to see a different bootstrap interface based on their (authenticated) VatId.
44 // This allows an application to bootstrap off of the authentication performed at the VatNetwork
45 // level. (Typically VatId is some sort of public key.)
46 //
47 // This is only useful for multi-party networks. For TwoPartyVatNetwork, there's no reason to
48 // use a BootstrapFactory; just specify a single bootstrap capability in this case.
49
50 public:
51 virtual Capability::Client createFor(typename VatId::Reader clientId) = 0;
52 // Create a bootstrap capability appropriate for exposing to the given client. VatNetwork will
53 // have authenticated the client VatId before this is called.
54
55 private:
56 Capability::Client baseCreateFor(AnyStruct::Reader clientId) override;
57 };
58
59 template <typename VatId>
60 class RpcSystem: public _::RpcSystemBase {
61 // Represents the RPC system, which is the portal to objects available on the network.
62 //
63 // The RPC implementation sits on top of an implementation of `VatNetwork`. The `VatNetwork`
64 // determines how to form connections between vats -- specifically, two-way, private, reliable,
65 // sequenced datagram connections. The RPC implementation determines how to use such connections
66 // to manage object references and make method calls.
67 //
68 // See `makeRpcServer()` and `makeRpcClient()` below for convenient syntax for setting up an
69 // `RpcSystem` given a `VatNetwork`.
70 //
71 // See `ez-rpc.h` for an even simpler interface for setting up RPC in a typical two-party
72 // client/server scenario.
73
74 public:
75 template <typename ProvisionId, typename RecipientId,
76 typename ThirdPartyCapId, typename JoinResult>
77 RpcSystem(
78 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
79 kj::Maybe<Capability::Client> bootstrapInterface,
80 kj::Maybe<RealmGateway<>::Client> gateway = nullptr);
81
82 template <typename ProvisionId, typename RecipientId,
83 typename ThirdPartyCapId, typename JoinResult>
84 RpcSystem(
85 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
86 BootstrapFactory<VatId>& bootstrapFactory,
87 kj::Maybe<RealmGateway<>::Client> gateway = nullptr);
88
89 template <typename ProvisionId, typename RecipientId,
90 typename ThirdPartyCapId, typename JoinResult,
91 typename LocalSturdyRefObjectId>
92 RpcSystem(
93 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
94 SturdyRefRestorer<LocalSturdyRefObjectId>& restorer);
95
96 RpcSystem(RpcSystem&& other) = default;
97
98 Capability::Client bootstrap(typename VatId::Reader vatId);
99 // Connect to the given vat and return its bootstrap interface.
100
101 Capability::Client restore(typename VatId::Reader hostId, AnyPointer::Reader objectId)
102 KJ_DEPRECATED("Please transition to using a bootstrap interface instead.");
103 // ** DEPRECATED **
104 //
105 // Restores the given SturdyRef from the network and return the capability representing it.
106 //
107 // `hostId` identifies the host from which to request the ref, in the format specified by the
108 // `VatNetwork` in use. `objectId` is the object ID in whatever format is expected by said host.
109 //
110 // This method will be removed in a future version of Cap'n Proto. Instead, please transition
111 // to using bootstrap(), which is equivalent to calling restore() with a null `objectId`.
112 // You may emulate the old concept of object IDs by exporting a bootstrap interface which has
113 // methods that can be used to obtain other capabilities by ID.
114
115 void setFlowLimit(size_t words);
116 // Sets the incoming call flow limit. If more than `words` worth of call messages have not yet
117 // received responses, the RpcSystem will not read further messages from the stream. This can be
118 // used as a crude way to prevent a resource exhaustion attack (or bug) in which a peer makes an
119 // excessive number of simultaneous calls that consume the receiver's RAM.
120 //
121 // There are some caveats. When over the flow limit, all messages are blocked, including returns.
122 // If the outstanding calls are themselves waiting on calls going in the opposite direction, the
123 // flow limit may prevent those calls from completing, leading to deadlock. However, a
124 // sufficiently high limit should make this unlikely.
125 //
126 // Note that a call's parameter size counts against the flow limit until the call returns, even
127 // if the recipient calls releaseParams() to free the parameter memory early. This is because
128 // releaseParams() may simply indicate that the parameters have been forwarded to another
129 // machine, but are still in-memory there. For illustration, say that Alice made a call to Bob
130 // who forwarded the call to Carol. Bob has imposed a flow limit on Alice. Alice's calls are
131 // being forwarded to Carol, so Bob never keeps the parameters in-memory for more than a brief
132 // period. However, the flow limit counts all calls that haven't returned, even if Bob has
133 // already freed the memory they consumed. You might argue that the right solution here is
134 // instead for Carol to impose her own flow limit on Bob. This has a serious problem, though:
135 // Bob might be forwarding requests to Carol on behalf of many different parties, not just Alice.
136 // If Alice can pump enough data to hit the Bob -> Carol flow limit, then those other parties
137 // will be disrupted. Thus, we can only really impose the limit on the Alice -> Bob link, which
138 // only affects Alice. We need that one flow limit to limit Alice's impact on the whole system,
139 // so it has to count all in-flight calls.
140 //
141 // In Sandstorm, flow limits are imposed by the supervisor on calls coming out of a grain, in
142 // order to prevent a grain from inundating the system with in-flight calls. In practice, the
143 // main time this happens is when a grain is pushing a large file download and doesn't implement
144 // proper cooperative flow control.
145 };
146
147 template <typename VatId, typename ProvisionId, typename RecipientId,
148 typename ThirdPartyCapId, typename JoinResult>
149 RpcSystem<VatId> makeRpcServer(
150 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
151 Capability::Client bootstrapInterface);
152 // Make an RPC server. Typical usage (e.g. in a main() function):
153 //
154 // MyEventLoop eventLoop;
155 // kj::WaitScope waitScope(eventLoop);
156 // MyNetwork network;
157 // MyMainInterface::Client bootstrap = makeMain();
158 // auto server = makeRpcServer(network, bootstrap);
159 // kj::NEVER_DONE.wait(waitScope); // run forever
160 //
161 // See also ez-rpc.h, which has simpler instructions for the common case of a two-party
162 // client-server RPC connection.
163
164 template <typename VatId, typename ProvisionId, typename RecipientId,
165 typename ThirdPartyCapId, typename JoinResult, typename RealmGatewayClient,
166 typename InternalRef = _::InternalRefFromRealmGatewayClient<RealmGatewayClient>,
167 typename ExternalRef = _::ExternalRefFromRealmGatewayClient<RealmGatewayClient>>
168 RpcSystem<VatId> makeRpcServer(
169 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
170 Capability::Client bootstrapInterface, RealmGatewayClient gateway);
171 // Make an RPC server for a VatNetwork that resides in a different realm from the application.
172 // The given RealmGateway is used to translate SturdyRefs between the app's ("internal") format
173 // and the network's ("external") format.
174
175 template <typename VatId, typename ProvisionId, typename RecipientId,
176 typename ThirdPartyCapId, typename JoinResult>
177 RpcSystem<VatId> makeRpcServer(
178 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
179 BootstrapFactory<VatId>& bootstrapFactory);
180 // Make an RPC server that can serve different bootstrap interfaces to different clients via a
181 // BootstrapInterface.
182
183 template <typename VatId, typename ProvisionId, typename RecipientId,
184 typename ThirdPartyCapId, typename JoinResult, typename RealmGatewayClient,
185 typename InternalRef = _::InternalRefFromRealmGatewayClient<RealmGatewayClient>,
186 typename ExternalRef = _::ExternalRefFromRealmGatewayClient<RealmGatewayClient>>
187 RpcSystem<VatId> makeRpcServer(
188 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
189 BootstrapFactory<VatId>& bootstrapFactory, RealmGatewayClient gateway);
190 // Make an RPC server that can serve different bootstrap interfaces to different clients via a
191 // BootstrapInterface and communicates with a different realm than the application is in via a
192 // RealmGateway.
193
194 template <typename VatId, typename LocalSturdyRefObjectId,
195 typename ProvisionId, typename RecipientId, typename ThirdPartyCapId, typename JoinResult>
196 RpcSystem<VatId> makeRpcServer(
197 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
198 SturdyRefRestorer<LocalSturdyRefObjectId>& restorer)
199 KJ_DEPRECATED("Please transition to using a bootstrap interface instead.");
200 // ** DEPRECATED **
201 //
202 // Create an RPC server which exports multiple main interfaces by object ID. The `restorer` object
203 // can be used to look up objects by ID.
204 //
205 // Please transition to exporting only one interface, which is known as the "bootstrap" interface.
206 // For backwards-compatibility with old clients, continue to implement SturdyRefRestorer, but
207 // return the new bootstrap interface when the request object ID is null. When new clients connect
208 // and request the bootstrap interface, they will get that interface. Eventually, once all clients
209 // are updated to request only the bootstrap interface, stop implementing SturdyRefRestorer and
210 // switch to passing the bootstrap capability itself as the second parameter to `makeRpcServer()`.
211
212 template <typename VatId, typename ProvisionId,
213 typename RecipientId, typename ThirdPartyCapId, typename JoinResult>
214 RpcSystem<VatId> makeRpcClient(
215 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network);
216 // Make an RPC client. Typical usage (e.g. in a main() function):
217 //
218 // MyEventLoop eventLoop;
219 // kj::WaitScope waitScope(eventLoop);
220 // MyNetwork network;
221 // auto client = makeRpcClient(network);
222 // MyCapability::Client cap = client.restore(hostId, objId).castAs<MyCapability>();
223 // auto response = cap.fooRequest().send().wait(waitScope);
224 // handleMyResponse(response);
225 //
226 // See also ez-rpc.h, which has simpler instructions for the common case of a two-party
227 // client-server RPC connection.
228
229 template <typename VatId, typename ProvisionId, typename RecipientId,
230 typename ThirdPartyCapId, typename JoinResult, typename RealmGatewayClient,
231 typename InternalRef = _::InternalRefFromRealmGatewayClient<RealmGatewayClient>,
232 typename ExternalRef = _::ExternalRefFromRealmGatewayClient<RealmGatewayClient>>
233 RpcSystem<VatId> makeRpcClient(
234 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
235 RealmGatewayClient gateway);
236 // Make an RPC client for a VatNetwork that resides in a different realm from the application.
237 // The given RealmGateway is used to translate SturdyRefs between the app's ("internal") format
238 // and the network's ("external") format.
239
240 template <typename SturdyRefObjectId>
241 class SturdyRefRestorer: public _::SturdyRefRestorerBase {
242 // ** DEPRECATED **
243 //
244 // In Cap'n Proto 0.4.x, applications could export multiple main interfaces identified by
245 // object IDs. The callback used to map object IDs to objects was `SturdyRefRestorer`, as we
246 // imagined this would eventually be used for restoring SturdyRefs as well. In practice, it was
247 // never used for real SturdyRefs, only for exporting singleton objects under well-known names.
248 //
249 // The new preferred strategy is to export only a _single_ such interface, called the
250 // "bootstrap interface". That interface can itself have methods for obtaining other objects, of
251 // course, but that is up to the app. `SturdyRefRestorer` exists for backwards-compatibility.
252 //
253 // Hint: Use SturdyRefRestorer<capnp::Text> to define a server that exports services under
254 // string names.
255
256 public:
257 virtual Capability::Client restore(typename SturdyRefObjectId::Reader ref)
258 KJ_DEPRECATED(
259 "Please transition to using bootstrap interfaces instead of SturdyRefRestorer.") = 0;
260 // Restore the given object, returning a capability representing it.
261
262 private:
263 Capability::Client baseRestore(AnyPointer::Reader ref) override final;
264 };
265
266 // =======================================================================================
267 // VatNetwork
268
269 class OutgoingRpcMessage {
270 // A message to be sent by a `VatNetwork`.
271
272 public:
273 virtual AnyPointer::Builder getBody() = 0;
274 // Get the message body, which the caller may fill in any way it wants. (The standard RPC
275 // implementation initializes it as a Message as defined in rpc.capnp.)
276
277 virtual void send() = 0;
278 // Send the message, or at least put it in a queue to be sent later. Note that the builder
279 // returned by `getBody()` remains valid at least until the `OutgoingRpcMessage` is destroyed.
280 };
281
282 class IncomingRpcMessage {
283 // A message received from a `VatNetwork`.
284
285 public:
286 virtual AnyPointer::Reader getBody() = 0;
287 // Get the message body, to be interpreted by the caller. (The standard RPC implementation
288 // interprets it as a Message as defined in rpc.capnp.)
289 };
290
291 template <typename VatId, typename ProvisionId, typename RecipientId,
292 typename ThirdPartyCapId, typename JoinResult>
293 class VatNetwork: public _::VatNetworkBase {
294 // Cap'n Proto RPC operates between vats, where a "vat" is some sort of host of objects.
295 // Typically one Cap'n Proto process (in the Unix sense) is one vat. The RPC system is what
296 // allows calls between objects hosted in different vats.
297 //
298 // The RPC implementation sits on top of an implementation of `VatNetwork`. The `VatNetwork`
299 // determines how to form connections between vats -- specifically, two-way, private, reliable,
300 // sequenced datagram connections. The RPC implementation determines how to use such connections
301 // to manage object references and make method calls.
302 //
303 // The most common implementation of VatNetwork is TwoPartyVatNetwork (rpc-twoparty.h). Most
304 // simple client-server apps will want to use it. (You may even want to use the EZ RPC
305 // interfaces in `ez-rpc.h` and avoid all of this.)
306 //
307 // TODO(someday): Provide a standard implementation for the public internet.
308
309 public:
310 class Connection;
311
312 struct ConnectionAndProvisionId {
313 // Result of connecting to a vat introduced by another vat.
314
315 kj::Own<Connection> connection;
316 // Connection to the new vat.
317
318 kj::Own<OutgoingRpcMessage> firstMessage;
319 // An already-allocated `OutgoingRpcMessage` associated with `connection`. The RPC system will
320 // construct this as an `Accept` message and send it.
321
322 Orphan<ProvisionId> provisionId;
323 // A `ProvisionId` already allocated inside `firstMessage`, which the RPC system will use to
324 // build the `Accept` message.
325 };
326
327 class Connection: public _::VatNetworkBase::Connection {
328 // A two-way RPC connection.
329 //
330 // This object may represent a connection that doesn't exist yet, but is expected to exist
331 // in the future. In this case, sent messages will automatically be queued and sent once the
332 // connection is ready, so that the caller doesn't need to know the difference.
333
334 public:
335 // Level 0 features ----------------------------------------------
336
337 virtual typename VatId::Reader getPeerVatId() = 0;
338 // Returns the connected vat's authenticated VatId. It is the VatNetwork's responsibility to
339 // authenticate this, so that the caller can be assured that they are really talking to the
340 // identified vat and not an imposter.
341
342 virtual kj::Own<OutgoingRpcMessage> newOutgoingMessage(uint firstSegmentWordSize) override = 0;
343 // Allocate a new message to be sent on this connection.
344 //
345 // If `firstSegmentWordSize` is non-zero, it should be treated as a hint suggesting how large
346 // to make the first segment. This is entirely a hint and the connection may adjust it up or
347 // down. If it is zero, the connection should choose the size itself.
348
349 virtual kj::Promise<kj::Maybe<kj::Own<IncomingRpcMessage>>> receiveIncomingMessage() override = 0;
350 // Wait for a message to be received and return it. If the read stream cleanly terminates,
351 // return null. If any other problem occurs, throw an exception.
352
353 virtual kj::Promise<void> shutdown() override KJ_WARN_UNUSED_RESULT = 0;
354 // Waits until all outgoing messages have been sent, then shuts down the outgoing stream. The
355 // returned promise resolves after shutdown is complete.
356
357 private:
358 AnyStruct::Reader baseGetPeerVatId() override;
359 };
360
361 // Level 0 features ------------------------------------------------
362
363 virtual kj::Maybe<kj::Own<Connection>> connect(typename VatId::Reader hostId) = 0;
364 // Connect to a VatId. Note that this method immediately returns a `Connection`, even
365 // if the network connection has not yet been established. Messages can be queued to this
366 // connection and will be delivered once it is open. The caller must attempt to read from the
367 // connection to verify that it actually succeeded; the read will fail if the connection
368 // couldn't be opened. Some network implementations may actually start sending messages before
369 // hearing back from the server at all, to avoid a round trip.
370 //
371 // Returns nullptr if `hostId` refers to the local host.
372
373 virtual kj::Promise<kj::Own<Connection>> accept() = 0;
374 // Wait for the next incoming connection and return it.
375
376 // Level 4 features ------------------------------------------------
377 // TODO(someday)
378
379 private:
380 kj::Maybe<kj::Own<_::VatNetworkBase::Connection>>
381 baseConnect(AnyStruct::Reader hostId) override final;
382 kj::Promise<kj::Own<_::VatNetworkBase::Connection>> baseAccept() override final;
383 };
384
385 // =======================================================================================
386 // ***************************************************************************************
387 // Inline implementation details start here
388 // ***************************************************************************************
389 // =======================================================================================
390
391 template <typename VatId>
392 Capability::Client BootstrapFactory<VatId>::baseCreateFor(AnyStruct::Reader clientId) {
393 return createFor(clientId.as<VatId>());
394 }
395
396 template <typename SturdyRef, typename ProvisionId, typename RecipientId,
397 typename ThirdPartyCapId, typename JoinResult>
398 kj::Maybe<kj::Own<_::VatNetworkBase::Connection>>
399 VatNetwork<SturdyRef, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>::
400 baseConnect(AnyStruct::Reader ref) {
401 auto maybe = connect(ref.as<SturdyRef>());
402 return maybe.map([](kj::Own<Connection>& conn) -> kj::Own<_::VatNetworkBase::Connection> {
403 return kj::mv(conn);
404 });
405 }
406
407 template <typename SturdyRef, typename ProvisionId, typename RecipientId,
408 typename ThirdPartyCapId, typename JoinResult>
409 kj::Promise<kj::Own<_::VatNetworkBase::Connection>>
410 VatNetwork<SturdyRef, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>::baseAccept() {
411 return accept().then(
412 [](kj::Own<Connection>&& connection) -> kj::Own<_::VatNetworkBase::Connection> {
413 return kj::mv(connection);
414 });
415 }
416
417 template <typename SturdyRef, typename ProvisionId, typename RecipientId,
418 typename ThirdPartyCapId, typename JoinResult>
419 AnyStruct::Reader VatNetwork<
420 SturdyRef, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>::
421 Connection::baseGetPeerVatId() {
422 return getPeerVatId();
423 }
424
425 template <typename SturdyRef>
426 Capability::Client SturdyRefRestorer<SturdyRef>::baseRestore(AnyPointer::Reader ref) {
427 #pragma GCC diagnostic push
428 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
429 return restore(ref.getAs<SturdyRef>());
430 #pragma GCC diagnostic pop
431 }
432
433 template <typename VatId>
434 template <typename ProvisionId, typename RecipientId,
435 typename ThirdPartyCapId, typename JoinResult>
436 RpcSystem<VatId>::RpcSystem(
437 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
438 kj::Maybe<Capability::Client> bootstrap,
439 kj::Maybe<RealmGateway<>::Client> gateway)
440 : _::RpcSystemBase(network, kj::mv(bootstrap), kj::mv(gateway)) {}
441
442 template <typename VatId>
443 template <typename ProvisionId, typename RecipientId,
444 typename ThirdPartyCapId, typename JoinResult>
445 RpcSystem<VatId>::RpcSystem(
446 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
447 BootstrapFactory<VatId>& bootstrapFactory,
448 kj::Maybe<RealmGateway<>::Client> gateway)
449 : _::RpcSystemBase(network, bootstrapFactory, kj::mv(gateway)) {}
450
451 template <typename VatId>
452 template <typename ProvisionId, typename RecipientId,
453 typename ThirdPartyCapId, typename JoinResult,
454 typename LocalSturdyRefObjectId>
455 RpcSystem<VatId>::RpcSystem(
456 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
457 SturdyRefRestorer<LocalSturdyRefObjectId>& restorer)
458 : _::RpcSystemBase(network, restorer) {}
459
460 template <typename VatId>
461 Capability::Client RpcSystem<VatId>::bootstrap(typename VatId::Reader vatId) {
462 return baseBootstrap(_::PointerHelpers<VatId>::getInternalReader(vatId));
463 }
464
465 template <typename VatId>
466 Capability::Client RpcSystem<VatId>::restore(
467 typename VatId::Reader hostId, AnyPointer::Reader objectId) {
468 return baseRestore(_::PointerHelpers<VatId>::getInternalReader(hostId), objectId);
469 }
470
471 template <typename VatId>
472 inline void RpcSystem<VatId>::setFlowLimit(size_t words) {
473 baseSetFlowLimit(words);
474 }
475
476 template <typename VatId, typename ProvisionId, typename RecipientId,
477 typename ThirdPartyCapId, typename JoinResult>
478 RpcSystem<VatId> makeRpcServer(
479 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
480 Capability::Client bootstrapInterface) {
481 return RpcSystem<VatId>(network, kj::mv(bootstrapInterface));
482 }
483
484 template <typename VatId, typename ProvisionId, typename RecipientId,
485 typename ThirdPartyCapId, typename JoinResult,
486 typename RealmGatewayClient, typename InternalRef, typename ExternalRef>
487 RpcSystem<VatId> makeRpcServer(
488 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
489 Capability::Client bootstrapInterface, RealmGatewayClient gateway) {
490 return RpcSystem<VatId>(network, kj::mv(bootstrapInterface),
491 gateway.template castAs<RealmGateway<>>());
492 }
493
494 template <typename VatId, typename ProvisionId, typename RecipientId,
495 typename ThirdPartyCapId, typename JoinResult>
496 RpcSystem<VatId> makeRpcServer(
497 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
498 BootstrapFactory<VatId>& bootstrapFactory) {
499 return RpcSystem<VatId>(network, bootstrapFactory);
500 }
501
502 template <typename VatId, typename ProvisionId, typename RecipientId,
503 typename ThirdPartyCapId, typename JoinResult,
504 typename RealmGatewayClient, typename InternalRef, typename ExternalRef>
505 RpcSystem<VatId> makeRpcServer(
506 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
507 BootstrapFactory<VatId>& bootstrapFactory, RealmGatewayClient gateway) {
508 return RpcSystem<VatId>(network, bootstrapFactory, gateway.template castAs<RealmGateway<>>());
509 }
510
511 template <typename VatId, typename LocalSturdyRefObjectId,
512 typename ProvisionId, typename RecipientId, typename ThirdPartyCapId, typename JoinResult>
513 RpcSystem<VatId> makeRpcServer(
514 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
515 SturdyRefRestorer<LocalSturdyRefObjectId>& restorer) {
516 return RpcSystem<VatId>(network, restorer);
517 }
518
519 template <typename VatId, typename ProvisionId,
520 typename RecipientId, typename ThirdPartyCapId, typename JoinResult>
521 RpcSystem<VatId> makeRpcClient(
522 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network) {
523 return RpcSystem<VatId>(network, nullptr);
524 }
525
526 template <typename VatId, typename ProvisionId,
527 typename RecipientId, typename ThirdPartyCapId, typename JoinResult,
528 typename RealmGatewayClient, typename InternalRef, typename ExternalRef>
529 RpcSystem<VatId> makeRpcClient(
530 VatNetwork<VatId, ProvisionId, RecipientId, ThirdPartyCapId, JoinResult>& network,
531 RealmGatewayClient gateway) {
532 return RpcSystem<VatId>(network, nullptr, gateway.template castAs<RealmGateway<>>());
533 }
534
535 } // namespace capnp
536
537 #endif // CAPNP_RPC_H_