From 7a43c5bc4110ad2a1948624c3b3135996053a3ce Mon Sep 17 00:00:00 2001 From: Milo Davis Date: Tue, 27 Mar 2018 18:04:51 -0400 Subject: [PATCH] P2p_pool: fix ambiguous JSON union case --- src/lib_p2p/p2p_pool.ml | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/lib_p2p/p2p_pool.ml b/src/lib_p2p/p2p_pool.ml index 605d26316..66e614f92 100644 --- a/src/lib_p2p/p2p_pool.ml +++ b/src/lib_p2p/p2p_pool.ml @@ -39,32 +39,43 @@ module Message = struct let open Data_encoding in dynamic_size @@ union ~tag_size:`Uint16 - ([ case (Tag 0x01) ~name:"Disconnect" null + ([ case (Tag 0x01) ~name:"Disconnect" + (obj1 (req "kind" (constant "Disconnect"))) (function Disconnect -> Some () | _ -> None) (fun () -> Disconnect); - case (Tag 0x02) ~name:"Bootstrap" null + case (Tag 0x02) ~name:"Bootstrap" + (obj1 (req "kind" (constant "Bootstrap"))) (function Bootstrap -> Some () | _ -> None) (fun () -> Bootstrap); - case (Tag 0x03) ~name:"Advertise" (Variable.list P2p_point.Id.encoding) - (function Advertise points -> Some points | _ -> None) - (fun points -> Advertise points); + case (Tag 0x03) ~name:"Advertise" + (obj2 + (req "id" (Variable.list P2p_point.Id.encoding)) + (req "kind" (constant "Advertise"))) + (function Advertise points -> Some (points, ()) | _ -> None) + (fun (points, ()) -> Advertise points); case (Tag 0x04) ~name:"Swap_request" - (tup2 P2p_point.Id.encoding P2p_peer.Id.encoding) + (obj3 + (req "point" P2p_point.Id.encoding) + (req "peer_id" P2p_peer.Id.encoding) + (req "kind" (constant "Swap_request"))) (function - | Swap_request (point, peer_id) -> Some (point, peer_id) + | Swap_request (point, peer_id) -> Some (point, peer_id, ()) | _ -> None) - (fun (point, peer_id) -> Swap_request (point, peer_id)) ; + (fun (point, peer_id, ()) -> Swap_request (point, peer_id)) ; case (Tag 0x05) ~name:"Swap_ack" - (tup2 P2p_point.Id.encoding P2p_peer.Id.encoding) + (obj3 + (req "point" P2p_point.Id.encoding) + (req "peer_id" P2p_peer.Id.encoding) + (req "kind" (constant "Swap_ack"))) (function - | Swap_ack (point, peer_id) -> Some (point, peer_id) + | Swap_ack (point, peer_id) -> Some (point, peer_id, ()) | _ -> None) - (fun (point, peer_id) -> Swap_ack (point, peer_id)) ; + (fun (point, peer_id, ()) -> Swap_ack (point, peer_id)) ; ] @ ListLabels.map msg_encoding ~f:(function Encoding { tag ; encoding ; wrap ; unwrap } -> - case (Tag tag) encoding + Data_encoding.case (Tag tag) encoding (function Message msg -> unwrap msg | _ -> None) (fun msg -> Message (wrap msg))))