2017-03-02 18:39:36 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2018-02-06 00:17:03 +04:00
|
|
|
(* Copyright (c) 2014 - 2018. *)
|
2017-03-02 18:39:36 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
let group =
|
2018-04-03 13:39:09 +04:00
|
|
|
{ Clic.name = "p2p" ;
|
2018-02-16 04:26:24 +04:00
|
|
|
title = "Commands for monitoring and controlling p2p-layer state" }
|
2017-03-02 18:39:36 +04:00
|
|
|
|
|
|
|
let commands () = [
|
2018-04-03 13:39:09 +04:00
|
|
|
let open Clic in
|
2017-03-02 18:39:36 +04:00
|
|
|
command ~group ~desc: "show global network status"
|
2017-09-19 13:31:35 +04:00
|
|
|
no_options
|
2018-02-16 21:10:18 +04:00
|
|
|
(prefixes ["p2p" ; "stat"] stop) begin fun () (cctxt : #Client_context.full) ->
|
2018-02-08 13:51:02 +04:00
|
|
|
P2p_services.stat cctxt >>=? fun stat ->
|
|
|
|
P2p_services.Connections.list cctxt >>=? fun conns ->
|
|
|
|
P2p_services.Peers.list cctxt >>=? fun peers ->
|
|
|
|
P2p_services.Points.list cctxt >>=? fun points ->
|
2017-11-07 20:38:11 +04:00
|
|
|
cctxt#message "GLOBAL STATS" >>= fun () ->
|
2018-01-24 15:48:25 +04:00
|
|
|
cctxt#message " %a" P2p_stat.pp stat >>= fun () ->
|
2017-11-07 20:38:11 +04:00
|
|
|
cctxt#message "CONNECTIONS" >>= fun () ->
|
2017-03-02 18:39:36 +04:00
|
|
|
let incoming, outgoing =
|
2018-01-24 15:48:25 +04:00
|
|
|
List.partition (fun c -> c.P2p_connection.Info.incoming) conns in
|
2017-03-02 18:39:36 +04:00
|
|
|
Lwt_list.iter_s begin fun conn ->
|
2018-01-24 15:48:25 +04:00
|
|
|
cctxt#message " %a" P2p_connection.Info.pp conn
|
2017-03-02 18:39:36 +04:00
|
|
|
end incoming >>= fun () ->
|
|
|
|
Lwt_list.iter_s begin fun conn ->
|
2018-01-24 15:48:25 +04:00
|
|
|
cctxt#message " %a" P2p_connection.Info.pp conn
|
2017-03-02 18:39:36 +04:00
|
|
|
end outgoing >>= fun () ->
|
2017-11-07 20:38:11 +04:00
|
|
|
cctxt#message "KNOWN PEERS" >>= fun () ->
|
2017-03-02 18:39:36 +04:00
|
|
|
Lwt_list.iter_s begin fun (p, pi) ->
|
2017-11-07 20:38:11 +04:00
|
|
|
cctxt#message " %a %.0f %a %a %s"
|
2018-01-24 15:48:25 +04:00
|
|
|
P2p_peer.State.pp_digram pi.P2p_peer.Info.state
|
2017-03-02 18:39:36 +04:00
|
|
|
pi.score
|
2018-01-24 15:48:25 +04:00
|
|
|
P2p_peer.Id.pp p
|
|
|
|
P2p_stat.pp pi.stat
|
2017-03-02 18:39:36 +04:00
|
|
|
(if pi.trusted then "★" else " ")
|
|
|
|
end peers >>= fun () ->
|
2017-11-07 20:38:11 +04:00
|
|
|
cctxt#message "KNOWN POINTS" >>= fun () ->
|
2017-03-02 18:39:36 +04:00
|
|
|
Lwt_list.iter_s begin fun (p, pi) ->
|
2018-01-24 15:48:25 +04:00
|
|
|
match pi.P2p_point.Info.state with
|
2017-03-02 18:39:36 +04:00
|
|
|
| Running peer_id ->
|
2017-11-07 20:38:11 +04:00
|
|
|
cctxt#message " %a %a %a %s"
|
2018-01-24 15:48:25 +04:00
|
|
|
P2p_point.State.pp_digram pi.state
|
|
|
|
P2p_point.Id.pp p
|
|
|
|
P2p_peer.Id.pp peer_id
|
2017-03-02 18:39:36 +04:00
|
|
|
(if pi.trusted then "★" else " ")
|
|
|
|
| _ ->
|
|
|
|
match pi.last_seen with
|
|
|
|
| Some (peer_id, ts) ->
|
2017-11-07 20:38:11 +04:00
|
|
|
cctxt#message " %a %a (last seen: %a %a) %s"
|
2018-01-24 15:48:25 +04:00
|
|
|
P2p_point.State.pp_digram pi.state
|
|
|
|
P2p_point.Id.pp p
|
|
|
|
P2p_peer.Id.pp peer_id
|
2017-03-02 18:39:36 +04:00
|
|
|
Time.pp_hum ts
|
|
|
|
(if pi.trusted then "★" else " ")
|
|
|
|
| None ->
|
2017-11-07 20:38:11 +04:00
|
|
|
cctxt#message " %a %a %s"
|
2018-01-24 15:48:25 +04:00
|
|
|
P2p_point.State.pp_digram pi.state
|
|
|
|
P2p_point.Id.pp p
|
2017-03-02 18:39:36 +04:00
|
|
|
(if pi.trusted then "★" else " ")
|
|
|
|
end points >>= fun () ->
|
2017-04-05 01:35:41 +04:00
|
|
|
return ()
|
2017-03-02 18:39:36 +04:00
|
|
|
end
|
|
|
|
]
|