Expand description

Protocol Controller. Generic implementation of peer management for protocols. Responsible for accepting/rejecting incoming connections and initiating outgoing connections, respecting the inbound and outbound peer slot counts. Communicates with PeerStore to get and update peer reputation values and sends commands to Notifications.

Due to asynchronous nature of communication between ProtocolController and Notifications, ProtocolController has an imperfect view of the states of the peers. To reduce this desynchronization, the following measures are taken:

  1. Network peer events from Notifications are prioritized over actions from external API and internal actions by ProtocolController (like slot allocation).
  2. Notifications ignores all commands from ProtocolController after sending “incoming” request until receiving the answer to this “incoming” request.
  3. After sending a “connect” message, ProtocolController switches the state of the peer from Outbound to Inbound if it receives an “incoming” request from Notifications for this peer.

These measures do not eliminate confusing commands from ProtocolController completely, so Notifications must correctly handle seemingly inconsistent commands, like a “connect” command for the peer it thinks is already connected, and a “drop” command for a peer that was previously dropped.

Even though this does not guarantee that ProtocolController and Notifications have the same view of the peers’ states at any given moment, the eventual consistency is maintained.

Structs

  • Opaque identifier for an incoming connection. Allocated by the network.
  • Configuration for a set of nodes for a specific protocol.
  • Worker side of ProtocolHandle responsible for all the logic.
  • Shared handle to ProtocolController. Distributed around the code outside of the protocol implementation.
  • Notifications protocol index. For historical reasons it’s called SetId, because it used to refer to a set of peers in a peerset for this protocol.

Enums

Constants