P2p: add "private node" information in Connection_metadata.

Add private_node flag in Connection_metadata.t and update Node,
Distributed_db, P2p and P2p_pool to propagate the information
This commit is contained in:
OCamlPro-Iguernlala 2018-05-31 13:19:36 +02:00 committed by Grégoire Henry
parent 65758d08ac
commit 4a16b3ef0b
6 changed files with 22 additions and 12 deletions

View File

@ -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 =

View File

@ -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 : {

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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 =

View File

@ -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