From 5beb62c83e6cfdd7b6df349b938f94386c133a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Sat, 11 Nov 2017 03:34:12 +0100 Subject: [PATCH] P2p: more debug in `P2p_connection`. --- src/node/net/p2p_connection.ml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/node/net/p2p_connection.ml b/src/node/net/p2p_connection.ml index 6d9c64ee3..b1ea6ab81 100644 --- a/src/node/net/p2p_connection.ml +++ b/src/node/net/p2p_connection.ml @@ -489,19 +489,32 @@ let catch_closed_pipe f = | exn -> fail (Exn exn) end -let write { writer } msg = +let pp_json encoding ppf msg = + Format.pp_print_string ppf + (Data_encoding_ezjsonm.to_string + (Data_encoding.Json.construct encoding msg)) + +let write { writer ; conn } msg = catch_closed_pipe begin fun () -> + debug "Sending message to %a: %a" + P2p_types.Peer_id.pp_short conn.info.peer_id (pp_json writer.encoding) msg ; Lwt.return (Writer.encode_message writer msg) >>=? fun buf -> Lwt_pipe.push writer.messages (buf, None) >>= return end -let write_sync { writer } msg = + +let write_sync { writer ; conn } msg = catch_closed_pipe begin fun () -> let waiter, wakener = Lwt.wait () in + debug "Sending message to %a: %a" + P2p_types.Peer_id.pp_short conn.info.peer_id (pp_json writer.encoding) msg ; Lwt.return (Writer.encode_message writer msg) >>=? fun buf -> Lwt_pipe.push writer.messages (buf, Some wakener) >>= fun () -> waiter end -let write_now { writer } msg = + +let write_now { writer ; conn } msg = + debug "Try sending message to %a: %a" + P2p_types.Peer_id.pp_short conn.info.peer_id (pp_json writer.encoding) msg ; Writer.encode_message writer msg >>? fun buf -> try Ok (Lwt_pipe.push_now writer.messages (buf, None)) with Lwt_pipe.Closed -> Error [P2p_io_scheduler.Connection_closed]