package octez-shell-libs

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

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.

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.TzPervasives.P2p_identity.t;
    (*

    Our identity.

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

    Maximum time allowed to the establishment of a connection.

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

    Maximum time allowed to the establishment of a connection.

    *)
  12. reconnection_config : Tezos_p2p_services.Point_reconnection_config.t;
    (*

    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.TzPervasives.P2p_addr.port option;
    (*

    The TCP port on which the peer can be reached.

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

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

    *)
  16. disable_peer_discovery : bool;
    (*

    If True, point discovery is disabled. The connections will neither send nor answer to Bootstrap and Advertise messages. It will send Nack messages with empty list of points and not register points received by Nack messages.

    *)
}
val create : ?p2p_versions:Tezos_base.TzPervasives.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.TzPervasives.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 : ?trusted:bool -> ?expected_peer_id:Tezos_base.TzPervasives.P2p_peer.Id.t -> ?timeout:Tezos_base.TzPervasives.Time.System.Span.t -> ('msg, 'peer, 'conn) t -> Tezos_base.TzPervasives.P2p_point.Id.t -> ('msg, 'peer, 'conn) P2p_conn.t Tezos_base.TzPervasives.tzresult Lwt.t

connect ?trusted ?expected_peer_id ?timeout t point tries to add a connection to point in t in less than timeout. Prior to connection attempt, the point is registered with P2p_pool.register_point, to which the optional arguments trusted and expected_peer_id are also provided.

val accept : ('msg, 'peer, 'conn) t -> P2p_fd.t -> Tezos_base.TzPervasives.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.TzPervasives.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.TzPervasives.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 on_disconnection : ('msg, 'peer, 'conn) t -> (Tezos_base.TzPervasives.P2p_peer.Id.t -> unit) -> unit

on_disconnection t f installs f as a hook for disconnections in t.

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

Innovation. Community. Security.