P2p: P2p_pool.Peers.ban
now also kick target
This commit is contained in:
parent
e1195e6f3e
commit
2830ca3232
@ -425,24 +425,18 @@ let broadcast_bootstrap_msg pool =
|
|||||||
|
|
||||||
(* this function duplicates bit of code from the modules below to avoid
|
(* this function duplicates bit of code from the modules below to avoid
|
||||||
creating mutually recurvive modules *)
|
creating mutually recurvive modules *)
|
||||||
let get_addr pool peer_id =
|
let connection_of_peer_id pool peer_id =
|
||||||
let info peer_id =
|
|
||||||
try Some (P2p_peer.Table.find pool.known_peer_ids peer_id)
|
|
||||||
with Not_found -> None
|
|
||||||
in
|
|
||||||
let find_by_peer_id peer_id =
|
|
||||||
Option.apply
|
Option.apply
|
||||||
(info peer_id)
|
(P2p_peer.Table.find_opt pool.known_peer_ids peer_id) ~f:begin fun p ->
|
||||||
~f:(fun p ->
|
|
||||||
match P2p_peer_state.get p with
|
match P2p_peer_state.get p with
|
||||||
| Running { data } -> Some data
|
| Running { data } -> Some data
|
||||||
| _ -> None)
|
| _ -> None
|
||||||
in
|
end
|
||||||
match find_by_peer_id peer_id with
|
|
||||||
| None -> None
|
let get_addr pool peer_id =
|
||||||
| Some ci ->
|
Option.map (connection_of_peer_id pool peer_id) ~f:begin fun ci ->
|
||||||
let info = P2p_socket.info ci.conn in
|
(P2p_socket.info ci.conn).id_point
|
||||||
Some(info.id_point)
|
end
|
||||||
|
|
||||||
module Points = struct
|
module Points = struct
|
||||||
|
|
||||||
@ -532,7 +526,12 @@ module Peers = struct
|
|||||||
let ban pool peer =
|
let ban pool peer =
|
||||||
Option.iter (get_addr pool peer) ~f:begin fun point ->
|
Option.iter (get_addr pool peer) ~f:begin fun point ->
|
||||||
Points.ban pool point ;
|
Points.ban pool point ;
|
||||||
P2p_acl.PeerBlacklist.add pool.acl peer
|
P2p_acl.PeerBlacklist.add pool.acl peer ;
|
||||||
|
end ;
|
||||||
|
(* Kick [peer] if it is in `Running` state. *)
|
||||||
|
Option.iter (connection_of_peer_id pool peer) ~f:begin fun conn ->
|
||||||
|
conn.wait_close <- false ;
|
||||||
|
Lwt.async (fun () -> Answerer.shutdown (Lazy.force conn.answerer))
|
||||||
end
|
end
|
||||||
|
|
||||||
let trust pool peer =
|
let trust pool peer =
|
||||||
|
Loading…
Reference in New Issue
Block a user