P2p: change configuration of P2p_maintenance

It feels more coherent not to configure `P2p_pool` with parameters
only for `P2p_maintenance`.
This commit is contained in:
Grégoire Henry 2019-02-26 17:44:38 +01:00 committed by Raphaël Proust
parent 10c37f153d
commit 9abcd0e55f
No known key found for this signature in database
GPG Key ID: F4B685504488CEC0
6 changed files with 41 additions and 27 deletions

View File

@ -72,7 +72,7 @@ type limits = {
connection_timeout : float ; connection_timeout : float ;
authentication_timeout : float ; authentication_timeout : float ;
greylist_timeout : int ; greylist_timeout : int ;
maintenance_idle_time: float ; maintenance_idle_time : float ;
min_connections : int ; min_connections : int ;
expected_connections : int ; expected_connections : int ;
@ -127,8 +127,6 @@ let create_connection_pool config limits meta_cfg conn_meta_cfg msg_cfg io_sched
max_incoming_connections = limits.max_incoming_connections ; max_incoming_connections = limits.max_incoming_connections ;
connection_timeout = limits.connection_timeout ; connection_timeout = limits.connection_timeout ;
authentication_timeout = limits.authentication_timeout ; authentication_timeout = limits.authentication_timeout ;
greylist_timeout = limits.greylist_timeout ;
maintenance_idle_time = limits.maintenance_idle_time ;
incoming_app_message_queue_size = limits.incoming_app_message_queue_size ; incoming_app_message_queue_size = limits.incoming_app_message_queue_size ;
incoming_message_queue_size = limits.incoming_message_queue_size ; incoming_message_queue_size = limits.incoming_message_queue_size ;
outgoing_message_queue_size = limits.outgoing_message_queue_size ; outgoing_message_queue_size = limits.outgoing_message_queue_size ;
@ -173,11 +171,15 @@ let create_maintenance_worker limits pool config =
bounds bounds
~min:limits.min_connections ~min:limits.min_connections
~expected:limits.expected_connections ~expected:limits.expected_connections
~max:limits.max_connections ~max:limits.max_connections in
in let maintenance_config = {
let discovery = P2p_maintenance.
may_create_discovery_worker limits config pool in maintenance_idle_time = limits.maintenance_idle_time ;
P2p_maintenance.create ?discovery bounds pool greylist_timeout = limits.greylist_timeout ;
private_mode = config.private_mode ;
} in
let discovery = may_create_discovery_worker limits config pool in
P2p_maintenance.create ?discovery maintenance_config bounds pool
let may_create_welcome_worker config limits pool = let may_create_welcome_worker config limits pool =
match config.listening_port with match config.listening_port with

View File

@ -33,10 +33,17 @@ type bounds = {
max_threshold: int ; max_threshold: int ;
} }
type config = {
maintenance_idle_time: float ;
greylist_timeout: int ;
private_mode: bool ;
}
type 'meta pool = Pool : ('msg, 'meta, 'meta_conn) P2p_pool.t -> 'meta pool type 'meta pool = Pool : ('msg, 'meta, 'meta_conn) P2p_pool.t -> 'meta pool
type 'meta t = { type 'meta t = {
canceler: Lwt_canceler.t ; canceler: Lwt_canceler.t ;
config: config ;
bounds: bounds ; bounds: bounds ;
pool: 'meta pool ; pool: 'meta pool ;
discovery: P2p_discovery.t option ; discovery: P2p_discovery.t option ;
@ -64,7 +71,6 @@ let connectable st start_time expected seen_points =
| Some t1, Some t2 -> Time.compare t2 t1 | Some t1, Some t2 -> Time.compare t2 t1
end) in end) in
let acc = Bounded_point_info.create expected in let acc = Bounded_point_info.create expected in
let private_mode = (P2p_pool.config pool).P2p_pool.private_mode in
let seen_points = let seen_points =
P2p_pool.Points.fold_known pool ~init:seen_points P2p_pool.Points.fold_known pool ~init:seen_points
~f:begin fun point pi seen_points -> ~f:begin fun point pi seen_points ->
@ -75,7 +81,7 @@ let connectable st start_time expected seen_points =
*) *)
if P2p_point.Set.mem point seen_points || if P2p_point.Set.mem point seen_points ||
P2p_pool.Points.banned pool point || P2p_pool.Points.banned pool point ||
(private_mode && not (P2p_point_state.Info.trusted pi)) (st.config.private_mode && not (P2p_point_state.Info.trusted pi))
then then
seen_points seen_points
else else
@ -131,9 +137,8 @@ let rec try_to_contact
let rec maintain st = let rec maintain st =
let Pool pool = st.pool in let Pool pool = st.pool in
let n_connected = P2p_pool.active_connections pool in let n_connected = P2p_pool.active_connections pool in
let pool_cfg = P2p_pool.config pool in
let older_than = let older_than =
Time.(add (now ()) (Int64.of_int (- pool_cfg.greylist_timeout))) Time.(add (now ()) (Int64.of_int (- st.config.greylist_timeout)))
in in
P2p_pool.gc_greylist pool ~older_than ; P2p_pool.gc_greylist pool ~older_than ;
if n_connected < st.bounds.min_threshold then if n_connected < st.bounds.min_threshold then
@ -190,11 +195,10 @@ and too_many_connections st n_connected =
let rec worker_loop st = let rec worker_loop st =
let Pool pool = st.pool in let Pool pool = st.pool in
let config = P2p_pool.config pool in
begin begin
protect ~canceler:st.canceler begin fun () -> protect ~canceler:st.canceler begin fun () ->
Lwt.pick [ Lwt.pick [
Lwt_unix.sleep config.P2p_pool.maintenance_idle_time ; (* default: every two minutes *) Lwt_unix.sleep st.config.maintenance_idle_time ; (* default: every two minutes *)
Lwt_condition.wait st.please_maintain ; (* when asked *) Lwt_condition.wait st.please_maintain ; (* when asked *)
P2p_pool.Pool_event.wait_too_few_connections pool ; (* limits *) P2p_pool.Pool_event.wait_too_few_connections pool ; (* limits *)
P2p_pool.Pool_event.wait_too_many_connections pool ; P2p_pool.Pool_event.wait_too_many_connections pool ;
@ -214,8 +218,9 @@ let rec worker_loop st =
| Error [ Canceled ] -> Lwt.return_unit | Error [ Canceled ] -> Lwt.return_unit
| Error _ -> Lwt.return_unit | Error _ -> Lwt.return_unit
let create ?discovery bounds pool = { let create ?discovery config bounds pool = {
canceler = Lwt_canceler.create () ; canceler = Lwt_canceler.create () ;
config ;
bounds ; bounds ;
discovery ; discovery ;
pool = Pool pool ; pool = Pool pool ;

View File

@ -50,15 +50,32 @@ type bounds = {
max_threshold: int ; max_threshold: int ;
} }
type config = {
maintenance_idle_time: float ;
(** How long to wait at most, in seconds, before running a maintenance loop. *)
greylist_timeout: int ;
(** GC delay for the greylists tables, in seconds. *)
private_mode: bool ;
(** If [true], only open outgoing/accept incoming connections
to/from peers whose addresses are in [trusted_peers], and inform
these peers that the identity of this node should be revealed to
the rest of the network. *)
}
type 'meta t type 'meta t
(** Type of a maintenance worker. *) (** Type of a maintenance worker. *)
val create: val create:
?discovery:P2p_discovery.t -> ?discovery:P2p_discovery.t ->
bounds -> config -> bounds ->
('msg, 'meta, 'meta_conn) P2p_pool.t -> ('msg, 'meta, 'meta_conn) P2p_pool.t ->
'meta t 'meta t
(** [run ?discovery bounds pool] returns a maintenance worker, with (** [run ?discovery config bounds pool] returns a maintenance worker, with
the [discovery] worker if present, for [pool] with connection targets the [discovery] worker if present, for [pool] with connection targets
specified in [bounds]. *) specified in [bounds]. *)

View File

@ -200,8 +200,6 @@ type config = {
max_incoming_connections : int ; max_incoming_connections : int ;
connection_timeout : float ; connection_timeout : float ;
authentication_timeout : float ; authentication_timeout : float ;
greylist_timeout : int ;
maintenance_idle_time: float ;
incoming_app_message_queue_size : int option ; incoming_app_message_queue_size : int option ;
incoming_message_queue_size : int option ; incoming_message_queue_size : int option ;

View File

@ -103,12 +103,6 @@ type config = {
authentication_timeout : float ; authentication_timeout : float ;
(** Delay granted to a peer to perform authentication, in seconds. *) (** Delay granted to a peer to perform authentication, in seconds. *)
greylist_timeout : int ;
(** GC delay for the grelists tables, in seconds. *)
maintenance_idle_time: float ;
(** How long to wait at most, in seconds, before running a maintenance loop. *)
incoming_app_message_queue_size : int option ; incoming_app_message_queue_size : int option ;
(** Size of the message queue for user messages (messages returned (** Size of the message queue for user messages (messages returned
by this module's [read] function. *) by this module's [read] function. *)

View File

@ -94,8 +94,6 @@ let detach_node f points n =
max_incoming_connections = nb_points ; max_incoming_connections = nb_points ;
connection_timeout = 10. ; connection_timeout = 10. ;
authentication_timeout = 2. ; authentication_timeout = 2. ;
greylist_timeout = 2 ;
maintenance_idle_time = 120. ;
incoming_app_message_queue_size = None ; incoming_app_message_queue_size = None ;
incoming_message_queue_size = None ; incoming_message_queue_size = None ;
outgoing_message_queue_size = None ; outgoing_message_queue_size = None ;