P2P: Add counters in peer_info
This commit is contained in:
parent
92f78b29e4
commit
224e5d8c73
@ -270,9 +270,9 @@ module Make (P: PARAMS) = struct
|
|||||||
reader : event Lwt_pipe.t ;
|
reader : event Lwt_pipe.t ;
|
||||||
writer : msg Lwt_pipe.t ;
|
writer : msg Lwt_pipe.t ;
|
||||||
total_sent : unit -> int ;
|
total_sent : unit -> int ;
|
||||||
total_received : unit -> int ;
|
total_recv : unit -> int ;
|
||||||
inflow : unit -> float ;
|
current_inflow : unit -> float ;
|
||||||
outflow : unit -> float ;
|
current_outflow : unit -> float ;
|
||||||
}
|
}
|
||||||
|
|
||||||
type peer_info = {
|
type peer_info = {
|
||||||
@ -280,6 +280,10 @@ module Make (P: PARAMS) = struct
|
|||||||
addr : addr ;
|
addr : addr ;
|
||||||
port : port ;
|
port : port ;
|
||||||
version : version ;
|
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
|
(* 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 try_send p = Lwt_pipe.push_now writer p in
|
||||||
let reader = Lwt_pipe.create 2 in
|
let reader = Lwt_pipe.create 2 in
|
||||||
let total_sent () = !sent in
|
let total_sent () = !sent in
|
||||||
let total_received () = !received in
|
let total_recv () = !received in
|
||||||
let inflow () = received_ema#get in
|
let current_inflow () = received_ema#get in
|
||||||
let outflow () = sent_ema#get in
|
let current_outflow () = sent_ema#get in
|
||||||
(* net object construction *)
|
(* net object construction *)
|
||||||
let peer = { gid ; public_key ; point = (addr, port) ;
|
let peer = { gid ; public_key ; point = (addr, port) ;
|
||||||
listening_port ; version ; last_seen ;
|
listening_port ; version ; last_seen ;
|
||||||
disconnect ; send ; try_send ; reader ; writer ;
|
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 uncrypt buf =
|
||||||
let nonce = get_nonce local_nonce in
|
let nonce = get_nonce local_nonce in
|
||||||
match Crypto_box.box_open my_secret_key public_key buf nonce with
|
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 ;
|
addr = fst peer.point ;
|
||||||
port = snd peer.point ;
|
port = snd peer.point ;
|
||||||
version = peer.version ;
|
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 () =
|
and recv_from () =
|
||||||
Lwt_pipe.pop messages
|
Lwt_pipe.pop messages
|
||||||
|
@ -124,6 +124,10 @@ module Make (P : PARAMS) : sig
|
|||||||
addr : addr ;
|
addr : addr ;
|
||||||
port : port ;
|
port : port ;
|
||||||
version : version ;
|
version : version ;
|
||||||
|
total_sent : int ;
|
||||||
|
total_recv : int ;
|
||||||
|
current_inflow : float ;
|
||||||
|
current_outflow : float ;
|
||||||
}
|
}
|
||||||
|
|
||||||
(** Access the info of an active peer, if available *)
|
(** Access the info of an active peer, if available *)
|
||||||
|
@ -33,6 +33,10 @@ type peer_info = {
|
|||||||
addr : addr ;
|
addr : addr ;
|
||||||
port : port ;
|
port : port ;
|
||||||
version : version ;
|
version : version ;
|
||||||
|
total_sent : int ;
|
||||||
|
total_recv : int ;
|
||||||
|
current_inflow : float ;
|
||||||
|
current_outflow : float ;
|
||||||
}
|
}
|
||||||
|
|
||||||
(** Access the info of an active peer, if available *)
|
(** Access the info of an active peer, if available *)
|
||||||
|
@ -77,6 +77,13 @@ let net_monitor config limits num_nets net =
|
|||||||
Lwt.async (fun () -> send_msgs_to_neighbours neighbours);
|
Lwt.async (fun () -> send_msgs_to_neighbours neighbours);
|
||||||
let rec recv_peer_msgs acc =
|
let rec recv_peer_msgs acc =
|
||||||
if List.length acc = num_nets - 1 then begin
|
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);
|
ListLabels.iter acc ~f:(fun (k, v) -> log_info "%s %s" k v);
|
||||||
Lwt.return_unit
|
Lwt.return_unit
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user