Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file s.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313(** The core types and module signatures. *)type'abrand=..(** A way for objects to provide an optional private API to certain other modules.
For example, CapTP proxies appear as plain services, but use this to reveal their
target details to the CapTP layer so that it can shorten the path when sending
such capabilties over the network. *)typeattachments=..(** The capabilities attached to a message.
This is only defined as an open type to avoid a nasty recursive type definition. *)typeattachments+=No_attachmentsmoduletypeWIRE_PAYLOAD=sigtypet(** A message payload.
This is typically a byte array of some kind, plus a way of attaching capabilities. *)typepathvalpp:tFmt.tvalcap_index:t->path->intoption(** [cap_index msg path] is the capability index at [path] in the message
(i.e the index of the capability in the attachments table). *)valattachments:t->attachmentsvalwith_attachments:attachments->t->tendmoduletypeWIRE=sig(** The core RPC logic can be used with different serialisation systems.
The appropriate types should be provided here. *)typerequesttyperesponsetype'amsgmodulePath:sig(** A field in a message that refers to a capability. *)includeMap.OrderedTypevalroot:t(** The path for the bootstrap capability in the bootstrap message. *)valpp:tFmt.tendmoduleRequest:WIRE_PAYLOADwithtypet=requestmsgandtypepath:=Path.tmoduleResponse:sigincludeWIRE_PAYLOADwithtypet=responsemsgandtypepath:=Path.tvalbootstrap:unit->t(** The (empty) content for the reply to the bootstrap message. *)endvalref_leak_detected:int->(unit->unit)->unit(** [ref_leak_detected thread_id fn] is called when a promise or capability is GC'd while
its ref-count is non-zero, indicating that resources may have been leaked.
[fn ()] will log a warning about this and free the resources itself.
The reason for going via [ref_leak_detected] rather than calling [fn] directly
is because the OCaml GC may detect the problem at any point (e.g. while we're
sending another message). The implementation should arrange for [fn] to be
called at a safe point in thread [thread_id] (e.g. when returning to the
thread's main loop). Unit-tests may wish to call [fn] immediately to show
the error and then fail the test. *)endmoduletypePAYLOAD=sig(** Wraps {!WIRE_PAYLOAD} to deal with caps rather than attachments. *)typettypecaptypepathvalsnapshot_caps:t->capRO_array.tvalfield:t->path->capoption(** [field t path] looks up [path] in the message and returns the capability at that index.
Returns [None] if the field wasn't set. Returns a broken capability if an index was
given but does not exist (i.e. the message is corrupted). Increases the ref-count on the result. *)valwith_caps:capRO_array.t->t->t(** [with_caps caps t] is a copy of [t] with a new set of capabilities.
This is useful to implement [TakeFromOtherQuestion], where the message is the same but
embargoes may be needed, and to break cycles. *)valrelease:t->unit(** [release t] frees all the capabilities attached to this message.
It is safe to call this multiple times; only the first call has any effect. *)valpp:tFmt.tendmoduletypeCORE_TYPES=sig(** This module defines a calling convention for invoking methods on objects.
The objects could be remote, but this module doesn't define anything related
to networks.
These types are generated automatically from [WIRE] by [Core_types]. *)moduleWire:WIREtype'aor_error=('a,Error.t)resultclasstypebase_ref=objectmethodpp:Format.formatter->unitmethodupdate_rc:int->unit(** [c#update_rc d] adds [d] to [c]'s (local) reference count.
When it reaches zero, [c] must not be used again. A message may be
sent releasing any remote resources. *)methodblocker:base_refoption(** [c#blocker] is the unresolved [cap] or [struct_ref] promise that must resolve for [c] to resolve.
This is used to help detect cycles. *)methodcheck_invariants:unit(** This is for debugging. Checks its own invariants and those of other base_refs it holds.
Raises [Invariant_broken] if there is a problem. *)methodsealed_dispatch:'a.'abrand->'aoption(** [c#sealed_dispatch brand] extracts some private data of the given type. *)end(** Common methods for [struct_ref] and [cap]. *)valpp:#base_refFmt.tvalinc_ref:#base_ref->unit(** [inc_ref x] increases [x]'s ref-count by one. *)valdec_ref:#base_ref->unit(** [dec_ref x] decreases [x]'s ref-count by one. *)classtypestruct_ref=objectinheritbase_refmethodwhen_resolved:(Wire.Response.tor_error->unit)->unit(** [r#when_resolved fn] queues up [fn] to be called on the result, when it arrives.
If the result has already arrived, [fn] is called immediately. *)methodresponse:Wire.Response.tor_erroroption(** [r#response] is [Some payload] if the response has arrived,
or [None] if we're still waiting. *)methodcap:Wire.Path.t->cap(** [r#cap path] is the capability found at [path] in the response.
If the response has arrived, this will extract the capability from it.
If not, it may create a capability that will pipeline through the promised
answer until the result arrives (at which point it will use the new, more
direct route). The caller should call [cap#dec_ref] when done. *)end(** The result of a call, which may not have arrived yet.
It can be used to pipeline calls to capabilities that we hope will
be returned in the results. *)andcap=objectinheritbase_refmethodcall:struct_resolver->Wire.Request.t->unit(* Takes ownership of [caps] *)(** [c#call results msg] invokes a method on [c]'s target and eventually resolves [results]
with the answer. *)methodshortest:cap(** [c#shortest] is the shortest known path to [cap]. i.e. if [c] is forwarding to another cap, we
return that, recursively. *)methodwhen_more_resolved:(cap->unit)->unit(** [c#when_more_resolved fn] calls [fn x] when this cap becomes more resolved.
[fn x] gets a reference to [x] and needs to [dec_ref] it.
Note that the new capability can be another promise.
If [c] is already resolved to its final value, this does nothing.
If [c] is a far-ref, [fn x] will be called when it breaks.
If [c] is forwarding to another cap, it will forward this call.
If [c] gets released before calling [fn], it will never call it. *)methodwhen_released:(unit->unit)->unit(** [c#when_released fn] will call [fn ()] when [c]'s ref-count drops to zero.
This is used for caches, to remove entries when they become invalid.
For promises, [fn] will be transferred to the resolution if resolved.
For broken caps, this method does nothing (exceptions are never released). *)methodproblem:Exception.toption(** [c#problem] is the exception for a broken reference, or [None] if it is not known to be broken. *)end(** A capability reference to an object that can handle calls.
We might not yet know its final location, but we may be able
to pipeline messages to it anyway. *)andstruct_resolver=objectmethodpp:Format.formatter->unitmethodresolve:struct_ref->unit(** [r#resolve x] causes [r]'s promise to behave as [x] in future.
The promise takes ownership of [x] (is responsible for calling [dec_rec] on it). *)methodsealed_dispatch:'a.'abrand->'aoption(** [r#sealed_dispatch brand] extracts some private data of the given type. *)methodset_blocker:base_ref->(unit,[>`Cycle])result(** [r#set_blocker b] means that [resolve] won't be called until [b] is resolved.
[r]'s promise should report this as its blocker. This is needed to detect cycles.
When the blocker is resolved, call this again with [None] to clear it (the promise
will then report itself as the blocker again, until resolved). *)methodclear_blocker:unit(** [r#clear_blocker] removes the blocker set by [set_blocker].
[r] is then blocked by itself, if unresolved. *)end(** A [struct_resolver] can be used to resolve some promise. *)moduleAttachments:sigvalbuilder:unit->attachments(** [builder ()] is a fresh writable attachments array. *)valcap:int->attachments->cap(** [cap i t] is the capability at index [i] in [t]. The reference count is increased by one. *)valclear_cap:attachments->int->unit(** Replace cap at index [i] with [null] and dec_ref it. *)valadd_cap:attachments->cap->int(** [add_cap t cap] stores [cap] in [t]. [t] must have been created by [builder].
Increases the ref-count on [cap] by one. *)valrelease_caps:attachments->unit(** [release_caps a] decreases the ref-count of every capability in [a]. *)endmoduleRequest_payload:PAYLOADwithtypet=Wire.Request.tandtypecap:=capandtypepath:=Wire.Path.t(** The payload of a request message. *)moduleResponse_payload:PAYLOADwithtypet=Wire.Response.tandtypecap:=capandtypepath:=Wire.Path.t(** The payload of a response message. *)classvirtualref_counted:objectmethodprivatevirtualrelease:unitmethodvirtualpp:Format.formatter->unitmethodprivatepp_refcount:Format.formatter->unit(** Write the current ref-count to the formatter (use with ["%t"]). *)methodprivatecheck_refcount:unit(** Raise an exception if the ref-count is less than one
(i.e. check that the object hasn't already been freed). *)methodupdate_rc:int->unitmethodcheck_invariants:unitmethodvirtualblocker:base_refoptionmethodsealed_dispatch:'a.'abrand->'aoptionend(** A mix-in to help with writing reference-counted objects.
It will call [self#release] when the ref-count reaches zero. *)classvirtualservice:objectinheritbase_refinheritref_countedmethodvirtualcall:struct_resolver->Wire.Request.t->unit(* Takes ownership of message. *)methodshortest:capmethodprivaterelease:unitmethodwhen_more_resolved:(cap->unit)->unitmethodwhen_released:(unit->unit)->unitmethodproblem:Exception.toptionend(** A convenience base class for creating local services.
The capability is always resolved, and the default [release] method does nothing. *)valnull:cap(** A (broken) capability representing a missing pointer.
Any attempt to call it will return an error. *)valreturn:Response_payload.t->struct_ref(** [return x] is a resolved [struct_ref] with successful resolution [x]. *)valfail:?ty:Exception.ty->('a,Format.formatter,unit,struct_ref)format4->'a(** [fail fmt] is a [struct_ref] that is broken with the given capnp exception message. *)valbroken_cap:Exception.t->cap(** [broken_cap ex] is a [cap] that is broken with the given exception. *)valbroken_struct:Error.t->struct_ref(** [broken_struct err] is a [struct_ref] that is broken with the given error. *)valresolved:Response_payload.tor_error->struct_ref(** [resolved x] is a resolved [struct_ref] with resolution [x]. *)valresolve_payload:#struct_resolver->Response_payload.tor_error->unit(** [resolve_payload r x] is [r#resolve (resolved x)]. [r] takes ownership of [x]. *)valresolve_ok:#struct_resolver->Wire.Response.t->unit(** [resolve_ok r msg] is [resolve_payload r (Ok msg)].
[r] takes ownership of [msg]. *)valresolve_exn:#struct_resolver->Exception.t->unit(** [resolve_exn r exn] is [resolve_payload r (Error (`Exception exn))]. *)valwhen_broken:(Exception.t->unit)->cap->unit(** [when_broken fn x] calls [fn problem] when [x] becomes broken.
If [x] is already broken, [fn] is called immediately.
If [x] can never become broken (e.g. it is a near ref), this does nothing. *)endmoduletypeNETWORK_TYPES=sig(* These depend on the particular network details. *)typeprovision_idtyperecipient_idtypethird_party_cap_idtypejoin_key_partend