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.
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 = {
incoming_app_message_queue_size : int option;
(*
Size of the message queue for user messages (messages returned by this module's read function.
*)
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.
*)
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.
*)
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).
*)
binary_chunks_size : int option;
(*
Size (in bytes) of binary blocks that are sent to other peers. Default value is 64 kB.
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.
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.