Admin/P2P: register forget and kick RPC

This commit is contained in:
Vincent Botbol 2018-09-19 17:51:51 +02:00
parent 705a779d76
commit 57fa653c5e
No known key found for this signature in database
GPG Key ID: A2CE1BDBED95DA38
2 changed files with 38 additions and 6 deletions

View File

@ -109,19 +109,31 @@ let commands () =
@@ param ~name:"address" ~desc:"IPv4 or IPV6 address" addr_parameter
@@ stop)
(fun port address (cctxt : #Client_context.full) ->
P2p_services.connect cctxt ~timeout:10. (address, port)
P2p_services.connect cctxt ~timeout:10. (address, port) >>=? fun () ->
cctxt#message "Connection to %a:%d established." P2p_addr.pp address port >>= return
) ;
command ~group ~desc: "Kick a peer."
no_options
(prefixes [ "kick" ; "peer" ]
@@ P2p_peer.Id.param ~name:"peer" ~desc:"peer network identity"
@@ stop)
(fun () peer (cctxt : #Client_context.full) ->
P2p_services.Connections.kick cctxt peer >>=? fun () ->
cctxt#message "Connection to %a interrupted." P2p_peer.Id.pp peer >>= fun () ->
return_unit
) ;
command ~group ~desc: "Remove an IP address from the blacklist and whitelist."
no_options
(args1 (port_arg ()))
(prefixes [ "forget" ; "address" ]
@@ param ~name:"address" ~desc:"IPv4 or IPV6 address" addr_parameter
@@ stop)
(fun () address (cctxt : #Client_context.full) ->
P2p_services.Points.forget cctxt (address, 0)
(fun port address (cctxt : #Client_context.full) ->
P2p_services.Points.forget cctxt (address, port)
) ;
command ~group ~desc: "Add an IP address to the blacklist."
command ~group ~desc: "Add an IP address to the blacklist and kicks it."
no_options
(prefixes [ "ban" ; "address" ]
@@ param ~name:"address" ~desc:"IPv4 or IPV6 address" addr_parameter
@ -161,7 +173,7 @@ let commands () =
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 and kicks it."
no_options
(prefixes [ "ban" ; "peer" ]
@@ P2p_peer.Id.param ~name:"peer" ~desc:"peer network identity"

View File

@ -711,6 +711,16 @@ let build_rpc_directory net =
RPC_answer.return_stream { next ; shutdown }
end in
let dir =
RPC_directory.gen_register1 dir P2p_services.Peers.S.forget
begin fun peer_id () () ->
match net.pool with
| None -> RPC_answer.not_found
| Some pool ->
P2p_pool.Peers.forget pool peer_id ;
RPC_answer.return ()
end in
let dir =
RPC_directory.gen_register1 dir P2p_services.Peers.S.ban
begin fun peer_id () () ->
@ -806,6 +816,16 @@ let build_rpc_directory net =
RPC_answer.return_stream { next ; shutdown }
end in
let dir =
RPC_directory.gen_register1 dir P2p_services.Points.S.forget
begin fun point () () ->
match net.pool with
| None -> RPC_answer.not_found
| Some pool ->
P2p_pool.Points.forget pool point ;
RPC_answer.return ()
end in
let dir =
RPC_directory.gen_register1 dir P2p_services.Points.S.ban
begin fun point () () ->