From 224e5d8c7359fb9072b71da12986d8cd06cf8b17 Mon Sep 17 00:00:00 2001 From: Vincent Bernardoff Date: Thu, 1 Dec 2016 17:11:27 +0100 Subject: [PATCH] P2P: Add counters in peer_info --- src/node/net/p2p.ml | 22 +++++++++++++++------- src/node/net/p2p.mli | 4 ++++ src/node/shell/tezos_p2p.mli | 4 ++++ test/test_p2p.ml | 7 +++++++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/node/net/p2p.ml b/src/node/net/p2p.ml index f34295b97..9b7f9875d 100644 --- a/src/node/net/p2p.ml +++ b/src/node/net/p2p.ml @@ -270,9 +270,9 @@ module Make (P: PARAMS) = struct reader : event Lwt_pipe.t ; writer : msg Lwt_pipe.t ; total_sent : unit -> int ; - total_received : unit -> int ; - inflow : unit -> float ; - outflow : unit -> float ; + total_recv : unit -> int ; + current_inflow : unit -> float ; + current_outflow : unit -> float ; } type peer_info = { @@ -280,6 +280,10 @@ module Make (P: PARAMS) = struct addr : addr ; port : port ; version : version ; + total_sent : int ; + total_recv : int ; + current_inflow : float ; + current_outflow : float ; } (* A net handler, as a record-encoded object, abstract from the @@ -515,14 +519,14 @@ module Make (P: PARAMS) = struct let try_send p = Lwt_pipe.push_now writer p in let reader = Lwt_pipe.create 2 in let total_sent () = !sent in - let total_received () = !received in - let inflow () = received_ema#get in - let outflow () = sent_ema#get in + let total_recv () = !received in + let current_inflow () = received_ema#get in + let current_outflow () = sent_ema#get in (* net object construction *) let peer = { gid ; public_key ; point = (addr, port) ; listening_port ; version ; last_seen ; disconnect ; send ; try_send ; reader ; writer ; - total_sent ; total_received ; inflow ; outflow } in + total_sent ; total_recv ; current_inflow ; current_outflow } in let uncrypt buf = let nonce = get_nonce local_nonce in match Crypto_box.box_open my_secret_key public_key buf nonce with @@ -1313,6 +1317,10 @@ module Make (P: PARAMS) = struct addr = fst peer.point ; port = snd peer.point ; version = peer.version ; + total_sent = peer.total_sent () ; + total_recv = peer.total_recv () ; + current_outflow = peer.current_outflow () ; + current_inflow = peer.current_inflow () ; } and recv_from () = Lwt_pipe.pop messages diff --git a/src/node/net/p2p.mli b/src/node/net/p2p.mli index 6ef313e58..a5ad8767a 100644 --- a/src/node/net/p2p.mli +++ b/src/node/net/p2p.mli @@ -124,6 +124,10 @@ module Make (P : PARAMS) : sig addr : addr ; port : port ; version : version ; + total_sent : int ; + total_recv : int ; + current_inflow : float ; + current_outflow : float ; } (** Access the info of an active peer, if available *) diff --git a/src/node/shell/tezos_p2p.mli b/src/node/shell/tezos_p2p.mli index 9d0b64e09..9f27f5a32 100644 --- a/src/node/shell/tezos_p2p.mli +++ b/src/node/shell/tezos_p2p.mli @@ -33,6 +33,10 @@ type peer_info = { addr : addr ; port : port ; version : version ; + total_sent : int ; + total_recv : int ; + current_inflow : float ; + current_outflow : float ; } (** Access the info of an active peer, if available *) diff --git a/test/test_p2p.ml b/test/test_p2p.ml index bf2170083..bf1c44617 100644 --- a/test/test_p2p.ml +++ b/test/test_p2p.ml @@ -77,6 +77,13 @@ let net_monitor config limits num_nets net = Lwt.async (fun () -> send_msgs_to_neighbours neighbours); let rec recv_peer_msgs acc = if List.length acc = num_nets - 1 then begin + (* Print total sent/recv *) + let peers = Net.peers net in + ListLabels.iter peers ~f:begin fun p -> + let pi = Net.peer_info net p in + log_info "%a -> %a %d %d %.2f %.2f" pp_gid (Net.gid net) pp_gid pi.gid + pi.total_sent pi.total_recv pi.current_inflow pi.current_outflow; + end; ListLabels.iter acc ~f:(fun (k, v) -> log_info "%s %s" k v); Lwt.return_unit end