From cc848fc4797a9cbf0380171d2bc5d3be4a5461c6 Mon Sep 17 00:00:00 2001 From: OCamlPro-Iguernlala Date: Fri, 24 Aug 2018 11:15:04 +0200 Subject: [PATCH] P2p: export 'P2p_pool.private_node' 'private_node conn' returns 'true' if the node associated with the given connection is in private mode --- src/lib_p2p/p2p_pool.ml | 8 +++++--- src/lib_p2p/p2p_pool.mli | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/lib_p2p/p2p_pool.ml b/src/lib_p2p/p2p_pool.ml index 286fd84dc..8938e78cc 100644 --- a/src/lib_p2p/p2p_pool.ml +++ b/src/lib_p2p/p2p_pool.ml @@ -584,6 +584,8 @@ end module Connection = struct + let private_node conn = P2p_socket.private_node conn.conn + let fold pool ~init ~f = Peers.fold_connected pool ~init ~f:begin fun peer_id peer_info acc -> match P2p_peer_state.get peer_info with @@ -597,7 +599,7 @@ module Connection = struct let random ?different_than ~no_private pool = let candidates = fold pool ~init:[] ~f:begin fun _peer conn acc -> - if no_private && (P2p_socket.private_node conn.conn) then + if no_private && (private_node conn) then acc else match different_than with @@ -613,7 +615,7 @@ module Connection = struct let random_lowid ?different_than ~no_private pool = let candidates = fold pool ~init:[] ~f:begin fun _peer conn acc -> - if no_private && (P2p_socket.private_node conn.conn) then + if no_private && (private_node conn) then acc else match different_than with @@ -1031,7 +1033,7 @@ and register_new_point pool _source_peer_id point = ignore (register_point pool _source_peer_id point) and list_known_points ?(ignore_private = false) pool conn = - if P2p_socket.private_node conn.conn then + if Connection.private_node conn then private_node_warn "Private peer (%a) asked other peers addresses" P2p_peer.Id.pp (P2p_peer_state.Info.peer_id conn.peer_info) >>= fun () -> Lwt.return_nil diff --git a/src/lib_p2p/p2p_pool.mli b/src/lib_p2p/p2p_pool.mli index b52072440..238eb7791 100644 --- a/src/lib_p2p/p2p_pool.mli +++ b/src/lib_p2p/p2p_pool.mli @@ -267,6 +267,10 @@ module Connection : sig P2p_peer.Id.t -> ('msg, 'peer_meta,'conn_meta) connection option + val private_node: ('msg, 'peer_meta,'conn_meta) connection -> bool + (** [private_node conn] returns 'true' if the node assocoatied to this + connection is in private mode *) + end val on_new_connection: