Module Tezos_p2p.P2p

Tezos Shell Net - Low level API for the Gossip network

This is the entry point of the peer-to-peer layer.

It is used by the Shell as the API to communicate with other nodes.

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 app_message_encoding =
| Encoding : {
tag : int;
encoding : 'a Tezos_base__TzPervasives.Data_encoding.t;
wrap : 'a ‑> 'msg;
unwrap : 'msg ‑> 'a option;
max_length : int option;
} ‑> 'msg app_message_encoding
type 'msg message_config = {
encoding : 'msg app_message_encoding list;
versions : Tezos_base__TzPervasives.P2p_version.t list;
}
type config = {
listening_port : Tezos_base__TzPervasives.P2p_addr.port option;

(** Tells if incoming connections accepted, precising the TCP port on which the peer can be reached *)

listening_addr : Tezos_base__TzPervasives.P2p_addr.t option;

(** When incoming connections are accepted, precising on which IP adddress the node listen (default: [::]). *)

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_points. *)

identity : Tezos_base__TzPervasives.P2p_identity.t;

(** Cryptographic identity of the peer. *)

proof_of_work_target : Tezos_base__TzPervasives.Crypto_box.target;

(** Expected level of proof of work of peers' identity. *)

}

Network configuration

type limits = {
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. *)

min_connections : int;

(** Strict minimum number of connections (triggers an urgent maintenance) *)

expected_connections : int;

(** Targeted number of connections to reach when bootstraping / maintaining *)

max_connections : int;

(** Maximum number of connections (exceeding peers are disconnected) *)

backlog : int;

(** Argument of Lwt_unix.accept. *)

max_incoming_connections : int;

(** Maximum not-yet-authenticated incoming connections. *)

max_download_speed : int option;

(** Hard-limit in the number of bytes received per second. *)

max_upload_speed : int option;

(** Hard-limit in the number of bytes sent per second. *)

read_buffer_size : int;

(** Size in bytes of the buffer passed to Lwt_unix.read. *)

read_queue_size : int option;
write_queue_size : int option;
incoming_app_message_queue_size : int option;
incoming_message_queue_size : int option;
outgoing_message_queue_size : int option;

(** Various bounds for internal queues. *)

known_peer_ids_history_size : int;
known_points_history_size : int;

(** Size of circular log buffers, in number of events recorded. *)

max_known_peer_ids : (int * int) option;
max_known_points : (int * int) option;

(** Optional limitation of internal hashtables (max, target) *)

swap_linger : float;

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

binary_chunks_size : int option;

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

}

Network capacities

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

Type of a P2P layer instance, parametrized by: 'msg: type of messages exchanged between peers 'peer_meta: type of the metadata associated with peers (score, etc.) 'conn_meta: type of the metadata associated with connection (ack_cfg)

type ('msg, 'peer_meta, 'conn_meta) net = ('msg'peer_meta'conn_metat
val faked_network : 'peer_meta peer_meta_config ‑> ('msg'peer_meta'conn_metanet

A faked p2p layer, which do not initiate any connection nor open any listening socket

val create : config:config ‑> limits:limits ‑> 'peer_meta peer_meta_config ‑> 'conn_meta conn_meta_config ‑> 'msg message_config ‑> ('msg'peer_meta'conn_metanet Tezos_base__TzPervasives.tzresult Lwt.t

Main network initialisation function

val peer_id : ('msg'peer_meta'conn_metanet ‑> Tezos_base__TzPervasives.P2p_peer.Id.t

Return one's peer_id

val maintain : ('msg'peer_meta'conn_metanet ‑> unit Lwt.t

A maintenance operation : try and reach the ideal number of peers

val roll : ('msg'peer_meta'conn_metanet ‑> unit Lwt.t

Voluntarily drop some peers and replace them by new buddies

val shutdown : ('msg'peer_meta'conn_metanet ‑> unit Lwt.t

Close all connections properly

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

A connection to a peer

val connections : ('msg'peer_meta'conn_metanet ‑> ('msg'peer_meta'conn_metaconnection list

Access the domain of active peers

val find_connection : ('msg'peer_meta'conn_metanet ‑> Tezos_base__TzPervasives.P2p_peer.Id.t ‑> ('msg'peer_meta'conn_metaconnection option

Return the active peer with identity peer_id

val connection_info : ('msg'peer_meta'conn_metanet ‑> ('msg'peer_meta'conn_metaconnection ‑> Tezos_base__TzPervasives.P2p_connection.Info.t

Access the info of an active peer, if available

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

Cleanly closes a connection.

val global_stat : ('msg'peer_meta'conn_metanet ‑> Tezos_base__TzPervasives.P2p_stat.t
val get_peer_metadata : ('msg'peer_meta'conn_metanet ‑> Tezos_base__TzPervasives.P2p_peer.Id.t ‑> 'peer_meta

Accessors for meta information about a global identifier

val set_peer_metadata : ('msg'peer_meta'conn_metanet ‑> Tezos_base__TzPervasives.P2p_peer.Id.t ‑> 'peer_meta ‑> unit
val recv : ('msg'peer_meta'conn_metanet ‑> ('msg'peer_meta'conn_metaconnection ‑> 'msg Tezos_base__TzPervasives.tzresult Lwt.t

Wait for a message from a given connection.

val recv_any : ('msg'peer_meta'conn_metanet ‑> (('msg'peer_meta'conn_metaconnection * 'msg) Lwt.t

Wait for a message from any active connections.

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

send net peer msg is a thread that returns when msg has been successfully enqueued in the send queue.

val try_send : ('msg'peer_meta'conn_metanet ‑> ('msg'peer_meta'conn_metaconnection ‑> 'msg ‑> bool

try_send net peer msg is true if msg has been added to the send queue for peer, false otherwise

val broadcast : ('msg'peer_meta'conn_metanet ‑> 'msg ‑> unit

Send a message to all peers

val fold_connections : ('msg'peer_meta'conn_metanet ‑> init:'a ‑> f:(Tezos_base__TzPervasives.P2p_peer.Id.t ‑> ('msg'peer_meta'conn_metaconnection ‑> 'a ‑> 'a) ‑> 'a
val iter_connections : ('msg'peer_meta'conn_metanet ‑> (Tezos_base__TzPervasives.P2p_peer.Id.t ‑> ('msg'peer_meta'conn_metaconnection ‑> unit) ‑> unit
val on_new_connection : ('msg'peer_meta'conn_metanet ‑> (Tezos_base__TzPervasives.P2p_peer.Id.t ‑> ('msg'peer_meta'conn_metaconnection ‑> unit) ‑> unit
val build_rpc_directory : (___t ‑> unit Tezos_base__TzPervasives.RPC_directory.t
val greylist_addr : ('msg'peer_meta'conn_metanet ‑> Tezos_base__TzPervasives.P2p_addr.t ‑> unit
val greylist_peer : ('msg'peer_meta'conn_metanet ‑> Tezos_base__TzPervasives.P2p_peer.Id.t ‑> unit