package tezos-p2p

  1. Overview
  2. Docs

This module manages incoming accept and outgoing connections connect.

connect and accept try to authenticate the remote point, and agree on protocol version. They ultimately returns a P2p_conn.t which provides the highest-level view of a connection in lib_p2p.

TODO: properly document this modules, including side-effects and interaction with P2p_pool.

Functions of this module can trigger two types of events. They can *log* P2p_connection.P2p_event.t, and they can trigger condition variables defined in P2p_trigger.t.

type ('msg, 'peer, 'conn) t
type config = {
  1. incoming_app_message_queue_size : int option;
    (*

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

    *)
  2. private_mode : bool;
    (*

    If true, only open outgoing/accept incoming connections to/from peers whose addresses are in trusted_peers, and inform these peers that the identity of this node should not be revealed to the rest of the network.

    *)
  3. min_connections : int;
    (*

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

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

    *)
  5. max_incoming_connections : int;
    (*

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

    *)
  6. incoming_message_queue_size : int option;
    (*

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

    *)
  7. outgoing_message_queue_size : int option;
    (*

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

    *)
  8. binary_chunks_size : int option;
    (*

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

    *)
  9. identity : Tezos_base.P2p_identity.t;
    (*

    Our identity.

    *)
  10. connection_timeout : Tezos_base.Time.System.Span.t;
    (*

    Maximum time allowed to the establishment of a connection.

    *)
  11. authentication_timeout : Tezos_base.Time.System.Span.t;
    (*

    Maximum time allowed to the establishment of a connection.

    *)
  12. reconnection_config : P2p_point_state.Info.reconnection_config;
    (*

    Delay granted to a peer to perform authentication.

    *)
  13. proof_of_work_target : Tezos_crypto.Crypto_box.pow_target;
    (*

    The proof of work target we require from peers.

    *)
  14. listening_port : Tezos_base.P2p_addr.port option;
    (*

    The TCP port on which the peer can be reached.

    *)
  15. advertised_port : Tezos_base.P2p_addr.port option;
    (*

    The TCP port advertised to other peers, the default is listening_port.

    *)
}
val create : ?p2p_versions:Tezos_base.P2p_version.t list -> config -> ('msg, 'peer, 'conn) P2p_pool.t -> 'msg P2p_params.message_config -> 'conn P2p_params.conn_meta_config -> P2p_io_scheduler.t -> P2p_trigger.t -> log:(Tezos_base.P2p_connection.P2p_event.t -> unit) -> answerer:'msg P2p_answerer.t Stdlib.Lazy.t -> ('msg, 'peer, 'conn) t

create ?p2p_version config pool message_config socket_meta_config scheduler triggers log answerer returns a connection handler.

config is a record of configuration parameters. triggers is a record of condition variable used to signal some events to other modules. log is a callback to signal events to the upper layer. answerer is a parameterized callback that defines how the p2p layer will reply to incoming P2p_message.t.

val config : (_, _, _) t -> config

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

val connect : ?timeout:Tezos_base.Time.System.Span.t -> ('msg, 'peer, 'conn) t -> Tezos_base.P2p_point.Id.t -> (('msg, 'peer, 'conn) P2p_conn.t, Tezos_error_monad.TzCore.error list) Stdlib.result Lwt.t

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

val accept : ('msg, 'peer, 'conn) t -> P2p_fd.t -> Tezos_base.P2p_point.Id.t -> unit

accept t fd point instructs t to start the process of accepting a connection from fd. point is the id of the connecting host.

Incoming connection from banned points, or when maximum number of connection is exceeded are refused. The maximum number of connections maybe be randomly increased by one. Socket fd is closed when the connection is refused.

val stat : ('msg, 'peer, 'conn) t -> Tezos_base.P2p_stat.t

stat t is a snapshot of current bandwidth usage for the entire connected peers.

val on_new_connection : ('msg, 'peer, 'conn) t -> (Tezos_base.P2p_peer.Id.t -> ('msg, 'peer, 'conn) P2p_conn.t -> unit) -> unit

on_new_connection t f installs f as a hook for new connections in t.

val destroy : ('msg, 'peer, 'conn) t -> unit Lwt.t
OCaml

Innovation. Community. Security.