Module Tezos_p2p.P2p_pool

Pool of connections. This module manages the connection pool that the peer-to-peer layer needs to maintain in order to function correctly.

A pool and its connections are parametrized by the type of messages exchanged over the connection and the type of meta-information associated with a peer. The type ('msg, 'peer_meta,'conn_meta) connection is a wrapper on top of P2p_socket.t that adds meta-informations, data-structures describing the detailed state of the peer and the connection, as well as a new message queue (referred to "app message queue") that will only contain the messages from the internal P2p_socket.t that needs to be examined by the higher layers. Some messages are directly processed by an internal worker and thus never propagated above.

type 'msg encoding =
| Encoding : {
tag : int;
encoding : 'a Tezos_base__TzPervasives.Data_encoding.t;
wrap : 'a ‑> 'msg;
unwrap : 'msg ‑> 'a option;
max_length : int option;
} ‑> 'msg encoding

Pool management

type ('msg, 'peer_meta, 'conn_meta) t
type ('msg, 'peer_meta, 'conn_meta) pool = ('msg'peer_meta'conn_metat

The type of a pool of connections, parametrized by resp. the type of messages and the meta-informations associated to an identity and a connection.

type config = {
identity : Tezos_base__TzPervasives.P2p_identity.t;

(** Our identity. *)

proof_of_work_target :;

(** The proof of work target we require from peers. *)

trusted_points : Tezos_base__TzPervasives.P2p_point.Id.t list;

(** List of hard-coded known peers to bootstrap the network from. *)

peers_file : string;

(** The path to the JSON file where the metadata associated to peer_ids are loaded / stored. *)

closed_network : bool;

(** If true, the only accepted connections are from peers whose addresses are in trusted_peers. *)

listening_port : Tezos_base__TzPervasives.P2p_addr.port option;

(** If provided, it will be passed to P2p_connection.authenticate when we authenticate against a new peer. *)

min_connections : int;

(** Strict minimum number of connections (triggers LogEvent.too_few_connections). *)

max_connections : int;

(** Max number of connections. If it's reached, connect and accept will fail, i.e. not add more connections (also triggers LogEvent.too_many_connections). *)

max_incoming_connections : int;

(** Max not-yet-authentified incoming connections. Above this number, accept will start dropping incoming connections. *)

connection_timeout : float;

(** Maximum time allowed to the establishment of a connection. *)

authentication_timeout : float;

(** Delay granted to a peer to perform authentication, in seconds. *)

greylist_timeout : int;

(** GC delay for the grelists tables, in seconds. *)

incoming_app_message_queue_size : int option;

(** Size of the message queue for user messages (messages returned by this module's read function. *)

incoming_message_queue_size : int option;

(** Size of the incoming message queue internal of a peer's Reader (See P2p_connection.accept). *)

outgoing_message_queue_size : int option;

(** Size of the outgoing message queue internal to a peer's Writer (See P2p_connection.accept). *)

known_peer_ids_history_size : int;

(** Size of the known peer_ids log buffer (default: 50) *)

known_points_history_size : int;

(** Size of the known points log buffer (default: 50) *)

max_known_points : (int * int) option;

(** Parameters for the the garbage collection of known points. If None, no garbage collection is performed. Otherwise, the first integer of the couple limits the size of the "known points" table. When this number is reached, the table is expurged from disconnected points, older first, to try to reach the amount of connections indicated by the second integer. *)

max_known_peer_ids : (int * int) option;

(** Like max_known_points, but for known peer_ids. *)

swap_linger : float;

(** Peer swapping does not occur more than once during a timespan of spap_linger seconds. *)

binary_chunks_size : int option;

(** Size (in bytes) of binary blocks that are sent to other peers. Default value is 64 kB. *)

type 'peer_meta peer_meta_config = {
peer_meta_encoding : 'peer_meta Tezos_base__TzPervasives.Data_encoding.t;
peer_meta_initial : 'peer_meta;
score : 'peer_meta ‑> float;
type 'conn_meta conn_meta_config = {
conn_meta_encoding : 'conn_meta Tezos_base__TzPervasives.Data_encoding.t;
conn_meta_value : Tezos_base__TzPervasives.P2p_peer.Id.t ‑> 'conn_meta;
type 'msg message_config = {
encoding : 'msg encoding list;
versions : Tezos_base__TzPervasives.P2p_version.t list;
val create : config ‑> 'peer_meta peer_meta_config ‑> 'conn_meta conn_meta_config ‑> 'msg message_config ‑> P2p_io_scheduler.t ‑> ('msg'peer_meta'conn_metapool Lwt.t

create config meta_cfg msg_cfg io_sched is a freshly minted pool.

val destroy : ('msg'peer_meta'conn_metapool ‑> unit Lwt.t

destroy pool returns when member connections are either disconnected or canceled.

val active_connections : ('msg'peer_meta'conn_metapool ‑> int

active_connections pool is the number of connections inside pool.

val pool_stat : ('msg'peer_meta'conn_metapool ‑> Tezos_base__TzPervasives.P2p_stat.t

pool_stat pool is a snapshot of current bandwidth usage for the entire pool.

val config : (___pool ‑> config

config pool is the config argument passed to pool at creation.

val send_swap_request : ('msg'peer_meta'conn_metapool ‑> unit

Pool events

module Pool_event : sig ... end

Connections management

type ('msg, 'peer_meta, 'conn_meta) connection

Type of a connection to a peer, parametrized by the type of messages exchanged as well as meta-information associated to a peer and a connection. It mostly wraps P2p_connection.connection, adding meta-information and data-structures describing a more fine-grained logical state of the connection.

val connect : ?⁠timeout:float ‑> ('msg'peer_meta'conn_metapool ‑> Tezos_base__TzPervasives.P2p_point.Id.t ‑> ('msg'peer_meta'conn_metaconnection Tezos_base__TzPervasives.tzresult Lwt.t

connect ?timeout pool point tries to add a connection to point in pool in less than timeout seconds.

val accept : ('msg'peer_meta'conn_metapool ‑> Lwt_unix.file_descr ‑> Tezos_base__TzPervasives.P2p_point.Id.t ‑> unit

accept pool fd point instructs pool to start the process of accepting a connection from fd. Used by P2p.

val disconnect : ?⁠wait:bool ‑> ('msg'peer_meta'conn_metaconnection ‑> unit Lwt.t

disconnect conn cleanly closes conn and returns after conn's internal worker has returned.

module Connection : sig ... end
val on_new_connection : ('msg'peer_meta'conn_metapool ‑> (Tezos_base__TzPervasives.P2p_peer.Id.t ‑> ('msg'peer_meta'conn_metaconnection ‑> unit) ‑> unit

I/O on connections

val read : ('msg'peer_meta'conn_metaconnection ‑> 'msg Tezos_base__TzPervasives.tzresult Lwt.t

read conn returns a message popped from conn's app message queue, or fails with Connection_closed.

val is_readable : ('msg'peer_meta'conn_metaconnection ‑> unit Tezos_base__TzPervasives.tzresult Lwt.t

is_readable conn returns when there is at least one message ready to be read.

val write : ('msg'peer_meta'conn_metaconnection ‑> 'msg ‑> unit Tezos_base__TzPervasives.tzresult Lwt.t

write conn msg is P2p_connection.write conn' msg where conn' is the internal P2p_connection.t inside conn.

val write_sync : ('msg'peer_meta'conn_metaconnection ‑> 'msg ‑> unit Tezos_base__TzPervasives.tzresult Lwt.t

write_sync conn msg is P2p_connection.write_sync conn' msg where conn' is the internal P2p_connection.t inside conn.

val write_now : ('msg'peer_meta'conn_metaconnection ‑> 'msg ‑> bool Tezos_base__TzPervasives.tzresult

write_now conn msg is P2p_connection.write_now conn' msg where conn' is the internal P2p_connection.t inside conn.

Broadcast functions

val write_all : ('msg'peer_meta'conn_metapool ‑> 'msg ‑> unit

write_all pool msg is write_now conn msg for all member connections to pool in Running state.

val broadcast_bootstrap_msg : ('msg'peer_meta'conn_metapool ‑> unit

write_all pool msg is P2P_connection.write_now conn Bootstrap for all member connections to pool in Running state.

val greylist_addr : ('msg'peer_meta'conn_metapool ‑> Tezos_base__TzPervasives.P2p_addr.t ‑> unit

greylist_addr pool addr adds addr to pool's IP greylist.

val greylist_peer : ('msg'peer_meta'conn_metapool ‑> Tezos_base__TzPervasives.P2p_peer.Id.t ‑> unit

greylist_peer pool peer adds peer to pool's peer greylist and peer's address to pool's IP greylist.

val gc_greylist : older_than:Tezos_base__TzPervasives.Time.t ‑> ('msg'peer_meta'conn_metapool ‑> unit

gc_greylist ~older_than pool

val acl_clear : ('msg'peer_meta'conn_metapool ‑> unit

acl_clear pool clears ACL tables.

Functions on Peer_id

module Peers : sig ... end

Functions on Points

module Points : sig ... end
val watch : ('msg'peer_meta'conn_metapool ‑> Tezos_base__TzPervasives.P2p_connection.Pool_event.t Lwt_stream.t * Tezos_base__TzPervasives.Lwt_watcher.stopper

watch pool is a stream, close a stream of events and a close function for this stream.