Module darkfi::net::protocol

source ·
Expand description

Defines the networking protocol used at each stage in a connection. Consists of a series of messages that are sent across the network at the different connection stages.

When a node connects to a network for the first time, it must follow a seed protocol, which provides it with a list of network hosts to connect to. To establish a connection to another node, nodes must send version and version acknowledgement messages. During a connection, nodes continually get address and get-address messages to inform each other about what nodes are on the network. Nodes also send out a ping and pong message which keeps the network from shutting down.

Protocol submodule also implements a jobs manager that handles the asynchronous execution of the protocols.



  • Protocol for address and get-address messages. Implements how nodes exchange connection information about other nodes on the network. Address and get-address messages are exchanged continually alongside ping-pong messages as part of a network connection.
  • Base trait for implementing P2P protocols
  • Manages the tasks for the network protocol. Used by other connection protocols to handle asynchronous task execution across the network. Runs all tasks that are handed to it on an executor that has stopping functionality.
  • Protocol for ping-pong keepalive messages. Implements ping message and pong response. These messages are like the network heartbeat - they are sent continually between nodes, to ensure each node is still alive and active. Ping-pong messages ensure that the network doesn’t time out.
  • Interface for registering arbitrary P2P protocols
  • Seed server protocol. Seed server is used when connecting to the network for the first time. Returns a list of peers that nodes can connect to.
  • Protocol for version information handshake between nodes at the start of a connection. This is the first step when establishing a p2p conn.