Chris@50: # Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors Chris@50: # Licensed under the MIT License: Chris@50: # Chris@50: # Permission is hereby granted, free of charge, to any person obtaining a copy Chris@50: # of this software and associated documentation files (the "Software"), to deal Chris@50: # in the Software without restriction, including without limitation the rights Chris@50: # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell Chris@50: # copies of the Software, and to permit persons to whom the Software is Chris@50: # furnished to do so, subject to the following conditions: Chris@50: # Chris@50: # The above copyright notice and this permission notice shall be included in Chris@50: # all copies or substantial portions of the Software. Chris@50: # Chris@50: # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR Chris@50: # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, Chris@50: # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE Chris@50: # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER Chris@50: # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, Chris@50: # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN Chris@50: # THE SOFTWARE. Chris@50: Chris@50: @0xb312981b2552a250; Chris@50: # Recall that Cap'n Proto RPC allows messages to contain references to remote objects that Chris@50: # implement interfaces. These references are called "capabilities", because they both designate Chris@50: # the remote object to use and confer permission to use it. Chris@50: # Chris@50: # Recall also that Cap'n Proto RPC has the feature that when a method call itself returns a Chris@50: # capability, the caller can begin calling methods on that capability _before the first call has Chris@50: # returned_. The caller essentially sends a message saying "Hey server, as soon as you finish Chris@50: # that previous call, do this with the result!". Cap'n Proto's RPC protocol makes this possible. Chris@50: # Chris@50: # The protocol is significantly more complicated than most RPC protocols. However, this is Chris@50: # implementation complexity that underlies an easy-to-grasp higher-level model of object oriented Chris@50: # programming. That is, just like TCP is a surprisingly complicated protocol that implements a Chris@50: # conceptually-simple byte stream abstraction, Cap'n Proto is a surprisingly complicated protocol Chris@50: # that implements a conceptually-simple object abstraction. Chris@50: # Chris@50: # Cap'n Proto RPC is based heavily on CapTP, the object-capability protocol used by the E Chris@50: # programming language: Chris@50: # http://www.erights.org/elib/distrib/captp/index.html Chris@50: # Chris@50: # Cap'n Proto RPC takes place between "vats". A vat hosts some set of objects and talks to other Chris@50: # vats through direct bilateral connections. Typically, there is a 1:1 correspondence between vats Chris@50: # and processes (in the unix sense of the word), although this is not strictly always true (one Chris@50: # process could run multiple vats, or a distributed virtual vat might live across many processes). Chris@50: # Chris@50: # Cap'n Proto does not distinguish between "clients" and "servers" -- this is up to the application. Chris@50: # Either end of any connection can potentially hold capabilities pointing to the other end, and Chris@50: # can call methods on those capabilities. In the doc comments below, we use the words "sender" Chris@50: # and "receiver". These refer to the sender and receiver of an instance of the struct or field Chris@50: # being documented. Sometimes we refer to a "third-party" that is neither the sender nor the Chris@50: # receiver. Documentation is generally written from the point of view of the sender. Chris@50: # Chris@50: # It is generally up to the vat network implementation to securely verify that connections are made Chris@50: # to the intended vat as well as to encrypt transmitted data for privacy and integrity. See the Chris@50: # `VatNetwork` example interface near the end of this file. Chris@50: # Chris@50: # When a new connection is formed, the only interesting things that can be done are to send a Chris@50: # `Bootstrap` (level 0) or `Accept` (level 3) message. Chris@50: # Chris@50: # Unless otherwise specified, messages must be delivered to the receiving application in the same Chris@50: # order in which they were initiated by the sending application. The goal is to support "E-Order", Chris@50: # which states that two calls made on the same reference must be delivered in the order which they Chris@50: # were made: Chris@50: # http://erights.org/elib/concurrency/partial-order.html Chris@50: # Chris@50: # Since the full protocol is complicated, we define multiple levels of support that an Chris@50: # implementation may target. For many applications, level 1 support will be sufficient. Chris@50: # Comments in this file indicate which level requires the corresponding feature to be Chris@50: # implemented. Chris@50: # Chris@50: # * **Level 0:** The implementation does not support object references. Only the bootstrap interface Chris@50: # can be called. At this level, the implementation does not support object-oriented protocols and Chris@50: # is similar in complexity to JSON-RPC or Protobuf services. This level should be considered only Chris@50: # a temporary stepping-stone toward level 1 as the lack of object references drastically changes Chris@50: # how protocols are designed. Applications _should not_ attempt to design their protocols around Chris@50: # the limitations of level 0 implementations. Chris@50: # Chris@50: # * **Level 1:** The implementation supports simple bilateral interaction with object references Chris@50: # and promise pipelining, but interactions between three or more parties are supported only via Chris@50: # proxying of objects. E.g. if Alice (in Vat A) wants to send Bob (in Vat B) a capability Chris@50: # pointing to Carol (in Vat C), Alice must create a proxy of Carol within Vat A and send Bob a Chris@50: # reference to that; Bob cannot form a direct connection to Carol. Level 1 implementations do Chris@50: # not support checking if two capabilities received from different vats actually point to the Chris@50: # same object ("join"), although they should be able to do this check on capabilities received Chris@50: # from the same vat. Chris@50: # Chris@50: # * **Level 2:** The implementation supports saving persistent capabilities -- i.e. capabilities Chris@50: # that remain valid even after disconnect, and can be restored on a future connection. When a Chris@50: # capability is saved, the requester receives a `SturdyRef`, which is a token that can be used Chris@50: # to restore the capability later. Chris@50: # Chris@50: # * **Level 3:** The implementation supports three-way interactions. That is, if Alice (in Vat A) Chris@50: # sends Bob (in Vat B) a capability pointing to Carol (in Vat C), then Vat B will automatically Chris@50: # form a direct connection to Vat C rather than have requests be proxied through Vat A. Chris@50: # Chris@50: # * **Level 4:** The entire protocol is implemented, including joins (checking if two capabilities Chris@50: # are equivalent). Chris@50: # Chris@50: # Note that an implementation must also support specific networks (transports), as described in Chris@50: # the "Network-specific Parameters" section below. An implementation might have different levels Chris@50: # depending on the network used. Chris@50: # Chris@50: # New implementations of Cap'n Proto should start out targeting the simplistic two-party network Chris@50: # type as defined in `rpc-twoparty.capnp`. With this network type, level 3 is irrelevant and Chris@50: # levels 2 and 4 are much easier than usual to implement. When such an implementation is paired Chris@50: # with a container proxy, the contained app effectively gets to make full use of the proxy's Chris@50: # network at level 4. And since Cap'n Proto IPC is extremely fast, it may never make sense to Chris@50: # bother implementing any other vat network protocol -- just use the correct container type and get Chris@50: # it for free. Chris@50: Chris@50: using Cxx = import "/capnp/c++.capnp"; Chris@50: $Cxx.namespace("capnp::rpc"); Chris@50: Chris@50: # ======================================================================================== Chris@50: # The Four Tables Chris@50: # Chris@50: # Cap'n Proto RPC connections are stateful (although an application built on Cap'n Proto could Chris@50: # export a stateless interface). As in CapTP, for each open connection, a vat maintains four state Chris@50: # tables: questions, answers, imports, and exports. See the diagram at: Chris@50: # http://www.erights.org/elib/distrib/captp/4tables.html Chris@50: # Chris@50: # The question table corresponds to the other end's answer table, and the imports table corresponds Chris@50: # to the other end's exports table. Chris@50: # Chris@50: # The entries in each table are identified by ID numbers (defined below as 32-bit integers). These Chris@50: # numbers are always specific to the connection; a newly-established connection starts with no Chris@50: # valid IDs. Since low-numbered IDs will pack better, it is suggested that IDs be assigned like Chris@50: # Unix file descriptors -- prefer the lowest-number ID that is currently available. Chris@50: # Chris@50: # IDs in the questions/answers tables are chosen by the questioner and generally represent method Chris@50: # calls that are in progress. Chris@50: # Chris@50: # IDs in the imports/exports tables are chosen by the exporter and generally represent objects on Chris@50: # which methods may be called. Exports may be "settled", meaning the exported object is an actual Chris@50: # object living in the exporter's vat, or they may be "promises", meaning the exported object is Chris@50: # the as-yet-unknown result of an ongoing operation and will eventually be resolved to some other Chris@50: # object once that operation completes. Calls made to a promise will be forwarded to the eventual Chris@50: # target once it is known. The eventual replacement object does *not* get the same ID as the Chris@50: # promise, as it may turn out to be an object that is already exported (so already has an ID) or Chris@50: # may even live in a completely different vat (and so won't get an ID on the same export table Chris@50: # at all). Chris@50: # Chris@50: # IDs can be reused over time. To make this safe, we carefully define the lifetime of IDs. Since Chris@50: # messages using the ID could be traveling in both directions simultaneously, we must define the Chris@50: # end of life of each ID _in each direction_. The ID is only safe to reuse once it has been Chris@50: # released by both sides. Chris@50: # Chris@50: # When a Cap'n Proto connection is lost, everything on the four tables is lost. All questions are Chris@50: # canceled and throw exceptions. All imports become broken (all future calls to them throw Chris@50: # exceptions). All exports and answers are implicitly released. The only things not lost are Chris@50: # persistent capabilities (`SturdyRef`s). The application must plan for this and should respond by Chris@50: # establishing a new connection and restoring from these persistent capabilities. Chris@50: Chris@50: using QuestionId = UInt32; Chris@50: # **(level 0)** Chris@50: # Chris@50: # Identifies a question in the sender's question table (which corresponds to the receiver's answer Chris@50: # table). The questioner (caller) chooses an ID when making a call. The ID remains valid in Chris@50: # caller -> callee messages until a Finish message is sent, and remains valid in callee -> caller Chris@50: # messages until a Return message is sent. Chris@50: Chris@50: using AnswerId = QuestionId; Chris@50: # **(level 0)** Chris@50: # Chris@50: # Identifies an answer in the sender's answer table (which corresponds to the receiver's question Chris@50: # table). Chris@50: # Chris@50: # AnswerId is physically equivalent to QuestionId, since the question and answer tables correspond, Chris@50: # but we define a separate type for documentation purposes: we always use the type representing Chris@50: # the sender's point of view. Chris@50: Chris@50: using ExportId = UInt32; Chris@50: # **(level 1)** Chris@50: # Chris@50: # Identifies an exported capability or promise in the sender's export table (which corresponds Chris@50: # to the receiver's import table). The exporter chooses an ID before sending a capability over the Chris@50: # wire. If the capability is already in the table, the exporter should reuse the same ID. If the Chris@50: # ID is a promise (as opposed to a settled capability), this must be indicated at the time the ID Chris@50: # is introduced (e.g. by using `senderPromise` instead of `senderHosted` in `CapDescriptor`); in Chris@50: # this case, the importer shall expect a later `Resolve` message that replaces the promise. Chris@50: # Chris@50: # ExportId/ImportIds are subject to reference counting. Whenever an `ExportId` is sent over the Chris@50: # wire (from the exporter to the importer), the export's reference count is incremented (unless Chris@50: # otherwise specified). The reference count is later decremented by a `Release` message. Since Chris@50: # the `Release` message can specify an arbitrary number by which to reduce the reference count, the Chris@50: # importer should usually batch reference decrements and only send a `Release` when it believes the Chris@50: # reference count has hit zero. Of course, it is possible that a new reference to the export is Chris@50: # in-flight at the time that the `Release` message is sent, so it is necessary for the exporter to Chris@50: # keep track of the reference count on its end as well to avoid race conditions. Chris@50: # Chris@50: # When a connection is lost, all exports are implicitly released. It is not possible to restore Chris@50: # a connection state after disconnect (although a transport layer could implement a concept of Chris@50: # persistent connections if it is transparent to the RPC layer). Chris@50: Chris@50: using ImportId = ExportId; Chris@50: # **(level 1)** Chris@50: # Chris@50: # Identifies an imported capability or promise in the sender's import table (which corresponds to Chris@50: # the receiver's export table). Chris@50: # Chris@50: # ImportId is physically equivalent to ExportId, since the export and import tables correspond, Chris@50: # but we define a separate type for documentation purposes: we always use the type representing Chris@50: # the sender's point of view. Chris@50: # Chris@50: # An `ImportId` remains valid in importer -> exporter messages until the importer has sent Chris@50: # `Release` messages that (it believes) have reduced the reference count to zero. Chris@50: Chris@50: # ======================================================================================== Chris@50: # Messages Chris@50: Chris@50: struct Message { Chris@50: # An RPC connection is a bi-directional stream of Messages. Chris@50: Chris@50: union { Chris@50: unimplemented @0 :Message; Chris@50: # The sender previously received this message from the peer but didn't understand it or doesn't Chris@50: # yet implement the functionality that was requested. So, the sender is echoing the message Chris@50: # back. In some cases, the receiver may be able to recover from this by pretending the sender Chris@50: # had taken some appropriate "null" action. Chris@50: # Chris@50: # For example, say `resolve` is received by a level 0 implementation (because a previous call Chris@50: # or return happened to contain a promise). The level 0 implementation will echo it back as Chris@50: # `unimplemented`. The original sender can then simply release the cap to which the promise Chris@50: # had resolved, thus avoiding a leak. Chris@50: # Chris@50: # For any message type that introduces a question, if the message comes back unimplemented, Chris@50: # the original sender may simply treat it as if the question failed with an exception. Chris@50: # Chris@50: # In cases where there is no sensible way to react to an `unimplemented` message (without Chris@50: # resource leaks or other serious problems), the connection may need to be aborted. This is Chris@50: # a gray area; different implementations may take different approaches. Chris@50: Chris@50: abort @1 :Exception; Chris@50: # Sent when a connection is being aborted due to an unrecoverable error. This could be e.g. Chris@50: # because the sender received an invalid or nonsensical message (`isCallersFault` is true) or Chris@50: # because the sender had an internal error (`isCallersFault` is false). The sender will shut Chris@50: # down the outgoing half of the connection after `abort` and will completely close the Chris@50: # connection shortly thereafter (it's up to the sender how much of a time buffer they want to Chris@50: # offer for the client to receive the `abort` before the connection is reset). Chris@50: Chris@50: # Level 0 features ----------------------------------------------- Chris@50: Chris@50: bootstrap @8 :Bootstrap; # Request the peer's bootstrap interface. Chris@50: call @2 :Call; # Begin a method call. Chris@50: return @3 :Return; # Complete a method call. Chris@50: finish @4 :Finish; # Release a returned answer / cancel a call. Chris@50: Chris@50: # Level 1 features ----------------------------------------------- Chris@50: Chris@50: resolve @5 :Resolve; # Resolve a previously-sent promise. Chris@50: release @6 :Release; # Release a capability so that the remote object can be deallocated. Chris@50: disembargo @13 :Disembargo; # Lift an embargo used to enforce E-order over promise resolution. Chris@50: Chris@50: # Level 2 features ----------------------------------------------- Chris@50: Chris@50: obsoleteSave @7 :AnyPointer; Chris@50: # Obsolete request to save a capability, resulting in a SturdyRef. This has been replaced Chris@50: # by the `Persistent` interface defined in `persistent.capnp`. This operation was never Chris@50: # implemented. Chris@50: Chris@50: obsoleteDelete @9 :AnyPointer; Chris@50: # Obsolete way to delete a SturdyRef. This operation was never implemented. Chris@50: Chris@50: # Level 3 features ----------------------------------------------- Chris@50: Chris@50: provide @10 :Provide; # Provide a capability to a third party. Chris@50: accept @11 :Accept; # Accept a capability provided by a third party. Chris@50: Chris@50: # Level 4 features ----------------------------------------------- Chris@50: Chris@50: join @12 :Join; # Directly connect to the common root of two or more proxied caps. Chris@50: } Chris@50: } Chris@50: Chris@50: # Level 0 message types ---------------------------------------------- Chris@50: Chris@50: struct Bootstrap { Chris@50: # **(level 0)** Chris@50: # Chris@50: # Get the "bootstrap" interface exported by the remote vat. Chris@50: # Chris@50: # For level 0, 1, and 2 implementations, the "bootstrap" interface is simply the main interface Chris@50: # exported by a vat. If the vat acts as a server fielding connections from clients, then the Chris@50: # bootstrap interface defines the basic functionality available to a client when it connects. Chris@50: # The exact interface definition obviously depends on the application. Chris@50: # Chris@50: # We call this a "bootstrap" because in an ideal Cap'n Proto world, bootstrap interfaces would Chris@50: # never be used. In such a world, any time you connect to a new vat, you do so because you Chris@50: # received an introduction from some other vat (see `ThirdPartyCapId`). Thus, the first message Chris@50: # you send is `Accept`, and further communications derive from there. `Bootstrap` is not used. Chris@50: # Chris@50: # In such an ideal world, DNS itself would support Cap'n Proto -- performing a DNS lookup would Chris@50: # actually return a new Cap'n Proto capability, thus introducing you to the target system via Chris@50: # level 3 RPC. Applications would receive the capability to talk to DNS in the first place as Chris@50: # an initial endowment or part of a Powerbox interaction. Therefore, an app can form arbitrary Chris@50: # connections without ever using `Bootstrap`. Chris@50: # Chris@50: # Of course, in the real world, DNS is not Cap'n-Proto-based, and we don't want Cap'n Proto to Chris@50: # require a whole new internet infrastructure to be useful. Therefore, we offer bootstrap Chris@50: # interfaces as a way to get up and running without a level 3 introduction. Thus, bootstrap Chris@50: # interfaces are used to "bootstrap" from other, non-Cap'n-Proto-based means of service discovery, Chris@50: # such as legacy DNS. Chris@50: # Chris@50: # Note that a vat need not provide a bootstrap interface, and in fact many vats (especially those Chris@50: # acting as clients) do not. In this case, the vat should either reply to `Bootstrap` with a Chris@50: # `Return` indicating an exception, or should return a dummy capability with no methods. Chris@50: Chris@50: questionId @0 :QuestionId; Chris@50: # A new question ID identifying this request, which will eventually receive a Return message Chris@50: # containing the restored capability. Chris@50: Chris@50: deprecatedObjectId @1 :AnyPointer; Chris@50: # ** DEPRECATED ** Chris@50: # Chris@50: # A Vat may export multiple bootstrap interfaces. In this case, `deprecatedObjectId` specifies Chris@50: # which one to return. If this pointer is null, then the default bootstrap interface is returned. Chris@50: # Chris@50: # As of verison 0.5, use of this field is deprecated. If a service wants to export multiple Chris@50: # bootstrap interfaces, it should instead define a single bootstarp interface that has methods Chris@50: # that return each of the other interfaces. Chris@50: # Chris@50: # **History** Chris@50: # Chris@50: # In the first version of Cap'n Proto RPC (0.4.x) the `Bootstrap` message was called `Restore`. Chris@50: # At the time, it was thought that this would eventually serve as the way to restore SturdyRefs Chris@50: # (level 2). Meanwhile, an application could offer its "main" interface on a well-known Chris@50: # (non-secret) SturdyRef. Chris@50: # Chris@50: # Since level 2 RPC was not implemented at the time, the `Restore` message was in practice only Chris@50: # used to obtain the main interface. Since most applications had only one main interface that Chris@50: # they wanted to restore, they tended to designate this with a null `objectId`. Chris@50: # Chris@50: # Unfortunately, the earliest version of the EZ RPC interfaces set a precedent of exporting Chris@50: # multiple main interfaces by allowing them to be exported under string names. In this case, Chris@50: # `objectId` was a Text value specifying the name. Chris@50: # Chris@50: # All of this proved problematic for several reasons: Chris@50: # Chris@50: # - The arrangement assumed that a client wishing to restore a SturdyRef would know exactly what Chris@50: # machine to connect to and would be able to immediately restore a SturdyRef on connection. Chris@50: # However, in practice, the ability to restore SturdyRefs is itself a capability that may Chris@50: # require going through an authentication process to obtain. Thus, it makes more sense to Chris@50: # define a "restorer service" as a full Cap'n Proto interface. If this restorer interface is Chris@50: # offered as the vat's bootstrap interface, then this is equivalent to the old arrangement. Chris@50: # Chris@50: # - Overloading "Restore" for the purpose of obtaining well-known capabilities encouraged the Chris@50: # practice of exporting singleton services with string names. If singleton services are desired, Chris@50: # it is better to have one main interface that has methods that can be used to obtain each Chris@50: # service, in order to get all the usual benefits of schemas and type checking. Chris@50: # Chris@50: # - Overloading "Restore" also had a security problem: Often, "main" or "well-known" Chris@50: # capabilities exported by a vat are in fact not public: they are intended to be accessed only Chris@50: # by clients who are capable of forming a connection to the vat. This can lead to trouble if Chris@50: # the client itself has other clients and wishes to foward some `Restore` requests from those Chris@50: # external clients -- it has to be very careful not to allow through `Restore` requests Chris@50: # addressing the default capability. Chris@50: # Chris@50: # For example, consider the case of a sandboxed Sandstorm application and its supervisor. The Chris@50: # application exports a default capability to its supervisor that provides access to Chris@50: # functionality that only the supervisor is supposed to access. Meanwhile, though, applications Chris@50: # may publish other capabilities that may be persistent, in which case the application needs Chris@50: # to field `Restore` requests that could come from anywhere. These requests of course have to Chris@50: # pass through the supervisor, as all communications with the outside world must. But, the Chris@50: # supervisor has to be careful not to honor an external request addressing the application's Chris@50: # default capability, since this capability is privileged. Unfortunately, the default Chris@50: # capability cannot be given an unguessable name, because then the supervisor itself would not Chris@50: # be able to address it! Chris@50: # Chris@50: # As of Cap'n Proto 0.5, `Restore` has been renamed to `Bootstrap` and is no longer planned for Chris@50: # use in restoring SturdyRefs. Chris@50: # Chris@50: # Note that 0.4 also defined a message type called `Delete` that, like `Restore`, addressed a Chris@50: # SturdyRef, but indicated that the client would not restore the ref again in the future. This Chris@50: # operation was never implemented, so it was removed entirely. If a "delete" operation is desired, Chris@50: # it should exist as a method on the same interface that handles restoring SturdyRefs. However, Chris@50: # the utility of such an operation is questionable. You wouldn't be able to rely on it for Chris@50: # garbage collection since a client could always disappear permanently without remembering to Chris@50: # delete all its SturdyRefs, thus leaving them dangling forever. Therefore, it is advisable to Chris@50: # design systems such that SturdyRefs never represent "owned" pointers. Chris@50: # Chris@50: # For example, say a SturdyRef points to an image file hosted on some server. That image file Chris@50: # should also live inside a collection (a gallery, perhaps) hosted on the same server, owned by Chris@50: # a user who can delete the image at any time. If the user deletes the image, the SturdyRef Chris@50: # stops working. On the other hand, if the SturdyRef is discarded, this has no effect on the Chris@50: # existence of the image in its collection. Chris@50: } Chris@50: Chris@50: struct Call { Chris@50: # **(level 0)** Chris@50: # Chris@50: # Message type initiating a method call on a capability. Chris@50: Chris@50: questionId @0 :QuestionId; Chris@50: # A number, chosen by the caller, that identifies this call in future messages. This number Chris@50: # must be different from all other calls originating from the same end of the connection (but Chris@50: # may overlap with question IDs originating from the opposite end). A fine strategy is to use Chris@50: # sequential question IDs, but the recipient should not assume this. Chris@50: # Chris@50: # A question ID can be reused once both: Chris@50: # - A matching Return has been received from the callee. Chris@50: # - A matching Finish has been sent from the caller. Chris@50: Chris@50: target @1 :MessageTarget; Chris@50: # The object that should receive this call. Chris@50: Chris@50: interfaceId @2 :UInt64; Chris@50: # The type ID of the interface being called. Each capability may implement multiple interfaces. Chris@50: Chris@50: methodId @3 :UInt16; Chris@50: # The ordinal number of the method to call within the requested interface. Chris@50: Chris@50: allowThirdPartyTailCall @8 :Bool = false; Chris@50: # Indicates whether or not the receiver is allowed to send a `Return` containing Chris@50: # `acceptFromThirdParty`. Level 3 implementations should set this true. Otherwise, the callee Chris@50: # will have to proxy the return in the case of a tail call to a third-party vat. Chris@50: Chris@50: params @4 :Payload; Chris@50: # The call parameters. `params.content` is a struct whose fields correspond to the parameters of Chris@50: # the method. Chris@50: Chris@50: sendResultsTo :union { Chris@50: # Where should the return message be sent? Chris@50: Chris@50: caller @5 :Void; Chris@50: # Send the return message back to the caller (the usual). Chris@50: Chris@50: yourself @6 :Void; Chris@50: # **(level 1)** Chris@50: # Chris@50: # Don't actually return the results to the sender. Instead, hold on to them and await Chris@50: # instructions from the sender regarding what to do with them. In particular, the sender Chris@50: # may subsequently send a `Return` for some other call (which the receiver had previously made Chris@50: # to the sender) with `takeFromOtherQuestion` set. The results from this call are then used Chris@50: # as the results of the other call. Chris@50: # Chris@50: # When `yourself` is used, the receiver must still send a `Return` for the call, but sets the Chris@50: # field `resultsSentElsewhere` in that `Return` rather than including the results. Chris@50: # Chris@50: # This feature can be used to implement tail calls in which a call from Vat A to Vat B ends up Chris@50: # returning the result of a call from Vat B back to Vat A. Chris@50: # Chris@50: # In particular, the most common use case for this feature is when Vat A makes a call to a Chris@50: # promise in Vat B, and then that promise ends up resolving to a capability back in Vat A. Chris@50: # Vat B must forward all the queued calls on that promise back to Vat A, but can set `yourself` Chris@50: # in the calls so that the results need not pass back through Vat B. Chris@50: # Chris@50: # For example: Chris@50: # - Alice, in Vat A, call foo() on Bob in Vat B. Chris@50: # - Alice makes a pipelined call bar() on the promise returned by foo(). Chris@50: # - Later on, Bob resolves the promise from foo() to point at Carol, who lives in Vat A (next Chris@50: # to Alice). Chris@50: # - Vat B dutifully forwards the bar() call to Carol. Let us call this forwarded call bar'(). Chris@50: # Notice that bar() and bar'() are travelling in opposite directions on the same network Chris@50: # link. Chris@50: # - The `Call` for bar'() has `sendResultsTo` set to `yourself`, with the value being the Chris@50: # question ID originally assigned to the bar() call. Chris@50: # - Vat A receives bar'() and delivers it to Carol. Chris@50: # - When bar'() returns, Vat A immediately takes the results and returns them from bar(). Chris@50: # - Meanwhile, Vat A sends a `Return` for bar'() to Vat B, with `resultsSentElsewhere` set in Chris@50: # place of results. Chris@50: # - Vat A sends a `Finish` for that call to Vat B. Chris@50: # - Vat B receives the `Return` for bar'() and sends a `Return` for bar(), with Chris@50: # `receivedFromYourself` set in place of the results. Chris@50: # - Vat B receives the `Finish` for bar() and sends a `Finish` to bar'(). Chris@50: Chris@50: thirdParty @7 :RecipientId; Chris@50: # **(level 3)** Chris@50: # Chris@50: # The call's result should be returned to a different vat. The receiver (the callee) expects Chris@50: # to receive an `Accept` message from the indicated vat, and should return the call's result Chris@50: # to it, rather than to the sender of the `Call`. Chris@50: # Chris@50: # This operates much like `yourself`, above, except that Carol is in a separate Vat C. `Call` Chris@50: # messages are sent from Vat A -> Vat B and Vat B -> Vat C. A `Return` message is sent from Chris@50: # Vat B -> Vat A that contains `acceptFromThirdParty` in place of results. When Vat A sends Chris@50: # an `Accept` to Vat C, it receives back a `Return` containing the call's actual result. Vat C Chris@50: # also sends a `Return` to Vat B with `resultsSentElsewhere`. Chris@50: } Chris@50: } Chris@50: Chris@50: struct Return { Chris@50: # **(level 0)** Chris@50: # Chris@50: # Message type sent from callee to caller indicating that the call has completed. Chris@50: Chris@50: answerId @0 :AnswerId; Chris@50: # Equal to the QuestionId of the corresponding `Call` message. Chris@50: Chris@50: releaseParamCaps @1 :Bool = true; Chris@50: # If true, all capabilities that were in the params should be considered released. The sender Chris@50: # must not send separate `Release` messages for them. Level 0 implementations in particular Chris@50: # should always set this true. This defaults true because if level 0 implementations forget to Chris@50: # set it they'll never notice (just silently leak caps), but if level >=1 implementations forget Chris@50: # to set it to false they'll quickly get errors. Chris@50: Chris@50: union { Chris@50: results @2 :Payload; Chris@50: # The result. Chris@50: # Chris@50: # For regular method calls, `results.content` points to the result struct. Chris@50: # Chris@50: # For a `Return` in response to an `Accept`, `results` contains a single capability (rather Chris@50: # than a struct), and `results.content` is just a capability pointer with index 0. A `Finish` Chris@50: # is still required in this case. Chris@50: Chris@50: exception @3 :Exception; Chris@50: # Indicates that the call failed and explains why. Chris@50: Chris@50: canceled @4 :Void; Chris@50: # Indicates that the call was canceled due to the caller sending a Finish message Chris@50: # before the call had completed. Chris@50: Chris@50: resultsSentElsewhere @5 :Void; Chris@50: # This is set when returning from a `Call` that had `sendResultsTo` set to something other Chris@50: # than `caller`. Chris@50: Chris@50: takeFromOtherQuestion @6 :QuestionId; Chris@50: # The sender has also sent (before this message) a `Call` with the given question ID and with Chris@50: # `sendResultsTo.yourself` set, and the results of that other call should be used as the Chris@50: # results here. Chris@50: Chris@50: acceptFromThirdParty @7 :ThirdPartyCapId; Chris@50: # **(level 3)** Chris@50: # Chris@50: # The caller should contact a third-party vat to pick up the results. An `Accept` message Chris@50: # sent to the vat will return the result. This pairs with `Call.sendResultsTo.thirdParty`. Chris@50: # It should only be used if the corresponding `Call` had `allowThirdPartyTailCall` set. Chris@50: } Chris@50: } Chris@50: Chris@50: struct Finish { Chris@50: # **(level 0)** Chris@50: # Chris@50: # Message type sent from the caller to the callee to indicate: Chris@50: # 1) The questionId will no longer be used in any messages sent by the callee (no further Chris@50: # pipelined requests). Chris@50: # 2) If the call has not returned yet, the caller no longer cares about the result. If nothing Chris@50: # else cares about the result either (e.g. there are no other outstanding calls pipelined on Chris@50: # the result of this one) then the callee may wish to immediately cancel the operation and Chris@50: # send back a Return message with "canceled" set. However, implementations are not required Chris@50: # to support premature cancellation -- instead, the implementation may wait until the call Chris@50: # actually completes and send a normal `Return` message. Chris@50: # Chris@50: # TODO(someday): Should we separate (1) and implicitly releasing result capabilities? It would be Chris@50: # possible and useful to notify the server that it doesn't need to keep around the response to Chris@50: # service pipeline requests even though the caller still wants to receive it / hasn't yet Chris@50: # finished processing it. It could also be useful to notify the server that it need not marshal Chris@50: # the results because the caller doesn't want them anyway, even if the caller is still sending Chris@50: # pipelined calls, although this seems less useful (just saving some bytes on the wire). Chris@50: Chris@50: questionId @0 :QuestionId; Chris@50: # ID of the call whose result is to be released. Chris@50: Chris@50: releaseResultCaps @1 :Bool = true; Chris@50: # If true, all capabilities that were in the results should be considered released. The sender Chris@50: # must not send separate `Release` messages for them. Level 0 implementations in particular Chris@50: # should always set this true. This defaults true because if level 0 implementations forget to Chris@50: # set it they'll never notice (just silently leak caps), but if level >=1 implementations forget Chris@50: # set it false they'll quickly get errors. Chris@50: } Chris@50: Chris@50: # Level 1 message types ---------------------------------------------- Chris@50: Chris@50: struct Resolve { Chris@50: # **(level 1)** Chris@50: # Chris@50: # Message type sent to indicate that a previously-sent promise has now been resolved to some other Chris@50: # object (possibly another promise) -- or broken, or canceled. Chris@50: # Chris@50: # Keep in mind that it's possible for a `Resolve` to be sent to a level 0 implementation that Chris@50: # doesn't implement it. For example, a method call or return might contain a capability in the Chris@50: # payload. Normally this is fine even if the receiver is level 0, because they will implicitly Chris@50: # release all such capabilities on return / finish. But if the cap happens to be a promise, then Chris@50: # a follow-up `Resolve` may be sent regardless of this release. The level 0 receiver will reply Chris@50: # with an `unimplemented` message, and the sender (of the `Resolve`) can respond to this as if the Chris@50: # receiver had immediately released any capability to which the promise resolved. Chris@50: # Chris@50: # When implementing promise resolution, it's important to understand how embargos work and the Chris@50: # tricky case of the Tribble 4-way race condition. See the comments for the Disembargo message, Chris@50: # below. Chris@50: Chris@50: promiseId @0 :ExportId; Chris@50: # The ID of the promise to be resolved. Chris@50: # Chris@50: # Unlike all other instances of `ExportId` sent from the exporter, the `Resolve` message does Chris@50: # _not_ increase the reference count of `promiseId`. In fact, it is expected that the receiver Chris@50: # will release the export soon after receiving `Resolve`, and the sender will not send this Chris@50: # `ExportId` again until it has been released and recycled. Chris@50: # Chris@50: # When an export ID sent over the wire (e.g. in a `CapDescriptor`) is indicated to be a promise, Chris@50: # this indicates that the sender will follow up at some point with a `Resolve` message. If the Chris@50: # same `promiseId` is sent again before `Resolve`, still only one `Resolve` is sent. If the Chris@50: # same ID is sent again later _after_ a `Resolve`, it can only be because the export's Chris@50: # reference count hit zero in the meantime and the ID was re-assigned to a new export, therefore Chris@50: # this later promise does _not_ correspond to the earlier `Resolve`. Chris@50: # Chris@50: # If a promise ID's reference count reaches zero before a `Resolve` is sent, the `Resolve` Chris@50: # message may or may not still be sent (the `Resolve` may have already been in-flight when Chris@50: # `Release` was sent, but if the `Release` is received before `Resolve` then there is no longer Chris@50: # any reason to send a `Resolve`). Thus a `Resolve` may be received for a promise of which Chris@50: # the receiver has no knowledge, because it already released it earlier. In this case, the Chris@50: # receiver should simply release the capability to which the promise resolved. Chris@50: Chris@50: union { Chris@50: cap @1 :CapDescriptor; Chris@50: # The object to which the promise resolved. Chris@50: # Chris@50: # The sender promises that from this point forth, until `promiseId` is released, it shall Chris@50: # simply forward all messages to the capability designated by `cap`. This is true even if Chris@50: # `cap` itself happens to desigate another promise, and that other promise later resolves -- Chris@50: # messages sent to `promiseId` shall still go to that other promise, not to its resolution. Chris@50: # This is important in the case that the receiver of the `Resolve` ends up sending a Chris@50: # `Disembargo` message towards `promiseId` in order to control message ordering -- that Chris@50: # `Disembargo` really needs to reflect back to exactly the object designated by `cap` even Chris@50: # if that object is itself a promise. Chris@50: Chris@50: exception @2 :Exception; Chris@50: # Indicates that the promise was broken. Chris@50: } Chris@50: } Chris@50: Chris@50: struct Release { Chris@50: # **(level 1)** Chris@50: # Chris@50: # Message type sent to indicate that the sender is done with the given capability and the receiver Chris@50: # can free resources allocated to it. Chris@50: Chris@50: id @0 :ImportId; Chris@50: # What to release. Chris@50: Chris@50: referenceCount @1 :UInt32; Chris@50: # The amount by which to decrement the reference count. The export is only actually released Chris@50: # when the reference count reaches zero. Chris@50: } Chris@50: Chris@50: struct Disembargo { Chris@50: # **(level 1)** Chris@50: # Chris@50: # Message sent to indicate that an embargo on a recently-resolved promise may now be lifted. Chris@50: # Chris@50: # Embargos are used to enforce E-order in the presence of promise resolution. That is, if an Chris@50: # application makes two calls foo() and bar() on the same capability reference, in that order, Chris@50: # the calls should be delivered in the order in which they were made. But if foo() is called Chris@50: # on a promise, and that promise happens to resolve before bar() is called, then the two calls Chris@50: # may travel different paths over the network, and thus could arrive in the wrong order. In Chris@50: # this case, the call to `bar()` must be embargoed, and a `Disembargo` message must be sent along Chris@50: # the same path as `foo()` to ensure that the `Disembargo` arrives after `foo()`. Once the Chris@50: # `Disembargo` arrives, `bar()` can then be delivered. Chris@50: # Chris@50: # There are two particular cases where embargos are important. Consider object Alice, in Vat A, Chris@50: # who holds a promise P, pointing towards Vat B, that eventually resolves to Carol. The two Chris@50: # cases are: Chris@50: # - Carol lives in Vat A, i.e. next to Alice. In this case, Vat A needs to send a `Disembargo` Chris@50: # message that echos through Vat B and back, to ensure that all pipelined calls on the promise Chris@50: # have been delivered. Chris@50: # - Carol lives in a different Vat C. When the promise resolves, a three-party handoff occurs Chris@50: # (see `Provide` and `Accept`, which constitute level 3 of the protocol). In this case, we Chris@50: # piggyback on the state that has already been set up to handle the handoff: the `Accept` Chris@50: # message (from Vat A to Vat C) is embargoed, as are all pipelined messages sent to it, while Chris@50: # a `Disembargo` message is sent from Vat A through Vat B to Vat C. See `Accept.embargo` for Chris@50: # an example. Chris@50: # Chris@50: # Note that in the case where Carol actually lives in Vat B (i.e., the same vat that the promise Chris@50: # already pointed at), no embargo is needed, because the pipelined calls are delivered over the Chris@50: # same path as the later direct calls. Chris@50: # Chris@50: # Keep in mind that promise resolution happens both in the form of Resolve messages as well as Chris@50: # Return messages (which resolve PromisedAnswers). Embargos apply in both cases. Chris@50: # Chris@50: # An alternative strategy for enforcing E-order over promise resolution could be for Vat A to Chris@50: # implement the embargo internally. When Vat A is notified of promise resolution, it could Chris@50: # send a dummy no-op call to promise P and wait for it to complete. Until that call completes, Chris@50: # all calls to the capability are queued locally. This strategy works, but is pessimistic: Chris@50: # in the three-party case, it requires an A -> B -> C -> B -> A round trip before calls can start Chris@50: # being delivered directly to from Vat A to Vat C. The `Disembargo` message allows latency to be Chris@50: # reduced. (In the two-party loopback case, the `Disembargo` message is just a more explicit way Chris@50: # of accomplishing the same thing as a no-op call, but isn't any faster.) Chris@50: # Chris@50: # *The Tribble 4-way Race Condition* Chris@50: # Chris@50: # Any implementation of promise resolution and embargos must be aware of what we call the Chris@50: # "Tribble 4-way race condition", after Dean Tribble, who explained the problem in a lively Chris@50: # Friam meeting. Chris@50: # Chris@50: # Embargos are designed to work in the case where a two-hop path is being shortened to one hop. Chris@50: # But sometimes there are more hops. Imagine that Alice has a reference to a remote promise P1 Chris@50: # that eventually resolves to _another_ remote promise P2 (in a third vat), which _at the same Chris@50: # time_ happens to resolve to Bob (in a fourth vat). In this case, we're shortening from a 3-hop Chris@50: # path (with four parties) to a 1-hop path (Alice -> Bob). Chris@50: # Chris@50: # Extending the embargo/disembargo protocol to be able to shorted multiple hops at once seems Chris@50: # difficult. Instead, we make a rule that prevents this case from coming up: Chris@50: # Chris@50: # One a promise P has been resolved to a remove object reference R, then all further messages Chris@50: # received addressed to P will be forwarded strictly to R. Even if it turns out later that R is Chris@50: # itself a promise, and has resolved to some other object Q, messages sent to P will still be Chris@50: # forwarded to R, not directly to Q (R will of course further forward the messages to Q). Chris@50: # Chris@50: # This rule does not cause a significant performance burden because once P has resolved to R, it Chris@50: # is expected that people sending messages to P will shortly start sending them to R instead and Chris@50: # drop P. P is at end-of-life anyway, so it doesn't matter if it ignores chances to further Chris@50: # optimize its path. Chris@50: Chris@50: target @0 :MessageTarget; Chris@50: # What is to be disembargoed. Chris@50: Chris@50: using EmbargoId = UInt32; Chris@50: # Used in `senderLoopback` and `receiverLoopback`, below. Chris@50: Chris@50: context :union { Chris@50: senderLoopback @1 :EmbargoId; Chris@50: # The sender is requesting a disembargo on a promise that is known to resolve back to a Chris@50: # capability hosted by the sender. As soon as the receiver has echoed back all pipelined calls Chris@50: # on this promise, it will deliver the Disembargo back to the sender with `receiverLoopback` Chris@50: # set to the same value as `senderLoopback`. This value is chosen by the sender, and since Chris@50: # it is also consumed be the sender, the sender can use whatever strategy it wants to make sure Chris@50: # the value is unambiguous. Chris@50: # Chris@50: # The receiver must verify that the target capability actually resolves back to the sender's Chris@50: # vat. Otherwise, the sender has committed a protocol error and should be disconnected. Chris@50: Chris@50: receiverLoopback @2 :EmbargoId; Chris@50: # The receiver previously sent a `senderLoopback` Disembargo towards a promise resolving to Chris@50: # this capability, and that Disembargo is now being echoed back. Chris@50: Chris@50: accept @3 :Void; Chris@50: # **(level 3)** Chris@50: # Chris@50: # The sender is requesting a disembargo on a promise that is known to resolve to a third-party Chris@50: # capability that the sender is currently in the process of accepting (using `Accept`). Chris@50: # The receiver of this `Disembargo` has an outstanding `Provide` on said capability. The Chris@50: # receiver should now send a `Disembargo` with `provide` set to the question ID of that Chris@50: # `Provide` message. Chris@50: # Chris@50: # See `Accept.embargo` for an example. Chris@50: Chris@50: provide @4 :QuestionId; Chris@50: # **(level 3)** Chris@50: # Chris@50: # The sender is requesting a disembargo on a capability currently being provided to a third Chris@50: # party. The question ID identifies the `Provide` message previously sent by the sender to Chris@50: # this capability. On receipt, the receiver (the capability host) shall release the embargo Chris@50: # on the `Accept` message that it has received from the third party. See `Accept.embargo` for Chris@50: # an example. Chris@50: } Chris@50: } Chris@50: Chris@50: # Level 2 message types ---------------------------------------------- Chris@50: Chris@50: # See persistent.capnp. Chris@50: Chris@50: # Level 3 message types ---------------------------------------------- Chris@50: Chris@50: struct Provide { Chris@50: # **(level 3)** Chris@50: # Chris@50: # Message type sent to indicate that the sender wishes to make a particular capability implemented Chris@50: # by the receiver available to a third party for direct access (without the need for the third Chris@50: # party to proxy through the sender). Chris@50: # Chris@50: # (In CapTP, `Provide` and `Accept` are methods of the global `NonceLocator` object exported by Chris@50: # every vat. In Cap'n Proto, we bake this into the core protocol.) Chris@50: Chris@50: questionId @0 :QuestionId; Chris@50: # Question ID to be held open until the recipient has received the capability. A result will be Chris@50: # returned once the third party has successfully received the capability. The sender must at some Chris@50: # point send a `Finish` message as with any other call, and that message can be used to cancel the Chris@50: # whole operation. Chris@50: Chris@50: target @1 :MessageTarget; Chris@50: # What is to be provided to the third party. Chris@50: Chris@50: recipient @2 :RecipientId; Chris@50: # Identity of the third party that is expected to pick up the capability. Chris@50: } Chris@50: Chris@50: struct Accept { Chris@50: # **(level 3)** Chris@50: # Chris@50: # Message type sent to pick up a capability hosted by the receiving vat and provided by a third Chris@50: # party. The third party previously designated the capability using `Provide`. Chris@50: # Chris@50: # This message is also used to pick up a redirected return -- see `Return.redirect`. Chris@50: Chris@50: questionId @0 :QuestionId; Chris@50: # A new question ID identifying this accept message, which will eventually receive a Return Chris@50: # message containing the provided capability (or the call result in the case of a redirected Chris@50: # return). Chris@50: Chris@50: provision @1 :ProvisionId; Chris@50: # Identifies the provided object to be picked up. Chris@50: Chris@50: embargo @2 :Bool; Chris@50: # If true, this accept shall be temporarily embargoed. The resulting `Return` will not be sent, Chris@50: # and any pipelined calls will not be delivered, until the embargo is released. The receiver Chris@50: # (the capability host) will expect the provider (the vat that sent the `Provide` message) to Chris@50: # eventually send a `Disembargo` message with the field `context.provide` set to the question ID Chris@50: # of the original `Provide` message. At that point, the embargo is released and the queued Chris@50: # messages are delivered. Chris@50: # Chris@50: # For example: Chris@50: # - Alice, in Vat A, holds a promise P, which currently points toward Vat B. Chris@50: # - Alice calls foo() on P. The `Call` message is sent to Vat B. Chris@50: # - The promise P in Vat B ends up resolving to Carol, in Vat C. Chris@50: # - Vat B sends a `Provide` message to Vat C, identifying Vat A as the recipient. Chris@50: # - Vat B sends a `Resolve` message to Vat A, indicating that the promise has resolved to a Chris@50: # `ThirdPartyCapId` identifying Carol in Vat C. Chris@50: # - Vat A sends an `Accept` message to Vat C to pick up the capability. Since Vat A knows that Chris@50: # it has an outstanding call to the promise, it sets `embargo` to `true` in the `Accept` Chris@50: # message. Chris@50: # - Vat A sends a `Disembargo` message to Vat B on promise P, with `context.accept` set. Chris@50: # - Alice makes a call bar() to promise P, which is now pointing towards Vat C. Alice doesn't Chris@50: # know anything about the mechanics of promise resolution happening under the hood, but she Chris@50: # expects that bar() will be delivered after foo() because that is the order in which she Chris@50: # initiated the calls. Chris@50: # - Vat A sends the bar() call to Vat C, as a pipelined call on the result of the `Accept` (which Chris@50: # hasn't returned yet, due to the embargo). Since calls to the newly-accepted capability Chris@50: # are embargoed, Vat C does not deliver the call yet. Chris@50: # - At some point, Vat B forwards the foo() call from the beginning of this example on to Vat C. Chris@50: # - Vat B forwards the `Disembargo` from Vat A on to vat C. It sets `context.provide` to the Chris@50: # question ID of the `Provide` message it had sent previously. Chris@50: # - Vat C receives foo() before `Disembargo`, thus allowing it to correctly deliver foo() Chris@50: # before delivering bar(). Chris@50: # - Vat C receives `Disembargo` from Vat B. It can now send a `Return` for the `Accept` from Chris@50: # Vat A, as well as deliver bar(). Chris@50: } Chris@50: Chris@50: # Level 4 message types ---------------------------------------------- Chris@50: Chris@50: struct Join { Chris@50: # **(level 4)** Chris@50: # Chris@50: # Message type sent to implement E.join(), which, given a number of capabilities that are Chris@50: # expected to be equivalent, finds the underlying object upon which they all agree and forms a Chris@50: # direct connection to it, skipping any proxies that may have been constructed by other vats Chris@50: # while transmitting the capability. See: Chris@50: # http://erights.org/elib/equality/index.html Chris@50: # Chris@50: # Note that this should only serve to bypass fully-transparent proxies -- proxies that were Chris@50: # created merely for convenience, without any intention of hiding the underlying object. Chris@50: # Chris@50: # For example, say Bob holds two capabilities hosted by Alice and Carol, but he expects that both Chris@50: # are simply proxies for a capability hosted elsewhere. He then issues a join request, which Chris@50: # operates as follows: Chris@50: # - Bob issues Join requests on both Alice and Carol. Each request contains a different piece Chris@50: # of the JoinKey. Chris@50: # - Alice is proxying a capability hosted by Dana, so forwards the request to Dana's cap. Chris@50: # - Dana receives the first request and sees that the JoinKeyPart is one of two. She notes that Chris@50: # she doesn't have the other part yet, so she records the request and responds with a Chris@50: # JoinResult. Chris@50: # - Alice relays the JoinAswer back to Bob. Chris@50: # - Carol is also proxying a capability from Dana, and so forwards her Join request to Dana as Chris@50: # well. Chris@50: # - Dana receives Carol's request and notes that she now has both parts of a JoinKey. She Chris@50: # combines them in order to form information needed to form a secure connection to Bob. She Chris@50: # also responds with another JoinResult. Chris@50: # - Bob receives the responses from Alice and Carol. He uses the returned JoinResults to Chris@50: # determine how to connect to Dana and attempts to form the connection. Since Bob and Dana now Chris@50: # agree on a secret key that neither Alice nor Carol ever saw, this connection can be made Chris@50: # securely even if Alice or Carol is conspiring against the other. (If Alice and Carol are Chris@50: # conspiring _together_, they can obviously reproduce the key, but this doesn't matter because Chris@50: # the whole point of the join is to verify that Alice and Carol agree on what capability they Chris@50: # are proxying.) Chris@50: # Chris@50: # If the two capabilities aren't actually proxies of the same object, then the join requests Chris@50: # will come back with conflicting `hostId`s and the join will fail before attempting to form any Chris@50: # connection. Chris@50: Chris@50: questionId @0 :QuestionId; Chris@50: # Question ID used to respond to this Join. (Note that this ID only identifies one part of the Chris@50: # request for one hop; each part has a different ID and relayed copies of the request have Chris@50: # (probably) different IDs still.) Chris@50: # Chris@50: # The receiver will reply with a `Return` whose `results` is a JoinResult. This `JoinResult` Chris@50: # is relayed from the joined object's host, possibly with transformation applied as needed Chris@50: # by the network. Chris@50: # Chris@50: # Like any return, the result must be released using a `Finish`. However, this release Chris@50: # should not occur until the joiner has either successfully connected to the joined object. Chris@50: # Vats relaying a `Join` message similarly must not release the result they receive until the Chris@50: # return they relayed back towards the joiner has itself been released. This allows the Chris@50: # joined object's host to detect when the Join operation is canceled before completing -- if Chris@50: # it receives a `Finish` for one of the join results before the joiner successfully Chris@50: # connects. It can then free any resources it had allocated as part of the join. Chris@50: Chris@50: target @1 :MessageTarget; Chris@50: # The capability to join. Chris@50: Chris@50: keyPart @2 :JoinKeyPart; Chris@50: # A part of the join key. These combine to form the complete join key, which is used to establish Chris@50: # a direct connection. Chris@50: Chris@50: # TODO(before implementing): Change this so that multiple parts can be sent in a single Join Chris@50: # message, so that if multiple join parts are going to cross the same connection they can be sent Chris@50: # together, so that the receive can potentially optimize its handling of them. In the case where Chris@50: # all parts are bundled together, should the recipient be expected to simply return a cap, so Chris@50: # that the caller can immediately start pipelining to it? Chris@50: } Chris@50: Chris@50: # ======================================================================================== Chris@50: # Common structures used in messages Chris@50: Chris@50: struct MessageTarget { Chris@50: # The target of a `Call` or other messages that target a capability. Chris@50: Chris@50: union { Chris@50: importedCap @0 :ImportId; Chris@50: # This message is to a capability or promise previously imported by the caller (exported by Chris@50: # the receiver). Chris@50: Chris@50: promisedAnswer @1 :PromisedAnswer; Chris@50: # This message is to a capability that is expected to be returned by another call that has not Chris@50: # yet been completed. Chris@50: # Chris@50: # At level 0, this is supported only for addressing the result of a previous `Bootstrap`, so Chris@50: # that initial startup doesn't require a round trip. Chris@50: } Chris@50: } Chris@50: Chris@50: struct Payload { Chris@50: # Represents some data structure that might contain capabilities. Chris@50: Chris@50: content @0 :AnyPointer; Chris@50: # Some Cap'n Proto data structure. Capability pointers embedded in this structure index into Chris@50: # `capTable`. Chris@50: Chris@50: capTable @1 :List(CapDescriptor); Chris@50: # Descriptors corresponding to the cap pointers in `content`. Chris@50: } Chris@50: Chris@50: struct CapDescriptor { Chris@50: # **(level 1)** Chris@50: # Chris@50: # When an application-defined type contains an interface pointer, that pointer contains an index Chris@50: # into the message's capability table -- i.e. the `capTable` part of the `Payload`. Each Chris@50: # capability in the table is represented as a `CapDescriptor`. The runtime API should not reveal Chris@50: # the CapDescriptor directly to the application, but should instead wrap it in some kind of Chris@50: # callable object with methods corresponding to the interface that the capability implements. Chris@50: # Chris@50: # Keep in mind that `ExportIds` in a `CapDescriptor` are subject to reference counting. See the Chris@50: # description of `ExportId`. Chris@50: Chris@50: union { Chris@50: none @0 :Void; Chris@50: # There is no capability here. This `CapDescriptor` should not appear in the payload content. Chris@50: # A `none` CapDescriptor can be generated when an application inserts a capability into a Chris@50: # message and then later changes its mind and removes it -- rewriting all of the other Chris@50: # capability pointers may be hard, so instead a tombstone is left, similar to the way a removed Chris@50: # struct or list instance is zeroed out of the message but the space is not reclaimed. Chris@50: # Hopefully this is unusual. Chris@50: Chris@50: senderHosted @1 :ExportId; Chris@50: # A capability newly exported by the sender. This is the ID of the new capability in the Chris@50: # sender's export table (receiver's import table). Chris@50: Chris@50: senderPromise @2 :ExportId; Chris@50: # A promise that the sender will resolve later. The sender will send exactly one Resolve Chris@50: # message at a future point in time to replace this promise. Note that even if the same Chris@50: # `senderPromise` is received multiple times, only one `Resolve` is sent to cover all of Chris@50: # them. If `senderPromise` is released before the `Resolve` is sent, the sender (of this Chris@50: # `CapDescriptor`) may choose not to send the `Resolve` at all. Chris@50: Chris@50: receiverHosted @3 :ImportId; Chris@50: # A capability (or promise) previously exported by the receiver (imported by the sender). Chris@50: Chris@50: receiverAnswer @4 :PromisedAnswer; Chris@50: # A capability expected to be returned in the results of a currently-outstanding call posed Chris@50: # by the sender. Chris@50: Chris@50: thirdPartyHosted @5 :ThirdPartyCapDescriptor; Chris@50: # **(level 3)** Chris@50: # Chris@50: # A capability that lives in neither the sender's nor the receiver's vat. The sender needs Chris@50: # to form a direct connection to a third party to pick up the capability. Chris@50: # Chris@50: # Level 1 and 2 implementations that receive a `thirdPartyHosted` may simply send calls to its Chris@50: # `vine` instead. Chris@50: } Chris@50: } Chris@50: Chris@50: struct PromisedAnswer { Chris@50: # **(mostly level 1)** Chris@50: # Chris@50: # Specifies how to derive a promise from an unanswered question, by specifying the path of fields Chris@50: # to follow from the root of the eventual result struct to get to the desired capability. Used Chris@50: # to address method calls to a not-yet-returned capability or to pass such a capability as an Chris@50: # input to some other method call. Chris@50: # Chris@50: # Level 0 implementations must support `PromisedAnswer` only for the case where the answer is Chris@50: # to a `Bootstrap` message. In this case, `path` is always empty since `Bootstrap` always returns Chris@50: # a raw capability. Chris@50: Chris@50: questionId @0 :QuestionId; Chris@50: # ID of the question (in the sender's question table / receiver's answer table) whose answer is Chris@50: # expected to contain the capability. Chris@50: Chris@50: transform @1 :List(Op); Chris@50: # Operations / transformations to apply to the result in order to get the capability actually Chris@50: # being addressed. E.g. if the result is a struct and you want to call a method on a capability Chris@50: # pointed to by a field of the struct, you need a `getPointerField` op. Chris@50: Chris@50: struct Op { Chris@50: union { Chris@50: noop @0 :Void; Chris@50: # Does nothing. This member is mostly defined so that we can make `Op` a union even Chris@50: # though (as of this writing) only one real operation is defined. Chris@50: Chris@50: getPointerField @1 :UInt16; Chris@50: # Get a pointer field within a struct. The number is an index into the pointer section, NOT Chris@50: # a field ordinal, so that the receiver does not need to understand the schema. Chris@50: Chris@50: # TODO(someday): We could add: Chris@50: # - For lists, the ability to address every member of the list, or a slice of the list, the Chris@50: # result of which would be another list. This is useful for implementing the equivalent of Chris@50: # a SQL table join (not to be confused with the `Join` message type). Chris@50: # - Maybe some ability to test a union. Chris@50: # - Probably not a good idea: the ability to specify an arbitrary script to run on the Chris@50: # result. We could define a little stack-based language where `Op` specifies one Chris@50: # "instruction" or transformation to apply. Although this is not a good idea Chris@50: # (over-engineered), any narrower additions to `Op` should be designed as if this Chris@50: # were the eventual goal. Chris@50: } Chris@50: } Chris@50: } Chris@50: Chris@50: struct ThirdPartyCapDescriptor { Chris@50: # **(level 3)** Chris@50: # Chris@50: # Identifies a capability in a third-party vat that the sender wants the receiver to pick up. Chris@50: Chris@50: id @0 :ThirdPartyCapId; Chris@50: # Identifies the third-party host and the specific capability to accept from it. Chris@50: Chris@50: vineId @1 :ExportId; Chris@50: # A proxy for the third-party object exported by the sender. In CapTP terminology this is called Chris@50: # a "vine", because it is an indirect reference to the third-party object that snakes through the Chris@50: # sender vat. This serves two purposes: Chris@50: # Chris@50: # * Level 1 and 2 implementations that don't understand how to connect to a third party may Chris@50: # simply send calls to the vine. Such calls will be forwarded to the third-party by the Chris@50: # sender. Chris@50: # Chris@50: # * Level 3 implementations must release the vine once they have successfully picked up the Chris@50: # object from the third party. This ensures that the capability is not released by the sender Chris@50: # prematurely. Chris@50: # Chris@50: # The sender will close the `Provide` request that it has sent to the third party as soon as Chris@50: # it receives either a `Call` or a `Release` message directed at the vine. Chris@50: } Chris@50: Chris@50: struct Exception { Chris@50: # **(level 0)** Chris@50: # Chris@50: # Describes an arbitrary error that prevented an operation (e.g. a call) from completing. Chris@50: # Chris@50: # Cap'n Proto exceptions always indicate that something went wrong. In other words, in a fantasy Chris@50: # world where everything always works as expected, no exceptions would ever be thrown. Clients Chris@50: # should only ever catch exceptions as a means to implement fault-tolerance, where "fault" can Chris@50: # mean: Chris@50: # - Bugs. Chris@50: # - Invalid input. Chris@50: # - Configuration errors. Chris@50: # - Network problems. Chris@50: # - Insufficient resources. Chris@50: # - Version skew (unimplemented functionality). Chris@50: # - Other logistical problems. Chris@50: # Chris@50: # Exceptions should NOT be used to flag application-specific conditions that a client is expected Chris@50: # to handle in an application-specific way. Put another way, in the Cap'n Proto world, Chris@50: # "checked exceptions" (where an interface explicitly defines the exceptions it throws and Chris@50: # clients are forced by the type system to handle those exceptions) do NOT make sense. Chris@50: Chris@50: reason @0 :Text; Chris@50: # Human-readable failure description. Chris@50: Chris@50: type @3 :Type; Chris@50: # The type of the error. The purpose of this enum is not to describe the error itself, but Chris@50: # rather to describe how the client might want to respond to the error. Chris@50: Chris@50: enum Type { Chris@50: failed @0; Chris@50: # A generic problem occurred, and it is believed that if the operation were repeated without Chris@50: # any change in the state of the world, the problem would occur again. Chris@50: # Chris@50: # A client might respond to this error by logging it for investigation by the developer and/or Chris@50: # displaying it to the user. Chris@50: Chris@50: overloaded @1; Chris@50: # The request was rejected due to a temporary lack of resources. Chris@50: # Chris@50: # Examples include: Chris@50: # - There's not enough CPU time to keep up with incoming requests, so some are rejected. Chris@50: # - The server ran out of RAM or disk space during the request. Chris@50: # - The operation timed out (took significantly longer than it should have). Chris@50: # Chris@50: # A client might respond to this error by scheduling to retry the operation much later. The Chris@50: # client should NOT retry again immediately since this would likely exacerbate the problem. Chris@50: Chris@50: disconnected @2; Chris@50: # The method failed because a connection to some necessary capability was lost. Chris@50: # Chris@50: # Examples include: Chris@50: # - The client introduced the server to a third-party capability, the connection to that third Chris@50: # party was subsequently lost, and then the client requested that the server use the dead Chris@50: # capability for something. Chris@50: # - The client previously requested that the server obtain a capability from some third party. Chris@50: # The server returned a capability to an object wrapping the third-party capability. Later, Chris@50: # the server's connection to the third party was lost. Chris@50: # - The capability has been revoked. Revocation does not necessarily mean that the client is Chris@50: # no longer authorized to use the capability; it is often used simply as a way to force the Chris@50: # client to repeat the setup process, perhaps to efficiently move them to a new back-end or Chris@50: # get them to recognize some other change that has occurred. Chris@50: # Chris@50: # A client should normally respond to this error by releasing all capabilities it is currently Chris@50: # holding related to the one it called and then re-creating them by restoring SturdyRefs and/or Chris@50: # repeating the method calls used to create them originally. In other words, disconnect and Chris@50: # start over. This should in turn cause the server to obtain a new copy of the capability that Chris@50: # it lost, thus making everything work. Chris@50: # Chris@50: # If the client receives another `disconnencted` error in the process of rebuilding the Chris@50: # capability and retrying the call, it should treat this as an `overloaded` error: the network Chris@50: # is currently unreliable, possibly due to load or other temporary issues. Chris@50: Chris@50: unimplemented @3; Chris@50: # The server doesn't implement the requested method. If there is some other method that the Chris@50: # client could call (perhaps an older and/or slower interface), it should try that instead. Chris@50: # Otherwise, this should be treated like `failed`. Chris@50: } Chris@50: Chris@50: obsoleteIsCallersFault @1 :Bool; Chris@50: # OBSOLETE. Ignore. Chris@50: Chris@50: obsoleteDurability @2 :UInt16; Chris@50: # OBSOLETE. See `type` instead. Chris@50: } Chris@50: Chris@50: # ======================================================================================== Chris@50: # Network-specific Parameters Chris@50: # Chris@50: # Some parts of the Cap'n Proto RPC protocol are not specified here because different vat networks Chris@50: # may wish to use different approaches to solving them. For example, on the public internet, you Chris@50: # may want to authenticate vats using public-key cryptography, but on a local intranet with trusted Chris@50: # infrastructure, you may be happy to authenticate based on network address only, or some other Chris@50: # lightweight mechanism. Chris@50: # Chris@50: # To accommodate this, we specify several "parameter" types. Each type is defined here as an Chris@50: # alias for `AnyPointer`, but a specific network will want to define a specific set of types to use. Chris@50: # All vats in a vat network must agree on these parameters in order to be able to communicate. Chris@50: # Inter-network communication can be accomplished through "gateways" that perform translation Chris@50: # between the primitives used on each network; these gateways may need to be deeply stateful, Chris@50: # depending on the translations they perform. Chris@50: # Chris@50: # For interaction over the global internet between parties with no other prior arrangement, a Chris@50: # particular set of bindings for these types is defined elsewhere. (TODO(someday): Specify where Chris@50: # these common definitions live.) Chris@50: # Chris@50: # Another common network type is the two-party network, in which one of the parties typically Chris@50: # interacts with the outside world entirely through the other party. In such a connection between Chris@50: # Alice and Bob, all objects that exist on Bob's other networks appear to Alice as if they were Chris@50: # hosted by Bob himself, and similarly all objects on Alice's network (if she even has one) appear Chris@50: # to Bob as if they were hosted by Alice. This network type is interesting because from the point Chris@50: # of view of a simple application that communicates with only one other party via the two-party Chris@50: # protocol, there are no three-party interactions at all, and joins are unusually simple to Chris@50: # implement, so implementing at level 4 is barely more complicated than implementing at level 1. Chris@50: # Moreover, if you pair an app implementing the two-party network with a container that implements Chris@50: # some other network, the app can then participate on the container's network just as if it Chris@50: # implemented that network directly. The types used by the two-party network are defined in Chris@50: # `rpc-twoparty.capnp`. Chris@50: # Chris@50: # The things that we need to parameterize are: Chris@50: # - How to store capabilities long-term without holding a connection open (mostly level 2). Chris@50: # - How to authenticate vats in three-party introductions (level 3). Chris@50: # - How to implement `Join` (level 4). Chris@50: # Chris@50: # Persistent references Chris@50: # --------------------- Chris@50: # Chris@50: # **(mostly level 2)** Chris@50: # Chris@50: # We want to allow some capabilities to be stored long-term, even if a connection is lost and later Chris@50: # recreated. ExportId is a short-term identifier that is specific to a connection, so it doesn't Chris@50: # help here. We need a way to specify long-term identifiers, as well as a strategy for Chris@50: # reconnecting to a referenced capability later. Chris@50: # Chris@50: # Three-party interactions Chris@50: # ------------------------ Chris@50: # Chris@50: # **(level 3)** Chris@50: # Chris@50: # In cases where more than two vats are interacting, we have situations where VatA holds a Chris@50: # capability hosted by VatB and wants to send that capability to VatC. This can be accomplished Chris@50: # by VatA proxying requests on the new capability, but doing so has two big problems: Chris@50: # - It's inefficient, requiring an extra network hop. Chris@50: # - If VatC receives another capability to the same object from VatD, it is difficult for VatC to Chris@50: # detect that the two capabilities are really the same and to implement the E "join" operation, Chris@50: # which is necessary for certain four-or-more-party interactions, such as the escrow pattern. Chris@50: # See: http://www.erights.org/elib/equality/grant-matcher/index.html Chris@50: # Chris@50: # Instead, we want a way for VatC to form a direct, authenticated connection to VatB. Chris@50: # Chris@50: # Join Chris@50: # ---- Chris@50: # Chris@50: # **(level 4)** Chris@50: # Chris@50: # The `Join` message type and corresponding operation arranges for a direct connection to be formed Chris@50: # between the joiner and the host of the joined object, and this connection must be authenticated. Chris@50: # Thus, the details are network-dependent. Chris@50: Chris@50: using SturdyRef = AnyPointer; Chris@50: # **(level 2)** Chris@50: # Chris@50: # Identifies a persisted capability that can be restored in the future. How exactly a SturdyRef Chris@50: # is restored to a live object is specified along with the SturdyRef definition (i.e. not by Chris@50: # rpc.capnp). Chris@50: # Chris@50: # Generally a SturdyRef needs to specify three things: Chris@50: # - How to reach the vat that can restore the ref (e.g. a hostname or IP address). Chris@50: # - How to authenticate the vat after connecting (e.g. a public key fingerprint). Chris@50: # - The identity of a specific object hosted by the vat. Generally, this is an opaque pointer whose Chris@50: # format is defined by the specific vat -- the client has no need to inspect the object ID. Chris@50: # It is important that the objec ID be unguessable if the object is not public (and objects Chris@50: # should almost never be public). Chris@50: # Chris@50: # The above are only suggestions. Some networks might work differently. For example, a private Chris@50: # network might employ a special restorer service whose sole purpose is to restore SturdyRefs. Chris@50: # In this case, the entire contents of SturdyRef might be opaque, because they are intended only Chris@50: # to be forwarded to the restorer service. Chris@50: Chris@50: using ProvisionId = AnyPointer; Chris@50: # **(level 3)** Chris@50: # Chris@50: # The information that must be sent in an `Accept` message to identify the object being accepted. Chris@50: # Chris@50: # In a network where each vat has a public/private key pair, this could simply be the public key Chris@50: # fingerprint of the provider vat along with the question ID used in the `Provide` message sent from Chris@50: # that provider. Chris@50: Chris@50: using RecipientId = AnyPointer; Chris@50: # **(level 3)** Chris@50: # Chris@50: # The information that must be sent in a `Provide` message to identify the recipient of the Chris@50: # capability. Chris@50: # Chris@50: # In a network where each vat has a public/private key pair, this could simply be the public key Chris@50: # fingerprint of the recipient. (CapTP also calls for a nonce to identify the object. In our Chris@50: # case, the `Provide` message's `questionId` can serve as the nonce.) Chris@50: Chris@50: using ThirdPartyCapId = AnyPointer; Chris@50: # **(level 3)** Chris@50: # Chris@50: # The information needed to connect to a third party and accept a capability from it. Chris@50: # Chris@50: # In a network where each vat has a public/private key pair, this could be a combination of the Chris@50: # third party's public key fingerprint, hints on how to connect to the third party (e.g. an IP Chris@50: # address), and the question ID used in the corresponding `Provide` message sent to that third party Chris@50: # (used to identify which capability to pick up). Chris@50: Chris@50: using JoinKeyPart = AnyPointer; Chris@50: # **(level 4)** Chris@50: # Chris@50: # A piece of a secret key. One piece is sent along each path that is expected to lead to the same Chris@50: # place. Once the pieces are combined, a direct connection may be formed between the sender and Chris@50: # the receiver, bypassing any men-in-the-middle along the paths. See the `Join` message type. Chris@50: # Chris@50: # The motivation for Joins is discussed under "Supporting Equality" in the "Unibus" protocol Chris@50: # sketch: http://www.erights.org/elib/distrib/captp/unibus.html Chris@50: # Chris@50: # In a network where each vat has a public/private key pair and each vat forms no more than one Chris@50: # connection to each other vat, Joins will rarely -- perhaps never -- be needed, as objects never Chris@50: # need to be transparently proxied and references to the same object sent over the same connection Chris@50: # have the same export ID. Thus, a successful join requires only checking that the two objects Chris@50: # come from the same connection and have the same ID, and then completes immediately. Chris@50: # Chris@50: # However, in networks where two vats may form more than one connection between each other, or Chris@50: # where proxying of objects occurs, joins are necessary. Chris@50: # Chris@50: # Typically, each JoinKeyPart would include a fixed-length data value such that all value parts Chris@50: # XOR'd together forms a shared secret that can be used to form an encrypted connection between Chris@50: # the joiner and the joined object's host. Each JoinKeyPart should also include an indication of Chris@50: # how many parts to expect and a hash of the shared secret (used to match up parts). Chris@50: Chris@50: using JoinResult = AnyPointer; Chris@50: # **(level 4)** Chris@50: # Chris@50: # Information returned as the result to a `Join` message, needed by the joiner in order to form a Chris@50: # direct connection to a joined object. This might simply be the address of the joined object's Chris@50: # host vat, since the `JoinKey` has already been communicated so the two vats already have a shared Chris@50: # secret to use to authenticate each other. Chris@50: # Chris@50: # The `JoinResult` should also contain information that can be used to detect when the Join Chris@50: # requests ended up reaching different objects, so that this situation can be detected easily. Chris@50: # This could be a simple matter of including a sequence number -- if the joiner receives two Chris@50: # `JoinResult`s with sequence number 0, then they must have come from different objects and the Chris@50: # whole join is a failure. Chris@50: Chris@50: # ======================================================================================== Chris@50: # Network interface sketch Chris@50: # Chris@50: # The interfaces below are meant to be pseudo-code to illustrate how the details of a particular Chris@50: # vat network might be abstracted away. They are written like Cap'n Proto interfaces, but in Chris@50: # practice you'd probably define these interfaces manually in the target programming language. A Chris@50: # Cap'n Proto RPC implementation should be able to use these interfaces without knowing the Chris@50: # definitions of the various network-specific parameters defined above. Chris@50: Chris@50: # interface VatNetwork { Chris@50: # # Represents a vat network, with the ability to connect to particular vats and receive Chris@50: # # connections from vats. Chris@50: # # Chris@50: # # Note that methods returning a `Connection` may return a pre-existing `Connection`, and the Chris@50: # # caller is expected to find and share state with existing users of the connection. Chris@50: # Chris@50: # # Level 0 features ----------------------------------------------- Chris@50: # Chris@50: # connect(vatId :VatId) :Connection; Chris@50: # # Connect to the given vat. The transport should return a promise that does not Chris@50: # # resolve until authentication has completed, but allows messages to be pipelined in before Chris@50: # # that; the transport either queues these messages until authenticated, or sends them encrypted Chris@50: # # such that only the authentic vat would be able to decrypt them. The latter approach avoids a Chris@50: # # round trip for authentication. Chris@50: # Chris@50: # accept() :Connection; Chris@50: # # Wait for the next incoming connection and return it. Only connections formed by Chris@50: # # connect() are returned by this method. Chris@50: # Chris@50: # # Level 4 features ----------------------------------------------- Chris@50: # Chris@50: # newJoiner(count :UInt32) :NewJoinerResponse; Chris@50: # # Prepare a new Join operation, which will eventually lead to forming a new direct connection Chris@50: # # to the host of the joined capability. `count` is the number of capabilities to join. Chris@50: # Chris@50: # struct NewJoinerResponse { Chris@50: # joinKeyParts :List(JoinKeyPart); Chris@50: # # Key parts to send in Join messages to each capability. Chris@50: # Chris@50: # joiner :Joiner; Chris@50: # # Used to establish the final connection. Chris@50: # } Chris@50: # Chris@50: # interface Joiner { Chris@50: # addJoinResult(result :JoinResult) :Void; Chris@50: # # Add a JoinResult received in response to one of the `Join` messages. All `JoinResult`s Chris@50: # # returned from all paths must be added before trying to connect. Chris@50: # Chris@50: # connect() :ConnectionAndProvisionId; Chris@50: # # Try to form a connection to the joined capability's host, verifying that it has received Chris@50: # # all of the JoinKeyParts. Once the connection is formed, the caller should send an `Accept` Chris@50: # # message on it with the specified `ProvisionId` in order to receive the final capability. Chris@50: # } Chris@50: # Chris@50: # acceptConnectionFromJoiner(parts :List(JoinKeyPart), paths :List(VatPath)) Chris@50: # :ConnectionAndProvisionId; Chris@50: # # Called on a joined capability's host to receive the connection from the joiner, once all Chris@50: # # key parts have arrived. The caller should expect to receive an `Accept` message over the Chris@50: # # connection with the given ProvisionId. Chris@50: # } Chris@50: # Chris@50: # interface Connection { Chris@50: # # Level 0 features ----------------------------------------------- Chris@50: # Chris@50: # send(message :Message) :Void; Chris@50: # # Send the message. Returns successfully when the message (and all preceding messages) has Chris@50: # # been acknowledged by the recipient. Chris@50: # Chris@50: # receive() :Message; Chris@50: # # Receive the next message, and acknowledges receipt to the sender. Messages are received in Chris@50: # # the order in which they are sent. Chris@50: # Chris@50: # # Level 3 features ----------------------------------------------- Chris@50: # Chris@50: # introduceTo(recipient :Connection) :IntroductionInfo; Chris@50: # # Call before starting a three-way introduction, assuming a `Provide` message is to be sent on Chris@50: # # this connection and a `ThirdPartyCapId` is to be sent to `recipient`. Chris@50: # Chris@50: # struct IntroductionInfo { Chris@50: # sendToRecipient :ThirdPartyCapId; Chris@50: # sendToTarget :RecipientId; Chris@50: # } Chris@50: # Chris@50: # connectToIntroduced(capId :ThirdPartyCapId) :ConnectionAndProvisionId; Chris@50: # # Given a ThirdPartyCapId received over this connection, connect to the third party. The Chris@50: # # caller should then send an `Accept` message over the new connection. Chris@50: # Chris@50: # acceptIntroducedConnection(recipientId :RecipientId) :Connection; Chris@50: # # Given a RecipientId received in a `Provide` message on this `Connection`, wait for the Chris@50: # # recipient to connect, and return the connection formed. Usually, the first message received Chris@50: # # on the new connection will be an `Accept` message. Chris@50: # } Chris@50: # Chris@50: # struct ConnectionAndProvisionId { Chris@50: # # **(level 3)** Chris@50: # Chris@50: # connection :Connection; Chris@50: # # Connection on which to issue `Accept` message. Chris@50: # Chris@50: # provision :ProvisionId; Chris@50: # # `ProvisionId` to send in the `Accept` message. Chris@50: # }