diversify connections and disconnection based on prefixes of IP addresses
(related to issue #214 (closed))
The main contribution of this MR is a data structure in
src/p2p_pool/p2p_points_partition.ml to partition points and/or
connections into equivalence classes, and three associated
functions:
partition_disconnected: partitions (disconnected) points of a
given pool into equivalence classes
partition_connected: partitions connections into equivalence classes
pick: picks (at most) n elements from the given equivalence class.
This code is parameterized by a hash function on IP
addresses. Currently, it is instantiated with a function that
hashes the prefixes of IP adresses, and the result is used to:
-
diversify new established connections when calling
too_few_connections(use ofpartition_disconnected+pick) -
diversify connections when killing connections with
too_many_connections(use ofpartition_connected+pick)
Note that:
-
Currently, connections that are in private mode are not killed. But, I'll probably change this to rather keep white-listed connections. -
I also modified a little bit
P2p_pool.acceptto randomly accept one additional incoming connection so thattoo_many_connectionscan be triggered
What do you think about this @hnrgrgr @chambart ?
EDIT: After a discussion with @chambart, I changed the code to "protect" trusted peers from disconnection instead of private nodes.