|0.4.1||Apr 21, 2021|
Used in iota_stronghold
This library enables strongholds on different devices and in different networks to communicate with each other. The main basis for its functionality is the rust-libp2p library, which is a system of protocols, specifications and libraries that enable the development of peer-to-peer network applications (https://libp2p.io/).
Stronghold-communication implements the
P2PNetworkBehaviour for sending messages and reacting upon the outcome of the operation.
It combines multiple protocols of Libp2p:
- Multiplexing following the Yamux specification
- Noise: Encryption of the communication using the Noise protocol with XX-Handshake
- Multicast DNS: Enable Peer Discovery in a local network
- Identify Protocol: Receive identifying information like the
PeerIdand listening addresses when connecting to a new peer.
- Request-Response Protocol: Allows sending direct request/response messages between Peers; it expects a response for each request
Upon creating a new instance, a transport is created and upgraded, and combined with the P2PNetworkBehaviour into a ExpandedSwarm. This Swarm is returned to the caller and serves as entry-point for all communication to other peers. Additional to the Libp2p methods of the
ExpandedSwarm, it enables sending outbound messages, and manages the known peers. Incoming
P2PEvents can be handled by polling from the swarm, e.g. via the
Communication Actor is using the Riker Framwork to implement the actor pattern.
When creating a new
Communication Actor, the actor creates a
P2PNetworkBehaviour and continuously polls for events,
incoming requests are sent to the client actor that has to be provided in the
All swarm interaction, and configuration of the
Communication Actor is accomplished by sending the appropriate
CommunicationRequest to it, for each
CommunicationResults is returned to the sender, this also allows using the ask pattern.
The communication actor implements a firewall that checks the permission of each outgoing and incoming requests and drops them if the necessary permission has not been set. The required
ToPermissionVariants trait for messages can be derived with the communication-macros, this allows in case of enum Request types to accept specific variants while rejecting others.