From 0c3a54c2f964b73fcdb178ab9468bc886284c59c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Fri, 29 Sep 2017 18:43:13 +0200 Subject: [PATCH] Distributed_db: export `disconnect` --- src/node/net/p2p.ml | 6 ++++++ src/node/net/p2p.mli | 5 +++++ src/node/shell/distributed_db.ml | 5 +++++ src/node/shell/distributed_db.mli | 2 ++ 4 files changed, 18 insertions(+) diff --git a/src/node/net/p2p.ml b/src/node/net/p2p.ml index c4c496ba9..3a93c776c 100644 --- a/src/node/net/p2p.ml +++ b/src/node/net/p2p.ml @@ -201,6 +201,8 @@ module Real = struct ~init:[] ~f:(fun _peer_id c acc -> c :: acc) let find_connection { pool } peer_id = P2p_connection_pool.Connection.find_by_peer_id pool peer_id + let disconnect ?wait conn = + P2p_connection_pool.disconnect ?wait conn let connection_info _net conn = P2p_connection_pool.Connection.info conn let connection_stat _net conn = @@ -319,6 +321,7 @@ type ('msg, 'meta) t = { shutdown : unit -> unit Lwt.t ; connections : unit -> ('msg, 'meta) connection list ; find_connection : Peer_id.t -> ('msg, 'meta) connection option ; + disconnect : ?wait:bool -> ('msg, 'meta) connection -> unit Lwt.t ; connection_info : ('msg, 'meta) connection -> Connection_info.t ; connection_stat : ('msg, 'meta) connection -> Stat.t ; global_stat : unit -> Stat.t ; @@ -385,6 +388,7 @@ let create ~config ~limits meta_cfg msg_cfg = shutdown = Real.shutdown net ; connections = Real.connections net ; find_connection = Real.find_connection net ; + disconnect = Real.disconnect ; connection_info = Real.connection_info net ; connection_stat = Real.connection_stat net ; global_stat = Real.global_stat net ; @@ -408,6 +412,7 @@ let faked_network meta_config = { shutdown = Lwt.return ; connections = (fun () -> []) ; find_connection = (fun _ -> None) ; + disconnect = (fun ?wait:_ _ -> Lwt.return_unit) ; connection_info = (fun _ -> Fake.connection_info) ; connection_stat = (fun _ -> Fake.empty_stat) ; global_stat = (fun () -> Fake.empty_stat) ; @@ -429,6 +434,7 @@ let maintain net = net.maintain () let roll net = net.roll () let shutdown net = net.shutdown () let connections net = net.connections () +let disconnect net = net.disconnect let find_connection net = net.find_connection let connection_info net = net.connection_info let connection_stat net = net.connection_stat diff --git a/src/node/net/p2p.mli b/src/node/net/p2p.mli index 265ca978a..61bf9add9 100644 --- a/src/node/net/p2p.mli +++ b/src/node/net/p2p.mli @@ -171,6 +171,11 @@ val connection_info : ('msg, 'meta) net -> ('msg, 'meta) connection -> Connection_info.t val connection_stat : ('msg, 'meta) net -> ('msg, 'meta) connection -> Stat.t + +(** Cleanly closes a connection. *) +val disconnect : + ('msg, 'meta) net -> ?wait:bool -> ('msg, 'meta) connection -> unit Lwt.t + val global_stat : ('msg, 'meta) net -> Stat.t (** Accessors for meta information about a global identifier *) diff --git a/src/node/shell/distributed_db.ml b/src/node/shell/distributed_db.ml index 9b93542f9..e4ad7369f 100644 --- a/src/node/shell/distributed_db.ml +++ b/src/node/shell/distributed_db.ml @@ -707,6 +707,11 @@ let get_net { active_nets } net_id = try Some (Net_id.Table.find active_nets net_id) with Not_found -> None +let disconnect { global_db = { p2p } } peer_id = + match P2p.find_connection p2p peer_id with + | None -> Lwt.return_unit + | Some conn -> P2p.disconnect p2p conn + let shutdown { p2p ; p2p_readers ; active_nets } = P2p.Peer_id.Table.fold (fun _peer_id reader acc -> diff --git a/src/node/shell/distributed_db.mli b/src/node/shell/distributed_db.mli index 2b33f20d1..4c1abf4dc 100644 --- a/src/node/shell/distributed_db.mli +++ b/src/node/shell/distributed_db.mli @@ -32,6 +32,8 @@ val activate: t -> State.Net.t -> net_db val set_callback: net_db -> callback -> unit val deactivate: net_db -> unit Lwt.t +val disconnect: net_db -> P2p.Peer_id.t -> unit Lwt.t + val broadcast_head: net_db -> Block_hash.t -> Operation_hash.t list -> unit