2018-06-29 16:08:08 +04:00
|
|
|
(*****************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Open Source License *)
|
|
|
|
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* Permission is hereby granted, free of charge, to any person obtaining a *)
|
|
|
|
(* copy of this software and associated documentation files (the "Software"),*)
|
|
|
|
(* to deal in the Software without restriction, including without limitation *)
|
|
|
|
(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)
|
|
|
|
(* and/or sell copies of the Software, and to permit persons to whom the *)
|
|
|
|
(* Software is furnished to do so, subject to the following conditions: *)
|
|
|
|
(* *)
|
|
|
|
(* The above copyright notice and this permission notice shall be included *)
|
|
|
|
(* in all copies or substantial portions of the Software. *)
|
|
|
|
(* *)
|
|
|
|
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
|
|
|
|
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)
|
|
|
|
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)
|
|
|
|
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
|
|
|
|
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)
|
|
|
|
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)
|
|
|
|
(* DEALINGS IN THE SOFTWARE. *)
|
|
|
|
(* *)
|
|
|
|
(*****************************************************************************)
|
2017-01-14 16:14:11 +04:00
|
|
|
|
|
|
|
(* min <= min_threshold <= min_target <= max_target <= max_threshold <= max *)
|
|
|
|
|
2018-02-20 21:28:05 +04:00
|
|
|
(** P2P maintenance worker.
|
2017-01-14 16:14:11 +04:00
|
|
|
|
2018-02-20 21:28:05 +04:00
|
|
|
The P2P layer urges the maintainer to work when the number of
|
|
|
|
connections reaches `max` or is below `min`. Otherwise, the
|
|
|
|
maintener is lazy and only looks up for connections every two
|
|
|
|
minutes (hardcoded constant). The [maintain] function is another
|
|
|
|
way to signal the maintainer that a maintenance step is desired.
|
2017-01-14 16:14:11 +04:00
|
|
|
|
2018-02-20 21:28:05 +04:00
|
|
|
When the maintener detects that the number of connections is over
|
|
|
|
`max_threshold`, it randomly kills connections to reach
|
|
|
|
`max_target`.
|
|
|
|
|
|
|
|
When the maintener detects that the number of connections is below
|
|
|
|
`min_threshold`, it creates enough connection to reach at least
|
|
|
|
`min_target` (and never more than `max_target`). In the process, it
|
|
|
|
might ask its actual peers for new peers. *)
|
2017-01-14 16:14:11 +04:00
|
|
|
|
|
|
|
type bounds = {
|
|
|
|
min_threshold: int ;
|
|
|
|
min_target: int ;
|
|
|
|
max_target: int ;
|
|
|
|
max_threshold: int ;
|
|
|
|
}
|
|
|
|
|
|
|
|
type 'meta t
|
|
|
|
(** Type of a maintenance worker. *)
|
|
|
|
|
2018-05-15 15:16:08 +04:00
|
|
|
val run: bounds -> ('msg, 'meta, 'meta_conn) P2p_pool.t -> 'meta t
|
2018-02-22 18:35:50 +04:00
|
|
|
(** [run ~greylist_timeout bounds pool] is a maintenance worker for
|
2018-03-11 18:02:59 +04:00
|
|
|
[pool] with connection targets specified in [bounds]. *)
|
2017-01-14 16:14:11 +04:00
|
|
|
|
|
|
|
val maintain: 'meta t -> unit Lwt.t
|
2018-02-20 21:28:05 +04:00
|
|
|
(** [maintain t] gives a hint to maintenance worker [t] that
|
|
|
|
maintenance is needed and returns whenever [t] has done a
|
|
|
|
maintenance cycle. *)
|
2017-01-14 16:14:11 +04:00
|
|
|
|
|
|
|
val shutdown: 'meta t -> unit Lwt.t
|
2018-02-20 21:28:05 +04:00
|
|
|
(** [shutdown t] is a thread that returns whenever [t] has
|
|
|
|
successfully shut down. *)
|