Skip to content

Commit

Permalink
Merge pull request #313 from talex5/update-crypto
Browse files Browse the repository at this point in the history
Update to new mirage-crypto API
  • Loading branch information
talex5 authored Feb 3, 2025
2 parents a9b4e9b + 33b9154 commit 21bd28b
Show file tree
Hide file tree
Showing 27 changed files with 19 additions and 37 deletions.
2 changes: 0 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ It is recommended to upgrade in stages, checking your application still works af
Calls to functions in the `Capnp_rpc_unix` and `Capnp_rpc_net` modules will need minor updates.
They were previously called from Lwt context, so you'll need to wrap them with `Lwt_eio.run_eio`
(or remove a `Lwt_eio.run_lwt` if you already updated the surrounding code).
You should also use `mirage-crypto-rng-eio` to ensure randomness is available
(`capnp-rpc-unix` no longer does this, although some other library might).

4. Upgrade code and libraries using `Capnp_rpc_lwt`:

Expand Down
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,6 @@ let start_server ~sw ~delay net =
let () =
Eio_main.run @@ fun env ->
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env @@ fun () ->
Switch.run @@ fun sw ->
let delay = Eio.Time.Timeout.seconds env#mono_clock delay in
let uri = start_server ~sw ~delay env#net in
Expand All @@ -476,12 +475,11 @@ let () =
<img src="./diagrams/vats.svg"/>
</p>
You'll need to edit your `dune` file to add dependencies
on `capnp-rpc-unix` and `mirage-crypto-rng-eio` in the `(libraries ...` line and also:
You'll need to edit your `dune` file to add a dependency on `capnp-rpc-unix` in the `(libraries ...)` line and also:
<!-- $MDX skip -->
```sh
$ opam install capnp-rpc-unix mirage-crypto-rng-eio
$ opam install capnp-rpc-unix
```
Running this will give something like:
Expand Down Expand Up @@ -569,7 +567,7 @@ Edit the `dune` file to build a client and server:
```
(executables
(names client server)
(libraries eio_main capnp-rpc logs.fmt capnp-rpc-unix mirage-crypto-rng-eio))
(libraries eio_main capnp-rpc logs.fmt capnp-rpc-unix))
(rule
(targets echo_api.ml echo_api.mli)
Expand Down Expand Up @@ -615,7 +613,6 @@ let serve_cmd env =
let () =
exit @@ Eio_main.run @@ fun env ->
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env @@ fun () ->
Cmd.eval (serve_cmd env)
```
Expand Down Expand Up @@ -661,7 +658,6 @@ let connect_cmd env =
let () =
exit @@ Eio_main.run @@ fun env ->
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env @@ fun () ->
Cmd.eval (connect_cmd env)
```
Expand Down Expand Up @@ -866,7 +862,6 @@ let run_client ~net cap_file msg =
let () =
Eio_main.run @@ fun env ->
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env @@ fun () ->
Switch.run @@ fun sw ->
let net = env#net in
start_server ~sw net;
Expand Down Expand Up @@ -910,7 +905,6 @@ We can use the new API like this:
```ocaml
let () =
Eio_main.run @@ fun env ->
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env @@ fun () ->
Switch.run @@ fun sw ->
let net = env#net in
let root_uri = start_server ~sw net in
Expand Down
4 changes: 2 additions & 2 deletions capnp-rpc-net.opam
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ depends: [
"asn1-combinators" {>= "0.2.0"}
"x509" {>= "1.0.3"}
"dune" {>= "3.16"}
"mirage-crypto" {>= "1.1.0"}
"mirage-crypto-rng" {>= "1.1.0"}
"mirage-crypto" {>= "1.2.0"}
"mirage-crypto-rng" {>= "1.2.0"}
]
build: [
["dune" "build" "-p" name "-j" jobs]
Expand Down
2 changes: 1 addition & 1 deletion capnp-rpc-unix.opam
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ depends: [
"dune" {>= "3.16"}
"ipaddr" {>= "5.3.0" }
"alcotest" {>= "1.6.0" & with-test}
"mirage-crypto-rng-eio" {>= "1.1.0" & with-test}
"mirage-crypto-rng" {>= "1.2.0"}
"mdx" {>= "2.4.1" & with-test}
"eio_main" {with-test}
"eio" {>= "1.2"}
Expand Down
2 changes: 1 addition & 1 deletion examples/pipelining/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(executable
(name main)
(libraries eio_main capnp-rpc-unix mirage-crypto-rng-eio logs.fmt))
(libraries eio_main capnp-rpc-unix logs.fmt))

(rule
(targets echo_api.ml echo_api.mli)
Expand Down
1 change: 0 additions & 1 deletion examples/pipelining/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ let start_server ~sw ~delay net =

let () =
Eio_main.run @@ fun env ->
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env @@ fun () ->
Switch.run @@ fun sw ->
let delay = Eio.Time.Timeout.seconds env#mono_clock delay in
let uri = start_server ~sw ~delay env#net in
Expand Down
2 changes: 1 addition & 1 deletion examples/sturdy-refs-2/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(executable
(name main)
(libraries eio_main capnp-rpc-unix mirage-crypto-rng-eio logs.fmt))
(libraries eio_main capnp-rpc-unix logs.fmt))

(rule
(targets api.ml api.mli)
Expand Down
1 change: 0 additions & 1 deletion examples/sturdy-refs-2/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ let start_server ~sw net =
(* $MDX part-begin=main *)
let () =
Eio_main.run @@ fun env ->
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env @@ fun () ->
Switch.run @@ fun sw ->
let net = env#net in
let root_uri = start_server ~sw net in
Expand Down
2 changes: 1 addition & 1 deletion examples/sturdy-refs-3/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(executable
(name main)
(libraries eio_main capnp-rpc-unix mirage-crypto-rng-eio logs.fmt))
(libraries eio_main capnp-rpc-unix logs.fmt))

(rule
(targets api.ml api.mli)
Expand Down
1 change: 0 additions & 1 deletion examples/sturdy-refs-3/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ let run_client ~net cap_file =

let () =
Eio_main.run @@ fun env ->
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env @@ fun () ->
Switch.run @@ fun sw ->
let net = env#net in
let root_uri = start_server ~sw net in
Expand Down
2 changes: 1 addition & 1 deletion examples/sturdy-refs-4/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(executable
(name main)
(libraries eio_main capnp-rpc-unix mirage-crypto-rng-eio logs.fmt cmdliner))
(libraries eio_main capnp-rpc-unix logs.fmt cmdliner))

(rule
(targets api.ml api.mli)
Expand Down
1 change: 0 additions & 1 deletion examples/sturdy-refs-4/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,4 @@ let () =
let doc = "a command-line interface for logger service" in
let info = Cmd.info ~doc "logger-client" in
exit @@ Eio_main.run @@ fun env ->
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env @@ fun () ->
Cmd.eval @@ Cmd.group info (cmds env)
2 changes: 1 addition & 1 deletion examples/sturdy-refs/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(executable
(name main)
(libraries eio_main capnp-rpc-unix mirage-crypto-rng-eio logs.fmt))
(libraries eio_main capnp-rpc-unix logs.fmt))

(rule
(targets api.ml api.mli)
Expand Down
1 change: 0 additions & 1 deletion examples/sturdy-refs/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ let run_client ~net cap_file msg =

let () =
Eio_main.run @@ fun env ->
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env @@ fun () ->
Switch.run @@ fun sw ->
let net = env#net in
start_server ~sw net;
Expand Down
2 changes: 1 addition & 1 deletion examples/v3/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(executable
(name main)
(libraries eio_main capnp-rpc-unix mirage-crypto-rng-eio logs.fmt))
(libraries eio_main capnp-rpc-unix logs.fmt))

(rule
(targets echo_api.ml echo_api.mli)
Expand Down
1 change: 0 additions & 1 deletion examples/v3/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ let start_server ~sw ~delay net =

let () =
Eio_main.run @@ fun env ->
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env @@ fun () ->
Switch.run @@ fun sw ->
let delay = Eio.Time.Timeout.seconds env#mono_clock delay in
let uri = start_server ~sw ~delay env#net in
Expand Down
1 change: 0 additions & 1 deletion examples/v4/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ let connect_cmd env =

let () =
exit @@ Eio_main.run @@ fun env ->
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env @@ fun () ->
Cmd.eval (connect_cmd env)
2 changes: 1 addition & 1 deletion examples/v4/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(executables
(names client server)
(libraries eio_main capnp-rpc logs.fmt capnp-rpc-unix mirage-crypto-rng-eio))
(libraries eio_main capnp-rpc logs.fmt capnp-rpc-unix))

(rule
(targets echo_api.ml echo_api.mli)
Expand Down
1 change: 0 additions & 1 deletion examples/v4/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ let serve_cmd env =

let () =
exit @@ Eio_main.run @@ fun env ->
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env @@ fun () ->
Cmd.eval (serve_cmd env)
1 change: 0 additions & 1 deletion test-bin/calc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ let cmds env = [serve_cmd env; connect_cmd env]

let () =
Eio_main.run @@ fun env ->
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env @@ fun () ->
Fmt_tty.setup_std_outputs ();
Logs.set_reporter reporter;
Logs.set_level ~all:true (Some Logs.Info);
Expand Down
3 changes: 1 addition & 2 deletions test-bin/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
(executables
(names calc calc_direct)
(libraries testlib cmdliner astring logs.fmt fmt.tty capnp-rpc-unix eio_main
mirage-crypto-rng-eio))
(libraries testlib cmdliner astring logs.fmt fmt.tty capnp-rpc-unix eio_main))
2 changes: 1 addition & 1 deletion test-bin/echo/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(executable
(name echo_bench)
(libraries eio_main capnp-rpc capnp-rpc-net capnp-rpc-unix mirage-crypto-rng-eio logs.fmt))
(libraries eio_main capnp-rpc capnp-rpc-net capnp-rpc-unix logs.fmt))

