3 releases (breaking)
| 0.4.0 | Nov 5, 2022 |
|---|---|
| 0.3.0 | Sep 26, 2022 |
| 0.2.0 | Jan 21, 2021 |
#7 in #network-message
27 downloads per month
Used in 5 crates
(4 directly)
76KB
1.5K
SLoC
I/O reactor that drives the protocol state machine.
The reactor translates network events into protocol events. This has the added benefit that it's trivial to swap nakamoto's networking code with a different implementation, as the code is fully self-contained.
To illustrate the above, lets trace the behavior of the system when a ping
message is received via a peer connection to the client:
- The
Reactorreads from the socket and decodes aNetworkMessage::Pingmessage. - The
Reactorwraps this message into a protocol inputInput::Received(addr, NetworkMessage::Ping), whereaddris the remote address of the socket on which it received this message. - The
ReactorcallsProtocol::step(input, time), whereinputis the above input, andtimeis the current local time. - The
Protocolforwards this message to thePingManager, which constructs a new outputOut::Message(addr, NetworkMessage::Pong), and forwards it upstream, to the reactor. - The
Reactorprocesses the output, encodes the raw message and writes it to the socket corresponding to theaddraddress, effectively sending apongmessage back to the original sender.
Though simplified, the above steps provide a good mental model of how the reactor and protocol interplay to handle network events.
Dependencies
~0.8–1.5MB
~28K SLoC