Skip to content

Commit

Permalink
Merge pull request #288 from talex5/asetmap
Browse files Browse the repository at this point in the history
Remove asetmap dependency
  • Loading branch information
talex5 authored Nov 18, 2024
2 parents c95f619 + 874e45e commit 7f87763
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 29 deletions.
1 change: 0 additions & 1 deletion capnp-rpc-net.opam
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ depends: [
"astring"
"fmt" {>= "0.8.7"}
"logs"
"asetmap"
"cstruct" {>= "6.0.0"}
"tls-eio" {>= "1.0.2"}
"base64" {>= "3.0.0"}
Expand Down
2 changes: 0 additions & 2 deletions capnp-rpc-net/auth.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open Asetmap

module Log = Capnp_rpc.Debug.Log

let default_rsa_key_bits = 2048
Expand Down
2 changes: 0 additions & 2 deletions capnp-rpc-net/auth.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open Asetmap

(** Vat-level authentication and encryption.
Unless your network provides a secure mechanism for establishing connections
Expand Down
15 changes: 9 additions & 6 deletions capnp-rpc-net/vat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module Make (Network : S.NETWORK) = struct
run_connection_generic t endpoint
~add:(fun conn -> t.connections <- ID_map.add peer_id conn t.connections; r conn)
~remove:(fun conn ->
match ID_map.find peer_id t.connections with
match ID_map.find_opt peer_id t.connections with
| Some x when x == conn -> t.connections <- ID_map.remove peer_id t.connections
| Some _ (* Already replaced by a new one? *)
| None -> ()
Expand All @@ -72,7 +72,7 @@ module Make (Network : S.NETWORK) = struct
run_connection_generic t endpoint
~add:(fun conn -> t.anon_connections <- conn :: t.anon_connections; r conn)
~remove:(fun conn -> t.anon_connections <- List.filter ((!=) conn) t.anon_connections)
) else match ID_map.find peer_id t.connections with
) else match ID_map.find_opt peer_id t.connections with
| None -> run_connection_tls t endpoint r
| Some existing ->
Log.info (fun f -> f ~tags:t.tags "Trying to add a connection, but we already have one for this vat");
Expand Down Expand Up @@ -163,15 +163,15 @@ module Make (Network : S.NETWORK) = struct
let my_id = Auth.Secret_key.digest ~hash (Lazy.force t.secret_key) in
if Auth.Digest.equal remote_id my_id then
Restorer.restore t.restore service
else match ID_map.find remote_id t.connections with
else match ID_map.find_opt remote_id t.connections with
| Some conn when CapTP.disconnecting conn ->
Eio.Condition.await_no_mutex t.connection_removed;
connect t (addr, service)
| Some conn ->
(* Already connected; use that. *)
Ok (CapTP.bootstrap conn service)
| None ->
match ID_map.find remote_id t.connecting with
match ID_map.find_opt remote_id t.connecting with
| None -> initiate_connection t addr service
| Some conn ->
(* We're already trying to establish a connection, wait for that. *)
Expand Down Expand Up @@ -218,10 +218,13 @@ module Make (Network : S.NETWORK) = struct
Auth.Digest.pp id
CapTP.dump conn

let dump_id_map pp f m =
Fmt.pf f "{@[<v0>%a@]}" (Fmt.seq pp) (ID_map.to_seq m)

let dump f t =
Fmt.pf f "@[<v2>%a@,Connecting: %a@,Connected: %a@,Anonymous: %a@]"
pp_vat_id t.address
(ID_map.dump dump_connecting) t.connecting
(ID_map.dump dump_id_conn) t.connections
(dump_id_map dump_connecting) t.connecting
(dump_id_map dump_id_conn) t.connections
(Fmt.Dump.list CapTP.dump) t.anon_connections
end
1 change: 0 additions & 1 deletion capnp-rpc-unix.opam
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ depends: [
"alcotest" {>= "1.6.0" & with-test}
"mirage-crypto-rng-eio" {>= "1.1.0" & with-test}
"mdx" {>= "2.4.1" & with-test}
"asetmap" {with-test}
"eio_main" {with-test}
"eio" {>= "1.1"}
]
Expand Down
1 change: 0 additions & 1 deletion capnp-rpc.opam
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ depends: [
"astring"
"fmt" {>= "0.8.7"}
"logs"
"asetmap"
"uri" {>= "1.6.0"}
"dune" {>= "3.16"}
"alcotest" {>= "1.6.0" & with-test}
Expand Down
6 changes: 2 additions & 4 deletions capnp-rpc/proto/capTP.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open Asetmap

module Log = Debug.Log
module IntMap = Map.Make(struct type t = int let compare (a:int) b = compare a b end)

Expand Down Expand Up @@ -1504,7 +1502,7 @@ module Make (EP : Message_types.ENDPOINT) = struct
let caps_used = Question.paths_used question |> caps_used ~msg in
let import_with_embargoes cap_index d =
let embargo_path =
match IntMap.find cap_index caps_used with
match IntMap.find_opt cap_index caps_used with
| None -> None
| Some path -> Some (Question.message_target question path)
in
Expand Down Expand Up @@ -1581,7 +1579,7 @@ module Make (EP : Message_types.ENDPOINT) = struct
let embargoes_needed = caps_used ~msg paths_used in
let maybe_embargo cap_index cap =
inc_ref cap;
match IntMap.find cap_index embargoes_needed with
match IntMap.find_opt cap_index embargoes_needed with
| None -> cap
| Some path ->
let old_path = Question.message_target question path in
Expand Down
2 changes: 1 addition & 1 deletion capnp-rpc/proto/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(library
(name capnp_rpc_proto)
(public_name capnp-rpc.proto)
(libraries astring fmt logs stdint asetmap threads))
(libraries astring fmt logs stdint threads))
14 changes: 5 additions & 9 deletions capnp-rpc/proto/struct_proxy.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open Asetmap

module Log = Debug.Log

module Make (C : S.CORE_TYPES) = struct
Expand Down Expand Up @@ -73,8 +71,6 @@ module Make (C : S.CORE_TYPES) = struct
| Forwarding of struct_ref
| Finished

let pp_fields = Field_map.dump (fun f (k, v) -> Fmt.pf f "%a:%a" Wire.Path.pp k RC.pp v.ref_count)

let pp_opt_blocked_on f = function
| None -> ()
| Some b -> Fmt.pf f " (blocked on %t)" b#pp
Expand Down Expand Up @@ -239,7 +235,7 @@ module Make (C : S.CORE_TYPES) = struct
dispatch state
~unresolved:(fun u ->
let field =
match Field_map.find path u.fields with
match Field_map.find_opt path u.fields with
| Some f -> f
| None ->
let cap = field path (self :> struct_ref_internal) in
Expand Down Expand Up @@ -393,7 +389,7 @@ module Make (C : S.CORE_TYPES) = struct
~unresolved:(fun u ->
(* When we resolve, we'll be holding references to all the caps in the resolution, so
so they must still be alive by the time we pass on any extra inc or dec refs. *)
let f = Field_map.get path u.fields in
let f = Field_map.find path u.fields in
assert (f.ref_count > RC.one); (* rc can't be one because that's our reference *)
let pp = self#field_pp path in
f.ref_count <- RC.sum f.ref_count d ~pp
Expand All @@ -406,7 +402,7 @@ module Make (C : S.CORE_TYPES) = struct
method field_dec_ref path =
dispatch state
~unresolved:(fun u ->
let f = Field_map.get path u.fields in
let f = Field_map.find path u.fields in
assert (f.ref_count > RC.one); (* rc can't be one because that's our reference *)
let pp = self#field_pp path in
f.ref_count <- RC.pred f.ref_count ~pp
Expand All @@ -424,7 +420,7 @@ module Make (C : S.CORE_TYPES) = struct
method field_check_invariants i =
dispatch state
~unresolved:(fun u ->
let f = Field_map.get i u.fields in
let f = Field_map.find i u.fields in
assert (f.ref_count > RC.one);
self#check_invariants
)
Expand All @@ -435,7 +431,7 @@ module Make (C : S.CORE_TYPES) = struct
| Finished -> Fmt.pf f "Promise is finished, but field %a isn't!" Wire.Path.pp path
| Forwarding _ -> Fmt.pf f "Promise is resolved, but field %a isn't!" Wire.Path.pp path
| Unresolved u ->
let field = Field_map.get path u.fields in
let field = Field_map.find path u.fields in
match RC.to_int field.ref_count with
| None ->
Fmt.pf f "(rc=LEAKED) -> #%a -> %t" Wire.Path.pp path self#pp
Expand Down
1 change: 0 additions & 1 deletion fuzz/fuzz.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
open Asetmap
module RO_array = Capnp_rpc_proto.RO_array
module Test_utils = Testbed.Test_utils
module OID = Capnp_rpc_proto.Debug.OID
Expand Down
2 changes: 1 addition & 1 deletion test/proto/testbed/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(library
(name testbed)
(libraries astring fmt logs logs.fmt capnp-rpc.proto alcotest asetmap))
(libraries astring fmt logs logs.fmt capnp-rpc.proto alcotest))

0 comments on commit 7f87763

Please sign in to comment.