(rule
(targets echo_api.ml echo_api.mli)
Expand Down
1 change: 0 additions & 1 deletion test-bin/echo/echo_bench.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ let start_server ~sw net =

let () =
Eio_main.run @@ fun env ->
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env @@ fun () ->
Switch.run ~name:"main" @@ fun sw ->
let uri = start_server ~sw env#net in
Fmt.pr "Connecting to echo service at: %a@." Uri.pp_hum uri;
Expand Down
2 changes: 1 addition & 1 deletion test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
(package capnp-rpc-unix)
(name test)
(libraries capnp-rpc capnp-rpc-unix testlib logs.fmt
mirage-crypto-rng-eio testbed eio_main eio.mock))
testbed eio_main eio.mock))
1 change: 0 additions & 1 deletion test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,6 @@ let rpc_tests ~net ~dir =

let () =
Eio_main.run @@ fun env ->
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env @@ fun () ->
(* Eio_unix.Ctf.with_tracing "/tmp/trace.ctf" @@ fun () -> *)
Alcotest.run ~and_exit:false "capnp-rpc" [
"eio", rpc_tests ~net:env#net ~dir:env#cwd;
Expand Down
2 changes: 2 additions & 0 deletions unix/capnp_rpc_unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ open Eio.Std

module Log = Capnp_rpc.Debug.Log

let () = Mirage_crypto_rng_unix.use_default ()

module CapTP = Vat_network.CapTP
module Vat = Vat_network.Vat
module Network = Network
Expand Down
2 changes: 1 addition & 1 deletion unix/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(library
(name capnp_rpc_unix)
(public_name capnp-rpc-unix)
(libraries eio.unix astring capnp-rpc capnp-rpc-net fmt logs cmdliner cstruct extunix))
(libraries eio.unix astring capnp-rpc capnp-rpc-net fmt logs mirage-crypto-rng.unix cmdliner cstruct extunix))

0 comments on commit 21bd28b

Please sign in to comment.