Admin/P2P: update the admin client commands for the new RPCs

This commit is contained in:
Vincent Botbol 2018-10-10 14:22:42 +02:00
parent b6bb16caf1
commit e61de64474
No known key found for this signature in database
GPG Key ID: A2CE1BDBED95DA38

View File

@ -99,7 +99,8 @@ let commands () =
@@ stop) @@ stop)
(fun () (address, port) (cctxt : #Client_context.full) -> (fun () (address, port) (cctxt : #Client_context.full) ->
P2p_services.connect cctxt ~timeout:10. (address, port) >>=? fun () -> P2p_services.connect cctxt ~timeout:10. (address, port) >>=? fun () ->
cctxt#message "Connection to %a:%d established." P2p_addr.pp address port >>= return cctxt#message "Connection to %a:%d established." P2p_addr.pp address port >>= fun () ->
return_unit
) ; ) ;
command ~group ~desc: "Kick a peer." command ~group ~desc: "Kick a peer."
@ -113,31 +114,56 @@ let commands () =
return_unit return_unit
) ; ) ;
command ~group ~desc: "Remove an IP address from the blacklist and whitelist." command ~group ~desc: "Add an IP address and all its ports to the \
no_options blacklist and kicks it. Remove the address \
(prefixes [ "forget" ; "address" ] from the whitelist if it was previously in \
@@ addr_parameter it."
@@ stop)
(fun () (address, port) (cctxt : #Client_context.full) ->
P2p_services.Points.forget cctxt (address, port)
) ;
command ~group ~desc: "Add an IP address to the blacklist and kicks it."
no_options no_options
(prefixes [ "ban" ; "address" ] (prefixes [ "ban" ; "address" ]
@@ addr_parameter @@ addr_parameter
@@ stop) @@ stop)
(fun () (address, port) (cctxt : #Client_context.full) -> (fun () (address, _port) (cctxt : #Client_context.full) ->
P2p_services.Points.ban cctxt (address, port) P2p_services.Points.ban cctxt (address, 0) >>=? fun () ->
cctxt#message "Address %a:* is now banned." P2p_addr.pp address >>= fun () ->
return_unit
) ; ) ;
command ~group ~desc: "Add an IP address to the whitelist." command ~group ~desc: "Remove an IP address and all its ports \
from the blacklist."
no_options
(prefixes [ "unban" ; "address" ]
@@ addr_parameter
@@ stop)
(fun () (address, _port) (cctxt : #Client_context.full) ->
P2p_services.Points.unban cctxt (address, 0) >>=? fun () ->
cctxt#message "Address %a:* is now unbanned." P2p_addr.pp address >>= fun () ->
return_unit
) ;
command ~group ~desc: "Add an IP address to the whitelist. Remove \
the address from the blacklist if it was \
previously in it."
no_options no_options
(prefixes [ "trust" ; "address" ] (prefixes [ "trust" ; "address" ]
@@ addr_parameter @@ addr_parameter
@@ stop) @@ stop)
(fun () (address, port) (cctxt : #Client_context.full) -> (fun () (address, port) (cctxt : #Client_context.full) ->
P2p_services.Points.trust cctxt (address, port) P2p_services.Points.trust cctxt (address, port) >>=? fun () ->
cctxt#message "Address %a:%d is now trusted."
P2p_addr.pp address port >>= fun () ->
return_unit
) ;
command ~group ~desc: "Removes an IP address from the whitelist."
no_options
(prefixes [ "untrust" ; "address" ]
@@ addr_parameter
@@ stop)
(fun () (address, port) (cctxt : #Client_context.full) ->
P2p_services.Points.untrust cctxt (address, port) >>=? fun () ->
cctxt#message "Address %a:%d is now untrusted."
P2p_addr.pp address port >>= fun () ->
return_unit
) ; ) ;
command ~group ~desc: "Check if an IP address is banned." command ~group ~desc: "Check if an IP address is banned."
@ -153,33 +179,6 @@ let commands () =
return_unit return_unit
) ; ) ;
command ~group ~desc: "Remove a peer ID from the blacklist and whitelist."
no_options
(prefixes [ "forget" ; "peer" ]
@@ P2p_peer.Id.param ~name:"peer" ~desc:"peer network identity"
@@ stop)
(fun () peer (cctxt : #Client_context.full) ->
P2p_services.Peers.forget cctxt peer
) ;
command ~group ~desc: "Add a peer ID to the blacklist and kicks it."
no_options
(prefixes [ "ban" ; "peer" ]
@@ P2p_peer.Id.param ~name:"peer" ~desc:"peer network identity"
@@ stop)
(fun () peer (cctxt : #Client_context.full) ->
P2p_services.Peers.ban cctxt peer
) ;
command ~group ~desc: "Add a peer ID to the whitelist."
no_options
(prefixes [ "trust" ; "peer" ]
@@ P2p_peer.Id.param ~name:"peer" ~desc:"peer network identity"
@@ stop)
(fun () peer (cctxt : #Client_context.full) ->
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
(prefixes [ "is" ; "peer" ; "banned" ] (prefixes [ "is" ; "peer" ; "banned" ]
@ -193,10 +192,64 @@ let commands () =
return_unit return_unit
) ; ) ;
command ~group ~desc: "Add a peer ID to the blacklist and kicks \
it. Remove the peer ID from the blacklist \
if was previously in it."
no_options
(prefixes [ "ban" ; "peer" ]
@@ P2p_peer.Id.param ~name:"peer" ~desc:"peer network identity"
@@ stop)
(fun () peer (cctxt : #Client_context.full) ->
P2p_services.Peers.ban cctxt peer >>=? fun () ->
cctxt#message "The peer %a is now banned."
P2p_peer.Id.pp_short peer >>= fun () ->
return_unit
) ;
command ~group ~desc: "Removes a peer ID from the blacklist."
no_options
(prefixes [ "unban" ; "peer" ]
@@ P2p_peer.Id.param ~name:"peer" ~desc:"peer network identity"
@@ stop)
(fun () peer (cctxt : #Client_context.full) ->
P2p_services.Peers.unban cctxt peer >>=? fun () ->
cctxt#message "The peer %a is now unbanned."
P2p_peer.Id.pp_short peer >>= fun () ->
return_unit
) ;
command ~group ~desc: "Add a peer ID to the whitelist. Remove the \
peer ID from the blacklist if it was \
previously in it."
no_options
(prefixes [ "trust" ; "peer" ]
@@ P2p_peer.Id.param ~name:"peer" ~desc:"peer network identity"
@@ stop)
(fun () peer (cctxt : #Client_context.full) ->
P2p_services.Peers.trust cctxt peer >>=? fun () ->
cctxt#message "The peer %a is now trusted."
P2p_peer.Id.pp_short peer >>= fun () ->
return_unit
) ;
command ~group ~desc: "Remove a peer ID from the whitelist."
no_options
(prefixes [ "untrust" ; "peer" ]
@@ P2p_peer.Id.param ~name:"peer" ~desc:"peer network identity"
@@ stop)
(fun () peer (cctxt : #Client_context.full) ->
P2p_services.Peers.untrust cctxt peer >>=? fun () ->
cctxt#message "The peer %a is now untrusted."
P2p_peer.Id.pp_short peer >>= fun () ->
return_unit
) ;
command ~group ~desc: "Clear all access control rules." command ~group ~desc: "Clear all access control rules."
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 () >>=? fun () ->
cctxt#message "The access control rules are now cleared." >>= fun () ->
return_unit
) ; ) ;
] ]