diff --git a/src/lib_p2p/p2p.ml b/src/lib_p2p/p2p.ml index 8b8808082..733b80f98 100644 --- a/src/lib_p2p/p2p.ml +++ b/src/lib_p2p/p2p.ml @@ -18,6 +18,7 @@ type 'peer_meta peer_meta_config = 'peer_meta P2p_pool.peer_meta_config = { type 'conn_meta conn_meta_config = 'conn_meta P2p_pool.conn_meta_config = { conn_meta_encoding : 'conn_meta Data_encoding.t ; conn_meta_value : P2p_peer.Id.t -> 'conn_meta ; + private_node : 'conn_meta -> bool ; } type 'msg app_message_encoding = 'msg P2p_pool.encoding = diff --git a/src/lib_p2p/p2p.mli b/src/lib_p2p/p2p.mli index 27864cbe3..306b5b06c 100644 --- a/src/lib_p2p/p2p.mli +++ b/src/lib_p2p/p2p.mli @@ -24,6 +24,7 @@ type 'peer_meta peer_meta_config = { type 'conn_meta conn_meta_config = { conn_meta_encoding : 'conn_meta Data_encoding.t; conn_meta_value : P2p_peer.Id.t -> 'conn_meta ; + private_node : 'conn_meta -> bool ; } type 'msg app_message_encoding = Encoding : { diff --git a/src/lib_p2p/p2p_pool.ml b/src/lib_p2p/p2p_pool.ml index a16a5bd7b..66d96a630 100644 --- a/src/lib_p2p/p2p_pool.ml +++ b/src/lib_p2p/p2p_pool.ml @@ -210,6 +210,7 @@ type 'msg message_config = { type 'conn_meta conn_meta_config = { conn_meta_encoding : 'conn_meta Data_encoding.t ; conn_meta_value : P2p_peer.Id.t -> 'conn_meta ; + private_node : 'conn_meta -> bool ; } type ('msg, 'peer_meta, 'conn_meta) t = { diff --git a/src/lib_p2p/p2p_pool.mli b/src/lib_p2p/p2p_pool.mli index db4b89d7c..dc149f2d2 100644 --- a/src/lib_p2p/p2p_pool.mli +++ b/src/lib_p2p/p2p_pool.mli @@ -134,6 +134,7 @@ type 'peer_meta peer_meta_config = { type 'conn_meta conn_meta_config = { conn_meta_encoding : 'conn_meta Data_encoding.t ; conn_meta_value : P2p_peer.Id.t -> 'conn_meta ; + private_node : 'conn_meta -> bool ; } type 'msg message_config = { diff --git a/src/lib_p2p/test/test_p2p_pool.ml b/src/lib_p2p/test/test_p2p_pool.ml index a900e48bc..780896d3d 100644 --- a/src/lib_p2p/test/test_p2p_pool.ml +++ b/src/lib_p2p/test/test_p2p_pool.ml @@ -36,6 +36,7 @@ let peer_meta_config : metadata P2p_pool.peer_meta_config = { let conn_meta_config : metadata P2p_pool.conn_meta_config = { conn_meta_encoding = Data_encoding.empty ; conn_meta_value = (fun _ -> ()) ; + private_node = (fun _ -> false) ; } let sync ch = diff --git a/src/lib_shell/node.ml b/src/lib_shell/node.ml index fdf57d688..08cc43b0a 100644 --- a/src/lib_shell/node.ml +++ b/src/lib_shell/node.ml @@ -65,6 +65,7 @@ type t = { shutdown: unit -> unit Lwt.t ; } + let peer_metadata_cfg : _ P2p.peer_meta_config = { peer_meta_encoding = Peer_metadata.encoding ; peer_meta_initial = () ; @@ -73,28 +74,32 @@ let peer_metadata_cfg : _ P2p.peer_meta_config = { let connection_metadata_cfg cfg : _ P2p.conn_meta_config = { conn_meta_encoding = Connection_metadata.encoding ; + private_node = (fun { private_node } -> private_node) ; conn_meta_value = fun _ -> cfg; } +let init_connection_metadata opt = + let open Connection_metadata in + match opt with + | None -> + { disable_mempool = false ; + private_node = false } + + | Some c -> + { disable_mempool = c.P2p.disable_mempool ; + private_node = c.P2p.private_mode } + let init_p2p p2p_params = match p2p_params with | None -> - let conn_metadata_cfg = - connection_metadata_cfg { - Connection_metadata. - disable_mempool = false ; - private_node = false ; - } in + let c_meta = init_connection_metadata None in + let conn_metadata_cfg = connection_metadata_cfg c_meta in lwt_log_notice "P2P layer is disabled" >>= fun () -> return (P2p.faked_network peer_metadata_cfg, conn_metadata_cfg) | Some (config, limits) -> - let conn_metadata_cfg = - connection_metadata_cfg { - Connection_metadata. - disable_mempool = config.P2p.disable_mempool ; - private_node = false ; - } in + let c_meta = init_connection_metadata (Some config) in + let conn_metadata_cfg = connection_metadata_cfg c_meta in lwt_log_notice "bootstraping chain..." >>= fun () -> P2p.create ~config ~limits