ligo/lib_client_base/client_network.ml

73 lines
2.9 KiB
OCaml
Raw Normal View History

2017-03-02 18:39:36 +04:00
(**************************************************************************)
(* *)
2017-11-14 03:36:14 +04:00
(* Copyright (c) 2014 - 2017. *)
2017-03-02 18:39:36 +04:00
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
open Client_commands
open P2p_types
2017-03-02 18:39:36 +04:00
let group =
{ Cli_entries.name = "network" ;
title = "Commands for monitoring and controlling network state" }
let commands () = [
let open Cli_entries in
command ~group ~desc: "show global network status"
no_options
(prefixes ["network" ; "stat"] stop) begin fun () cctxt ->
Client_node_rpcs.Network.stat cctxt.rpc_config >>=? fun stat ->
Client_node_rpcs.Network.connections cctxt.rpc_config >>=? fun conns ->
Client_node_rpcs.Network.peers cctxt.rpc_config >>=? fun peers ->
Client_node_rpcs.Network.points cctxt.rpc_config >>=? fun points ->
2017-03-02 18:39:36 +04:00
cctxt.message "GLOBAL STATS" >>= fun () ->
cctxt.message " %a" Stat.pp stat >>= fun () ->
2017-03-02 18:39:36 +04:00
cctxt.message "CONNECTIONS" >>= fun () ->
let incoming, outgoing =
List.partition (fun c -> c.Connection_info.incoming) conns in
2017-03-02 18:39:36 +04:00
Lwt_list.iter_s begin fun conn ->
cctxt.message " %a" Connection_info.pp conn
2017-03-02 18:39:36 +04:00
end incoming >>= fun () ->
Lwt_list.iter_s begin fun conn ->
cctxt.message " %a" Connection_info.pp conn
2017-03-02 18:39:36 +04:00
end outgoing >>= fun () ->
cctxt.message "KNOWN PEERS" >>= fun () ->
Lwt_list.iter_s begin fun (p, pi) ->
cctxt.message " %a %.0f %a %a %s"
Peer_state.pp_digram pi.Peer_info.state
2017-03-02 18:39:36 +04:00
pi.score
Peer_id.pp p
Stat.pp pi.stat
2017-03-02 18:39:36 +04:00
(if pi.trusted then "" else " ")
end peers >>= fun () ->
cctxt.message "KNOWN POINTS" >>= fun () ->
Lwt_list.iter_s begin fun (p, pi) ->
match pi.Point_info.state with
2017-03-02 18:39:36 +04:00
| Running peer_id ->
cctxt.message " %a %a %a %s"
Point_state.pp_digram pi.state
2017-03-02 18:39:36 +04:00
Point.pp p
Peer_id.pp peer_id
(if pi.trusted then "" else " ")
| _ ->
match pi.last_seen with
| Some (peer_id, ts) ->
cctxt.message " %a %a (last seen: %a %a) %s"
Point_state.pp_digram pi.state
2017-03-02 18:39:36 +04:00
Point.pp p
Peer_id.pp peer_id
Time.pp_hum ts
(if pi.trusted then "" else " ")
| None ->
cctxt.message " %a %a %s"
Point_state.pp_digram pi.state
2017-03-02 18:39:36 +04:00
Point.pp p
(if pi.trusted then "" else " ")
end points >>= fun () ->
return ()
2017-03-02 18:39:36 +04:00
end
]