Formatting client_p2p_commands
This commit is contained in:
parent
d71ff759dc
commit
137613ee9a
@ -26,62 +26,64 @@ let port_arg () =
|
|||||||
|
|
||||||
let commands () =
|
let commands () =
|
||||||
let open Clic in
|
let open Clic in
|
||||||
let addr_parameter = parameter (fun _ x -> return (P2p_addr.of_string_exn x)) in
|
let addr_parameter =
|
||||||
|
parameter (fun _ x -> return (P2p_addr.of_string_exn x))
|
||||||
|
in
|
||||||
[
|
[
|
||||||
|
|
||||||
command ~group ~desc: "show global network status"
|
command ~group ~desc: "show global network status"
|
||||||
no_options
|
no_options
|
||||||
(prefixes ["p2p" ; "stat"] stop) begin fun () (cctxt : #Client_context.full) ->
|
(prefixes ["p2p" ; "stat"] stop) begin fun () (cctxt : #Client_context.full) ->
|
||||||
P2p_services.stat cctxt >>=? fun stat ->
|
P2p_services.stat cctxt >>=? fun stat ->
|
||||||
P2p_services.Connections.list cctxt >>=? fun conns ->
|
P2p_services.Connections.list cctxt >>=? fun conns ->
|
||||||
P2p_services.Peers.list cctxt >>=? fun peers ->
|
P2p_services.Peers.list cctxt >>=? fun peers ->
|
||||||
P2p_services.Points.list cctxt >>=? fun points ->
|
P2p_services.Points.list cctxt >>=? fun points ->
|
||||||
cctxt#message "GLOBAL STATS" >>= fun () ->
|
cctxt#message "GLOBAL STATS" >>= fun () ->
|
||||||
cctxt#message " %a" P2p_stat.pp stat >>= fun () ->
|
cctxt#message " %a" P2p_stat.pp stat >>= fun () ->
|
||||||
cctxt#message "CONNECTIONS" >>= fun () ->
|
cctxt#message "CONNECTIONS" >>= fun () ->
|
||||||
let incoming, outgoing =
|
let incoming, outgoing =
|
||||||
List.partition (fun c -> c.P2p_connection.Info.incoming) conns in
|
List.partition (fun c -> c.P2p_connection.Info.incoming) conns in
|
||||||
Lwt_list.iter_s begin fun conn ->
|
Lwt_list.iter_s begin fun conn ->
|
||||||
cctxt#message " %a" P2p_connection.Info.pp conn
|
cctxt#message " %a" P2p_connection.Info.pp conn
|
||||||
end incoming >>= fun () ->
|
end incoming >>= fun () ->
|
||||||
Lwt_list.iter_s begin fun conn ->
|
Lwt_list.iter_s begin fun conn ->
|
||||||
cctxt#message " %a" P2p_connection.Info.pp conn
|
cctxt#message " %a" P2p_connection.Info.pp conn
|
||||||
end outgoing >>= fun () ->
|
end outgoing >>= fun () ->
|
||||||
cctxt#message "KNOWN PEERS" >>= fun () ->
|
cctxt#message "KNOWN PEERS" >>= fun () ->
|
||||||
Lwt_list.iter_s begin fun (p, pi) ->
|
Lwt_list.iter_s begin fun (p, pi) ->
|
||||||
cctxt#message " %a %.0f %a %a %s"
|
cctxt#message " %a %.0f %a %a %s"
|
||||||
P2p_peer.State.pp_digram pi.P2p_peer.Info.state
|
P2p_peer.State.pp_digram pi.P2p_peer.Info.state
|
||||||
pi.score
|
pi.score
|
||||||
P2p_peer.Id.pp p
|
P2p_peer.Id.pp p
|
||||||
P2p_stat.pp pi.stat
|
P2p_stat.pp pi.stat
|
||||||
(if pi.trusted then "★" else " ")
|
(if pi.trusted then "★" else " ")
|
||||||
end peers >>= fun () ->
|
end peers >>= fun () ->
|
||||||
cctxt#message "KNOWN POINTS" >>= fun () ->
|
cctxt#message "KNOWN POINTS" >>= fun () ->
|
||||||
Lwt_list.iter_s begin fun (p, pi) ->
|
Lwt_list.iter_s begin fun (p, pi) ->
|
||||||
match pi.P2p_point.Info.state with
|
match pi.P2p_point.Info.state with
|
||||||
| Running peer_id ->
|
| Running peer_id ->
|
||||||
cctxt#message " %a %a %a %s"
|
cctxt#message " %a %a %a %s"
|
||||||
P2p_point.State.pp_digram pi.state
|
P2p_point.State.pp_digram pi.state
|
||||||
P2p_point.Id.pp p
|
P2p_point.Id.pp p
|
||||||
P2p_peer.Id.pp peer_id
|
P2p_peer.Id.pp peer_id
|
||||||
(if pi.trusted then "★" else " ")
|
(if pi.trusted then "★" else " ")
|
||||||
| _ ->
|
| _ ->
|
||||||
match pi.last_seen with
|
match pi.last_seen with
|
||||||
| Some (peer_id, ts) ->
|
| Some (peer_id, ts) ->
|
||||||
cctxt#message " %a %a (last seen: %a %a) %s"
|
cctxt#message " %a %a (last seen: %a %a) %s"
|
||||||
P2p_point.State.pp_digram pi.state
|
P2p_point.State.pp_digram pi.state
|
||||||
P2p_point.Id.pp p
|
P2p_point.Id.pp p
|
||||||
P2p_peer.Id.pp peer_id
|
P2p_peer.Id.pp peer_id
|
||||||
Time.pp_hum ts
|
Time.pp_hum ts
|
||||||
(if pi.trusted then "★" else " ")
|
(if pi.trusted then "★" else " ")
|
||||||
| None ->
|
| None ->
|
||||||
cctxt#message " %a %a %s"
|
cctxt#message " %a %a %s"
|
||||||
P2p_point.State.pp_digram pi.state
|
P2p_point.State.pp_digram pi.state
|
||||||
P2p_point.Id.pp p
|
P2p_point.Id.pp p
|
||||||
(if pi.trusted then "★" else " ")
|
(if pi.trusted then "★" else " ")
|
||||||
end points >>= fun () ->
|
end points >>= fun () ->
|
||||||
return ()
|
return ()
|
||||||
end ;
|
end ;
|
||||||
|
|
||||||
command ~group ~desc: "Connect to a new point."
|
command ~group ~desc: "Connect to a new point."
|
||||||
(args1 (port_arg ()))
|
(args1 (port_arg ()))
|
||||||
@ -90,7 +92,7 @@ let commands () =
|
|||||||
@@ stop)
|
@@ stop)
|
||||||
(fun port address (cctxt : #Client_context.full) ->
|
(fun port address (cctxt : #Client_context.full) ->
|
||||||
P2p_services.connect cctxt ~timeout:10. (address, port)
|
P2p_services.connect cctxt ~timeout:10. (address, port)
|
||||||
);
|
) ;
|
||||||
|
|
||||||
command ~group ~desc: "Remove an IP address from the blacklist and whitelist."
|
command ~group ~desc: "Remove an IP address from the blacklist and whitelist."
|
||||||
no_options
|
no_options
|
||||||
@ -99,7 +101,7 @@ let commands () =
|
|||||||
@@ stop)
|
@@ stop)
|
||||||
(fun () address (cctxt : #Client_context.full) ->
|
(fun () address (cctxt : #Client_context.full) ->
|
||||||
P2p_services.Points.forget cctxt (address, 0)
|
P2p_services.Points.forget cctxt (address, 0)
|
||||||
);
|
) ;
|
||||||
|
|
||||||
command ~group ~desc: "Add an IP address to the blacklist."
|
command ~group ~desc: "Add an IP address to the blacklist."
|
||||||
no_options
|
no_options
|
||||||
@ -108,7 +110,7 @@ let commands () =
|
|||||||
@@ stop)
|
@@ stop)
|
||||||
(fun () address (cctxt : #Client_context.full) ->
|
(fun () address (cctxt : #Client_context.full) ->
|
||||||
P2p_services.Points.ban cctxt (address, 0)
|
P2p_services.Points.ban cctxt (address, 0)
|
||||||
);
|
) ;
|
||||||
|
|
||||||
command ~group ~desc: "Add an IP address to the whitelist."
|
command ~group ~desc: "Add an IP address to the whitelist."
|
||||||
no_options
|
no_options
|
||||||
@ -117,7 +119,7 @@ let commands () =
|
|||||||
@@ stop)
|
@@ stop)
|
||||||
(fun () address (cctxt : #Client_context.full) ->
|
(fun () address (cctxt : #Client_context.full) ->
|
||||||
P2p_services.Points.trust cctxt (address, 0)
|
P2p_services.Points.trust cctxt (address, 0)
|
||||||
);
|
) ;
|
||||||
|
|
||||||
command ~group ~desc: "Check if an IP address is banned."
|
command ~group ~desc: "Check if an IP address is banned."
|
||||||
no_options
|
no_options
|
||||||
@ -130,7 +132,7 @@ let commands () =
|
|||||||
"The given ip address is %s"
|
"The given ip address is %s"
|
||||||
(if banned then "banned" else "not banned") >>= fun () ->
|
(if banned then "banned" else "not banned") >>= fun () ->
|
||||||
return ()
|
return ()
|
||||||
);
|
) ;
|
||||||
|
|
||||||
command ~group ~desc: "Remove a peer ID from the blacklist and whitelist."
|
command ~group ~desc: "Remove a peer ID from the blacklist and whitelist."
|
||||||
no_options
|
no_options
|
||||||
@ -139,7 +141,7 @@ let commands () =
|
|||||||
@@ stop)
|
@@ stop)
|
||||||
(fun () peer (cctxt : #Client_context.full) ->
|
(fun () peer (cctxt : #Client_context.full) ->
|
||||||
P2p_services.Peers.forget cctxt peer
|
P2p_services.Peers.forget cctxt peer
|
||||||
);
|
) ;
|
||||||
|
|
||||||
command ~group ~desc: "Add a peer ID to the blacklist."
|
command ~group ~desc: "Add a peer ID to the blacklist."
|
||||||
no_options
|
no_options
|
||||||
@ -148,7 +150,7 @@ let commands () =
|
|||||||
@@ stop)
|
@@ stop)
|
||||||
(fun () peer (cctxt : #Client_context.full) ->
|
(fun () peer (cctxt : #Client_context.full) ->
|
||||||
P2p_services.Peers.ban cctxt peer
|
P2p_services.Peers.ban cctxt peer
|
||||||
);
|
) ;
|
||||||
|
|
||||||
command ~group ~desc: "Add a peer ID to the whitelist."
|
command ~group ~desc: "Add a peer ID to the whitelist."
|
||||||
no_options
|
no_options
|
||||||
@ -157,7 +159,7 @@ let commands () =
|
|||||||
@@ stop)
|
@@ stop)
|
||||||
(fun () peer (cctxt : #Client_context.full) ->
|
(fun () peer (cctxt : #Client_context.full) ->
|
||||||
P2p_services.Peers.trust cctxt peer
|
P2p_services.Peers.trust cctxt peer
|
||||||
);
|
) ;
|
||||||
|
|
||||||
command ~group ~desc: "Check if a peer ID is banned."
|
command ~group ~desc: "Check if a peer ID is banned."
|
||||||
no_options
|
no_options
|
||||||
@ -170,12 +172,12 @@ let commands () =
|
|||||||
"The given peer ID is %s"
|
"The given peer ID is %s"
|
||||||
(if banned then "banned" else "not banned") >>= fun () ->
|
(if banned then "banned" else "not banned") >>= fun () ->
|
||||||
return ()
|
return ()
|
||||||
);
|
) ;
|
||||||
|
|
||||||
command ~group ~desc: "Clear all ACLs."
|
command ~group ~desc: "Clear all ACLs."
|
||||||
no_options
|
no_options
|
||||||
(prefixes [ "clear" ; "acls" ] @@ stop)
|
(prefixes [ "clear" ; "acls" ] @@ stop)
|
||||||
(fun () (cctxt : #Client_context.full) ->
|
(fun () (cctxt : #Client_context.full) ->
|
||||||
P2p_services.ACL.clear cctxt ()
|
P2p_services.ACL.clear cctxt ()
|
||||||
);
|
) ;
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user