github.com/aakash4dev/cometbft@v0.38.2/spec/p2p/reactor-api/README.md (about)

     1  # Reactors
     2  
     3  Reactor is the generic name for a component that employs the p2p communication layer.
     4  
     5  This section documents the interaction of the p2p communication layer with the
     6  reactors.
     7  The diagram below summarizes this interaction, namely the **northbound interface**
     8  of the p2p communication layer, representing some relevant event flows:
     9  
    10  <img src="../images/p2p-reactors.png" style="background-color: white">
    11  
    12  Each of the protocols running a CometBFT node implements a reactor and registers
    13  the implementation with the p2p layer.
    14  The p2p layer provides network events to the registered reactors, the main
    15  two being new connections with peers and received messages.
    16  The reactors provide to the p2p layer messages to be sent to
    17  peers and commands to control the operation of the p2p layer.
    18  
    19  It is worth noting that the components depicted in the diagram below run
    20  multiple routines and that the illustrated actions happen in parallel.
    21  For instance, the connection establishment routines run in parallel, invoking
    22  the depicted `AddPeer` method concurrently.
    23  Once a connection is fully established, each `Peer` instance runs a send and a
    24  receive routines.
    25  The send routine collects messages from multiple reactors to a peer, packaging
    26  then into raw messages which are transmitted to the peer.
    27  The receive routine processes incoming messages and forwards them to the
    28  destination reactors, invoking the depicted `Receive` methods.
    29  In addition, the reactors run multiple routines for interacting
    30  with the peers (for example, to send messages to them) or with the `Switch`.
    31  
    32  The remaining of the documentation is organized as follows:
    33  
    34  - [Reactor API](./reactor.md): documents the [`p2p.Reactor`][reactor-interface]
    35    interface and specifies the behaviour of the p2p layer when interacting with
    36    a reactor.
    37    In other words, the interaction of the p2p layer with the protocol layer (bottom-up).
    38  
    39  - [P2P API](./p2p-api.md): documents the interface provided by the p2p
    40    layer to the reactors, through the `Switch` and `Peer` abstractions.
    41    In other words, the interaction of the protocol layer with the p2p layer (top-down).
    42  
    43  [reactor-interface]: ../../../p2p/base_reactor.go