From 6b8c3f7d31aa80abe6ce4151418776e6678b8b57 Mon Sep 17 00:00:00 2001 From: OCamlPro-Iguernlala Date: Thu, 3 May 2018 18:20:28 +0200 Subject: [PATCH] P2p_maintenance.connectable: ignore non-trusted points if option --closed is set --- src/lib_p2p/p2p_maintenance.ml | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/lib_p2p/p2p_maintenance.ml b/src/lib_p2p/p2p_maintenance.ml index 3863c88b2..b1421affe 100644 --- a/src/lib_p2p/p2p_maintenance.ml +++ b/src/lib_p2p/p2p_maintenance.ml @@ -27,10 +27,11 @@ type 'meta t = { mutable maintain_worker : unit Lwt.t ; } -(** Select [expected] points amongst the disconnected known points. +(** Select [expected] points among the disconnected known points. It ignores points which are greylisted, or for which a connection failed after [start_time] and the pointes that are banned. It - first selects points with the oldest last tentative. *) + first selects points with the oldest last tentative. + Non-trusted points are also ignored if option --closed is set. *) let connectable st start_time expected = let Pool pool = st.pool in let now = Time.now () in @@ -45,18 +46,22 @@ let connectable st start_time expected = | Some t1, Some t2 -> Time.compare t2 t1 end) in let acc = Bounded_point_info.create expected in + let closed = (P2p_pool.config pool).P2p_pool.closed_network in P2p_pool.Points.fold_known pool ~init:() ~f:begin fun point pi () -> - match P2p_point_state.get pi with - | Disconnected -> begin - match P2p_point_state.Info.last_miss pi with - | Some last when Time.(start_time < last) - || P2p_point_state.Info.greylisted ~now pi -> () - | _ when (P2p_pool.Points.banned pool point) -> () - | last -> - Bounded_point_info.insert (last, point) acc - end - | _ -> () + (* consider the point only if --closed is not set, or if pi is + trusted *) + if not closed || P2p_point_state.Info.trusted pi then + match P2p_point_state.get pi with + | Disconnected -> begin + match P2p_point_state.Info.last_miss pi with + | Some last when Time.(start_time < last) + || P2p_point_state.Info.greylisted ~now pi -> () + | _ when (P2p_pool.Points.banned pool point) -> () + | last -> + Bounded_point_info.insert (last, point) acc + end + | _ -> () end ; List.map snd (Bounded_point_info.get acc)