P2p: randomly allow one additional incoming connection

If 'max_connections' is already reached, this modification will
enable one additional incoming connection if 'Random.bool()' is
true. This will allow a kind of connections diversification by
enabling a call to P2p_maintenance.too_many_connections, which
will close some connection with a low score (depending on the
chosen scoring criterion)
This commit is contained in:
OCamlPro-Iguernlala 2018-07-19 15:25:48 +02:00 committed by Grégoire Henry
parent 3a4d523e09
commit 3a3d0848ad
No known key found for this signature in database
GPG Key ID: 827A020B224844F1
2 changed files with 8 additions and 1 deletions

View File

@ -67,6 +67,7 @@ let commands = [
] ]
let () = let () =
Random.self_init () ;
match Cmdliner.Term.eval_choice (term, info) commands with match Cmdliner.Term.eval_choice (term, info) commands with
| `Error _ -> exit 1 | `Error _ -> exit 1
| `Help -> exit 0 | `Help -> exit 0

View File

@ -1129,8 +1129,14 @@ and swap pool conn current_peer_id new_point =
let accept pool fd point = let accept pool fd point =
log pool (Incoming_connection point) ; log pool (Incoming_connection point) ;
let max_active_conns =
if Random.bool () then
(* randomly allow one additional incoming connection *)
pool.config.max_connections + 1
else
pool.config.max_connections in
if pool.config.max_incoming_connections <= P2p_point.Table.length pool.incoming if pool.config.max_incoming_connections <= P2p_point.Table.length pool.incoming
|| pool.config.max_connections <= active_connections pool || max_active_conns <= active_connections pool
(* silently ignore banned points *) (* silently ignore banned points *)
|| (P2p_acl.banned_addr pool.acl (fst point)) then || (P2p_acl.banned_addr pool.acl (fst point)) then
Lwt.async (fun () -> P2p_fd.close fd) Lwt.async (fun () -> P2p_fd.close fd)