aboutsummaryrefslogtreecommitdiffstats
path: root/lib/protocols/Session.ml
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-09-26 22:29:45 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2026-09-26 22:29:45 -0300
commit63352e46a880985efbdfab2e539d0f4975960b94 (patch)
treec85a0c47d425d371773d7a66896e41099d2dc9ef /lib/protocols/Session.ml
parent504e2d03a10f1641b36a9d5f127a18bc943562ce (diff)
downloadRNT-63352e46a880985efbdfab2e539d0f4975960b94.tar.gz
RNT-63352e46a880985efbdfab2e539d0f4975960b94.zip
add session object and protocol with pinning
Diffstat (limited to 'lib/protocols/Session.ml')
-rw-r--r--lib/protocols/Session.ml23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/protocols/Session.ml b/lib/protocols/Session.ml
new file mode 100644
index 0000000..f740c1a
--- /dev/null
+++ b/lib/protocols/Session.ml
@@ -0,0 +1,23 @@
+module Error = struct
+ open Concepts.Condition
+
+ let not_a_session () =
+ condition "not-a-session" "A handle was expected to carry the session protocol and did not"
+ empty
+end
+
+type state = {branch: string; snapshot: Concepts.Hash.hash}
+
+class type implementation = object
+ method state : state
+ method pin : state -> unit
+end
+
+type Handle.protocol += Session of implementation
+type t = implementation
+
+let make impl = Session (impl :> implementation)
+let from handle = Handle.into handle (function Session impl -> Some impl | _ -> None)
+let require handle = from handle |> Option.to_result ~none:(Error.not_a_session ())
+let state i = Handle.invoke i (fun o -> o#state)
+let pin i state = Handle.invoke i (fun o -> o#pin state)